Skip to content

Commit

Permalink
Fix admission.Validator value in variable declaration error
Browse files Browse the repository at this point in the history
It fixes following error:
```
cannot use &Watcher{} (value of type *Watcher) as admission.Validator value in variable declaration: *Watcher does not implement admission.Validator (wrong type for method ValidateCreate)
		have ValidateCreate() error
		want ValidateCreate() (admission.Warnings, error)
```

Signed-off-by: Chandan Kumar <[email protected]>
  • Loading branch information
raukadah committed Nov 27, 2024
1 parent 8b742e6 commit 9cd7ca4
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,4 @@ run-with-webhook: export METRICS_PORT?=8080
run-with-webhook: export HEALTH_PORT?=8081
run-with-webhook: manifests generate fmt vet ## Run a controller from your host.
/bin/bash hack/clean_local_webhook.sh
/bin/bash hack/run_with_local_webhook.sh
/bin/bash hack/run_with_local_webhook.sh
3 changes: 2 additions & 1 deletion api/v1beta1/watcher_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// log is for logging in this package.
Expand Down Expand Up @@ -51,7 +52,7 @@ func (r *Watcher) Default() {
var _ webhook.Validator = &Watcher{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *Watcher) ValidateCreate() error {
func (r *Watcher) ValidateCreate() (admission.Warnings, error) {
watcherlog.Info("validate create", "name", r.Name)

// TODO(user): fill in your validation logic upon object creation.
Expand Down
3 changes: 2 additions & 1 deletion api/v1beta1/watcherapi_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// log is for logging in this package.
Expand Down Expand Up @@ -51,7 +52,7 @@ func (r *WatcherAPI) Default() {
var _ webhook.Validator = &WatcherAPI{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *WatcherAPI) ValidateCreate() error {
func (r *WatcherAPI) ValidateCreate() (admission.Warnings, error) {
watcherapilog.Info("validate create", "name", r.Name)

// TODO(user): fill in your validation logic upon object creation.
Expand Down
3 changes: 2 additions & 1 deletion api/v1beta1/watcherapplier_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// log is for logging in this package.
Expand Down Expand Up @@ -51,7 +52,7 @@ func (r *WatcherApplier) Default() {
var _ webhook.Validator = &WatcherApplier{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *WatcherApplier) ValidateCreate() error {
func (r *WatcherApplier) ValidateCreate() (admission.Warnings, error) {
watcherapplierlog.Info("validate create", "name", r.Name)

// TODO(user): fill in your validation logic upon object creation.
Expand Down
3 changes: 2 additions & 1 deletion api/v1beta1/watcherdecisionengine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// log is for logging in this package.
Expand Down Expand Up @@ -51,7 +52,7 @@ func (r *WatcherDecisionEngine) Default() {
var _ webhook.Validator = &WatcherDecisionEngine{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *WatcherDecisionEngine) ValidateCreate() error {
func (r *WatcherDecisionEngine) ValidateCreate() (admission.Warnings, error) {
watcherdecisionenginelog.Info("validate create", "name", r.Name)

// TODO(user): fill in your validation logic upon object creation.
Expand Down
174 changes: 174 additions & 0 deletions config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
creationTimestamp: null
name: mutating-webhook-configuration
webhooks:
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /mutate-watcher-openstack-org-v1beta1-watcher
failurePolicy: Fail
name: mwatcher.kb.io
rules:
- apiGroups:
- watcher.openstack.org
apiVersions:
- v1beta1
operations:
- CREATE
- UPDATE
resources:
- watchers
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /mutate-watcher-openstack-org-v1beta1-watcherapi
failurePolicy: Fail
name: mwatcherapi.kb.io
rules:
- apiGroups:
- watcher.openstack.org
apiVersions:
- v1beta1
operations:
- CREATE
- UPDATE
resources:
- watcherapis
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /mutate-watcher-openstack-org-v1beta1-watcherapplier
failurePolicy: Fail
name: mwatcherapplier.kb.io
rules:
- apiGroups:
- watcher.openstack.org
apiVersions:
- v1beta1
operations:
- CREATE
- UPDATE
resources:
- watcherappliers
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /mutate-watcher-openstack-org-v1beta1-watcherdecisionengine
failurePolicy: Fail
name: mwatcherdecisionengine.kb.io
rules:
- apiGroups:
- watcher.openstack.org
apiVersions:
- v1beta1
operations:
- CREATE
- UPDATE
resources:
- watcherdecisionengines
sideEffects: None
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
creationTimestamp: null
name: validating-webhook-configuration
webhooks:
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /validate-watcher-openstack-org-v1beta1-watcher
failurePolicy: Fail
name: vwatcher.kb.io
rules:
- apiGroups:
- watcher.openstack.org
apiVersions:
- v1beta1
operations:
- CREATE
- UPDATE
resources:
- watchers
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /validate-watcher-openstack-org-v1beta1-watcherapi
failurePolicy: Fail
name: vwatcherapi.kb.io
rules:
- apiGroups:
- watcher.openstack.org
apiVersions:
- v1beta1
operations:
- CREATE
- UPDATE
resources:
- watcherapis
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /validate-watcher-openstack-org-v1beta1-watcherapplier
failurePolicy: Fail
name: vwatcherapplier.kb.io
rules:
- apiGroups:
- watcher.openstack.org
apiVersions:
- v1beta1
operations:
- CREATE
- UPDATE
resources:
- watcherappliers
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /validate-watcher-openstack-org-v1beta1-watcherdecisionengine
failurePolicy: Fail
name: vwatcherdecisionengine.kb.io
rules:
- apiGroups:
- watcher.openstack.org
apiVersions:
- v1beta1
operations:
- CREATE
- UPDATE
resources:
- watcherdecisionengines
sideEffects: None
2 changes: 1 addition & 1 deletion hack/clean_local_webhook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ oc delete mutatingwebhookconfiguration/mwatcherapi.kb.io --ignore-not-found
oc delete validatingwebhookconfiguration/vwatcherdecisionengine.kb.io --ignore-not-found
oc delete mutatingwebhookconfiguration/mwatcherdecisionengine.kb.io --ignore-not-found
oc delete validatingwebhookconfiguration/vwatcherapplier.kb.io --ignore-not-found
oc delete mutatingwebhookconfiguration/mwatcherapplier.kb.io --ignore-not-found
oc delete mutatingwebhookconfiguration/mwatcherapplier.kb.io --ignore-not-found

0 comments on commit 9cd7ca4

Please sign in to comment.