-
Notifications
You must be signed in to change notification settings - Fork 127
[Draft] Validation Webhook for splunk-operator #1664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| Copyright (c) 2018-2022 Splunk Inc. All rights reserved. | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package v4 | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
| "sigs.k8s.io/controller-runtime/pkg/webhook/admission" | ||
| ) | ||
|
|
||
| var webhooklog = logf.Log.WithName("splunk-webhook") | ||
|
|
||
| // SplunkValidator handles validation for all Splunk Enterprise CRDs | ||
| // This is a dummy implementation to test webhook connectivity | ||
| type SplunkValidator struct{} | ||
|
|
||
| // SetupWebhookWithManager registers the centralized webhook with the manager | ||
| func SetupWebhookWithManager(mgr ctrl.Manager) error { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need an error return at all if we always return nil |
||
| validator := &SplunkValidator{} | ||
|
|
||
| mgr.GetWebhookServer().Register("/validate-splunk-enterprise", &admission.Webhook{ | ||
| Handler: validator, | ||
| }) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // Handle implements the admission.Handler interface | ||
| // This is a dummy implementation that just logs and allows all requests | ||
| func (v *SplunkValidator) Handle(ctx context.Context, req admission.Request) admission.Response { | ||
| // Dummy webhook - just log and allow everything | ||
| webhooklog.Info("WEBHOOK CALLED - Validation webhook is working!", | ||
| "kind", req.Kind.Kind, | ||
| "name", req.Name, | ||
| "namespace", req.Namespace, | ||
| "operation", req.Operation, | ||
| "user", req.UserInfo.Username) | ||
|
|
||
| // Always allow - this is just for testing webhook connectivity | ||
| return admission.Allowed("webhook is working - all requests allowed") | ||
| } | ||
|
|
||
| // Ensure SplunkValidator implements admission.Handler | ||
| var _ admission.Handler = &SplunkValidator{} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -221,6 +221,12 @@ func main() { | |
| setupLog.Error(err, "unable to create controller", "controller", "Standalone") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| // Setup centralized validation webhook for all CRDs | ||
| if err = enterpriseApi.SetupWebhookWithManager(mgr); err != nil { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And if we always return nil in SetupWebhookWithManager, then this if is not required |
||
| setupLog.Error(err, "unable to create validation webhook") | ||
| os.Exit(1) | ||
| } | ||
| //+kubebuilder:scaffold:builder | ||
|
|
||
| if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # The following manifests contain a self-signed issuer CR and a certificate CR. | ||
| # More document can be found at https://docs.cert-manager.io | ||
| # WARNING: Targets CertManager v1.0. Check https://cert-manager.io/docs/installation/upgrading/ for breaking changes. | ||
| apiVersion: cert-manager.io/v1 | ||
| kind: Issuer | ||
| metadata: | ||
| labels: | ||
| app.kubernetes.io/name: issuer | ||
| app.kubernetes.io/instance: selfsigned-issuer | ||
| app.kubernetes.io/component: certificate | ||
| app.kubernetes.io/created-by: splunk-operator | ||
| app.kubernetes.io/part-of: splunk-operator | ||
| app.kubernetes.io/managed-by: kustomize | ||
| name: selfsigned-issuer | ||
| namespace: system | ||
| spec: | ||
| selfSigned: {} | ||
| --- | ||
| apiVersion: cert-manager.io/v1 | ||
| kind: Certificate | ||
| metadata: | ||
| labels: | ||
| app.kubernetes.io/name: certificate | ||
| app.kubernetes.io/instance: serving-cert | ||
| app.kubernetes.io/component: certificate | ||
| app.kubernetes.io/created-by: splunk-operator | ||
| app.kubernetes.io/part-of: splunk-operator | ||
| app.kubernetes.io/managed-by: kustomize | ||
| name: serving-cert | ||
| namespace: system | ||
| spec: | ||
| dnsNames: | ||
| - $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc | ||
| - $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc.cluster.local | ||
| issuerRef: | ||
| kind: Issuer | ||
| name: selfsigned-issuer | ||
| secretName: webhook-server-cert |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| resources: | ||
| - certificate.yaml | ||
|
|
||
| configurations: | ||
| - kustomizeconfig.yaml |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # This configuration is for teaching kustomize how to update name ref and var substitution | ||
| nameReference: | ||
| - kind: Issuer | ||
| group: cert-manager.io | ||
| fieldSpecs: | ||
| - kind: Certificate | ||
| group: cert-manager.io | ||
| path: spec/issuerRef/name | ||
|
|
||
| varReference: | ||
| - kind: Certificate | ||
| group: cert-manager.io | ||
| path: spec/dnsNames |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: controller-manager | ||
| namespace: system | ||
| spec: | ||
| template: | ||
| spec: | ||
| containers: | ||
| - name: manager | ||
| ports: | ||
| - containerPort: 9443 | ||
| name: webhook-server | ||
| protocol: TCP | ||
| volumeMounts: | ||
| - mountPath: /tmp/k8s-webhook-server/serving-certs | ||
| name: cert | ||
| readOnly: true | ||
| volumes: | ||
| - name: cert | ||
| secret: | ||
| defaultMode: 420 | ||
| secretName: webhook-server-cert |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # This patch add annotation to admission webhook config and | ||
| # the variables $(CERTIFICATE_NAMESPACE) and $(CERTIFICATE_NAME) will be substituted by kustomize. | ||
| apiVersion: admissionregistration.k8s.io/v1 | ||
| kind: ValidatingWebhookConfiguration | ||
| metadata: | ||
| labels: | ||
| app.kubernetes.io/name: validatingwebhookconfiguration | ||
| app.kubernetes.io/instance: validating-webhook-configuration | ||
| app.kubernetes.io/component: webhook | ||
| app.kubernetes.io/created-by: splunk-operator | ||
| app.kubernetes.io/part-of: splunk-operator | ||
| app.kubernetes.io/managed-by: kustomize | ||
| name: validating-webhook-configuration | ||
| annotations: | ||
| cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| resources: | ||
| - manifests.yaml | ||
| - service.yaml | ||
|
|
||
| configurations: | ||
| - kustomizeconfig.yaml |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # the following config is for teaching kustomize where to look at when substituting vars. | ||
| # It requires kustomize v2.1.0 or newer to work properly. | ||
| nameReference: | ||
| - kind: Service | ||
| version: v1 | ||
| fieldSpecs: | ||
| - kind: MutatingWebhookConfiguration | ||
| group: admissionregistration.k8s.io | ||
| path: webhooks/clientConfig/service/name | ||
| - kind: ValidatingWebhookConfiguration | ||
| group: admissionregistration.k8s.io | ||
| path: webhooks/clientConfig/service/name | ||
|
|
||
| namespace: | ||
| - kind: MutatingWebhookConfiguration | ||
| group: admissionregistration.k8s.io | ||
| path: webhooks/clientConfig/service/namespace | ||
| create: true | ||
| - kind: ValidatingWebhookConfiguration | ||
| group: admissionregistration.k8s.io | ||
| path: webhooks/clientConfig/service/namespace | ||
| create: true | ||
|
|
||
| varReference: | ||
| - path: metadata/annotations |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| --- | ||
| apiVersion: admissionregistration.k8s.io/v1 | ||
| kind: ValidatingWebhookConfiguration | ||
| metadata: | ||
| name: validating-webhook-configuration | ||
| webhooks: | ||
| - admissionReviewVersions: | ||
| - v1 | ||
| clientConfig: | ||
| service: | ||
| name: webhook-service | ||
| namespace: system | ||
| path: /validate-splunk-enterprise | ||
| failurePolicy: Fail | ||
| name: vsplunk.kb.io | ||
| rules: | ||
| - apiGroups: | ||
| - enterprise.splunk.com | ||
| apiVersions: | ||
| - v4 | ||
| operations: | ||
| - CREATE | ||
| - UPDATE | ||
| resources: | ||
| - standalones | ||
| - indexerclusters | ||
| - searchheadclusters | ||
| - clustermanagers | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we skipping ClusterMaster and LicenseMaster? |
||
| - licensemanagers | ||
| - monitoringconsoles | ||
| sideEffects: None | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: webhook-service | ||
| namespace: system | ||
| spec: | ||
| ports: | ||
| - port: 443 | ||
| protocol: TCP | ||
| targetPort: 9443 | ||
| selector: | ||
| control-plane: controller-manager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it requires updating to 2026 included