Skip to content

Commit 8cf5958

Browse files
committed
webhook: generate webhook using operator-sdk but without defaulting/mutating
For now, we only need a validating and not a mutating webhook. The parent commit generated both a validating and a mutating commit. This commit on top of that and undoes the parts that are about enabling the mutating webhook. It's done this way, so we first generate both kinds of webhooks, and then undo part of it. The benefit is that if we ever want to add the mutating webhook, we can git-revert this commit. We also clearer see the difference by doing it this way. This commit has no manual changes, it is fully generated by running the following command on the grandparent commit. $ make operator-sdk && \ ./bin/operator-sdk create webhook --group config --version v1 --kind DpuOperatorConfig --programmatic-validation && \ make vendor && \ make manifests && \ (cd api/ && go get github.com/onsi/ginkgo/[email protected]) && \ make vendor && \ make manifests && \ make generate && \ sed -i $'33i \\\tconfigv1 "github.com/openshift/dpu-operator/api/v1"' cmd/main.go && \ sed -i 's/^- path: patches\/webhook_in_dpuoperatorconfigs.yaml/#\0/' config/crd/kustomization.yaml && \ sed -i -e 's/var _ webhook.\(Defaulter\|Validator\)/\/\/\0/' \ -e 's/"sigs.k8s.io\/controller-runtime\/pkg\/webhook"/\/\/\0/' \ api/v1/dpuoperatorconfig_webhook.go \ vendor/github.com/openshift/dpu-operator/api/v1/dpuoperatorconfig_webhook.go && \ make bundle
1 parent 9c4e609 commit 8cf5958

File tree

7 files changed

+2
-99
lines changed

7 files changed

+2
-99
lines changed

PROJECT

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ resources:
2121
path: github.com/openshift/dpu-operator/api/v1
2222
version: v1
2323
webhooks:
24-
defaulting: true
2524
validation: true
2625
webhookVersion: v1
2726
- api:

api/v1/dpuoperatorconfig_webhook.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,6 @@ func (r *DpuOperatorConfig) SetupWebhookWithManager(mgr ctrl.Manager) error {
3636

3737
// TODO(user): EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
3838

39-
//+kubebuilder:webhook:path=/mutate-config-openshift-io-v1-dpuoperatorconfig,mutating=true,failurePolicy=fail,sideEffects=None,groups=config.openshift.io,resources=dpuoperatorconfigs,verbs=create;update,versions=v1,name=mdpuoperatorconfig.kb.io,admissionReviewVersions=v1
40-
41-
//var _ webhook.Defaulter = &DpuOperatorConfig{}
42-
43-
// Default implements webhook.Defaulter so a webhook will be registered for the type
44-
func (r *DpuOperatorConfig) Default() {
45-
dpuoperatorconfiglog.Info("default", "name", r.Name)
46-
47-
// TODO(user): fill in your defaulting logic.
48-
}
49-
5039
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
5140
// NOTE: The 'path' attribute must follow a specific pattern and should not be modified directly here.
5241
// Modifying the path for an invalid path can cause API server errors; failing to locate the webhook.

api/v1/dpuoperatorconfig_webhook_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ import (
2222

2323
var _ = Describe("DpuOperatorConfig Webhook", func() {
2424

25-
Context("When creating DpuOperatorConfig under Defaulting Webhook", func() {
26-
It("Should fill in the default value if a required field is empty", func() {
27-
28-
// TODO(user): Add your logic here
29-
30-
})
31-
})
32-
3325
Context("When creating DpuOperatorConfig under Validating Webhook", func() {
3426
It("Should deny if a required field is empty", func() {
3527

bundle/manifests/dpu-operator.clusterserviceversion.yaml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ metadata:
3838
}
3939
]
4040
capabilities: Basic Install
41-
createdAt: "2025-02-25T12:19:48Z"
41+
createdAt: "2025-02-25T12:29:34Z"
4242
features.operators.openshift.io/cnf: "false"
4343
features.operators.openshift.io/cni: "true"
4444
features.operators.openshift.io/csi: "false"
@@ -417,26 +417,6 @@ spec:
417417
url: www.redhat.com
418418
version: 4.19.0
419419
webhookdefinitions:
420-
- admissionReviewVersions:
421-
- v1
422-
containerPort: 443
423-
deploymentName: dpu-operator-controller-manager
424-
failurePolicy: Fail
425-
generateName: mdpuoperatorconfig.kb.io
426-
rules:
427-
- apiGroups:
428-
- config.openshift.io
429-
apiVersions:
430-
- v1
431-
operations:
432-
- CREATE
433-
- UPDATE
434-
resources:
435-
- dpuoperatorconfigs
436-
sideEffects: None
437-
targetPort: 9443
438-
type: MutatingAdmissionWebhook
439-
webhookPath: /mutate-config-openshift-io-v1-dpuoperatorconfig
440420
- admissionReviewVersions:
441421
- v1
442422
containerPort: 443

config/webhook/manifests.yaml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,5 @@
11
---
22
apiVersion: admissionregistration.k8s.io/v1
3-
kind: MutatingWebhookConfiguration
4-
metadata:
5-
name: mutating-webhook-configuration
6-
webhooks:
7-
- admissionReviewVersions:
8-
- v1
9-
clientConfig:
10-
service:
11-
name: webhook-service
12-
namespace: system
13-
path: /mutate-config-openshift-io-v1-dpuoperatorconfig
14-
failurePolicy: Fail
15-
name: mdpuoperatorconfig.kb.io
16-
rules:
17-
- apiGroups:
18-
- config.openshift.io
19-
apiVersions:
20-
- v1
21-
operations:
22-
- CREATE
23-
- UPDATE
24-
resources:
25-
- dpuoperatorconfigs
26-
sideEffects: None
27-
---
28-
apiVersion: admissionregistration.k8s.io/v1
293
kind: ValidatingWebhookConfiguration
304
metadata:
315
name: validating-webhook-configuration

manifests/stable/dpu-operator.clusterserviceversion.yaml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ metadata:
3838
}
3939
]
4040
capabilities: Basic Install
41-
createdAt: "2025-02-25T12:19:48Z"
41+
createdAt: "2025-02-25T12:29:34Z"
4242
features.operators.openshift.io/cnf: "false"
4343
features.operators.openshift.io/cni: "true"
4444
features.operators.openshift.io/csi: "false"
@@ -417,26 +417,6 @@ spec:
417417
url: www.redhat.com
418418
version: 4.19.0
419419
webhookdefinitions:
420-
- admissionReviewVersions:
421-
- v1
422-
containerPort: 443
423-
deploymentName: dpu-operator-controller-manager
424-
failurePolicy: Fail
425-
generateName: mdpuoperatorconfig.kb.io
426-
rules:
427-
- apiGroups:
428-
- config.openshift.io
429-
apiVersions:
430-
- v1
431-
operations:
432-
- CREATE
433-
- UPDATE
434-
resources:
435-
- dpuoperatorconfigs
436-
sideEffects: None
437-
targetPort: 9443
438-
type: MutatingAdmissionWebhook
439-
webhookPath: /mutate-config-openshift-io-v1-dpuoperatorconfig
440420
- admissionReviewVersions:
441421
- v1
442422
containerPort: 443

vendor/github.com/openshift/dpu-operator/api/v1/dpuoperatorconfig_webhook.go

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)