Skip to content

Commit

Permalink
Add logic for webhooks in main.go
Browse files Browse the repository at this point in the history
It also fixes:
- Fix admission.Validator value in variable declaration error
- Fix functional tests and pre-commit
- Fix tls.crt no such file or directory
- Use METRICS_PORT to 33080 and HEALTH_PORT to 33081

Signed-off-by: Chandan Kumar <[email protected]>
  • Loading branch information
raukadah committed Nov 29, 2024
1 parent c71f46a commit b7e21be
Show file tree
Hide file tree
Showing 14 changed files with 251 additions and 190 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ crd-schema-check: manifests
# before deploying with OLM again for other untrappable signals.
SKIP_CERT ?=false
.PHONY: run-with-webhook
run-with-webhook: export METRICS_PORT?=8080
run-with-webhook: export HEALTH_PORT?=8081
run-with-webhook: export METRICS_PORT?=33080
run-with-webhook: export HEALTH_PORT?=33081
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
13 changes: 7 additions & 6 deletions 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,25 +52,25 @@ 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.
return nil
return nil, nil
}

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

// TODO(user): fill in your validation logic upon object update.
return nil
return nil, nil
}

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

// TODO(user): fill in your validation logic upon object deletion.
return nil
return nil, nil
}
13 changes: 7 additions & 6 deletions 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,25 +52,25 @@ 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.
return nil
return nil, nil
}

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

// TODO(user): fill in your validation logic upon object update.
return nil
return nil, nil
}

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

// TODO(user): fill in your validation logic upon object deletion.
return nil
return nil, nil
}
13 changes: 7 additions & 6 deletions 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,25 +52,25 @@ 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.
return nil
return nil, nil
}

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

// TODO(user): fill in your validation logic upon object update.
return nil
return nil, nil
}

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

// TODO(user): fill in your validation logic upon object deletion.
return nil
return nil, nil
}
13 changes: 7 additions & 6 deletions 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,25 +52,25 @@ 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.
return nil
return nil, nil
}

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

// TODO(user): fill in your validation logic upon object update.
return nil
return nil, nil
}

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

// TODO(user): fill in your validation logic upon object deletion.
return nil
return nil, nil
}
141 changes: 0 additions & 141 deletions api/v1beta1/webhook_suite_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ patches:
# [WEBHOOK] To enable webhook, uncomment the following section
# the following config is for teaching kustomize how to do kustomization for CRDs.

#configurations:
#- kustomizeconfig.yaml
configurations:
- kustomizeconfig.yaml
4 changes: 2 additions & 2 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ resources:
- ../manager
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
#- ../webhook
- ../webhook
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
#- ../certmanager
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
Expand All @@ -34,7 +34,7 @@ patches:

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
#- path: manager_webhook_patch.yaml
- path: manager_webhook_patch.yaml

# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'.
# Uncomment 'CERTMANAGER' sections in crd/kustomization.yaml to enable the CA injection in the admission webhooks.
Expand Down
Loading

0 comments on commit b7e21be

Please sign in to comment.