Skip to content

Commit

Permalink
webhook: move initialization inside of the module (#1284)
Browse files Browse the repository at this point in the history
Add webhook.Init() function and hide webhook setup inside of the
module. It will make it possible to replace Init with a NOP (no
operation) with conditional compilation for no-webhook build.

Signed-off-by: Yauheni Kaliuta <[email protected]>
  • Loading branch information
ykaliuta authored Oct 9, 2024
1 parent 6134496 commit e40c770
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 9 additions & 0 deletions controllers/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ type OpenDataHubValidatingWebhook struct {
Decoder *admission.Decoder
}

func Init(mgr ctrl.Manager) {
(&OpenDataHubValidatingWebhook{
Client: mgr.GetClient(),
Decoder: admission.NewDecoder(mgr.GetScheme()),
}).SetupWithManager(mgr)

(&DSCDefaulter{}).SetupWithManager(mgr)
}

func (w *OpenDataHubValidatingWebhook) SetupWithManager(mgr ctrl.Manager) {
hookServer := mgr.GetWebhookServer()
odhWebhook := &webhook.Admission{
Expand Down
8 changes: 1 addition & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"
ctrlmetrics "sigs.k8s.io/controller-runtime/pkg/metrics/server"
ctrlwebhook "sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
Expand Down Expand Up @@ -235,12 +234,7 @@ func main() { //nolint:funlen,maintidx
os.Exit(1)
}

(&webhook.OpenDataHubValidatingWebhook{
Client: mgr.GetClient(),
Decoder: admission.NewDecoder(mgr.GetScheme()),
}).SetupWithManager(mgr)

(&webhook.DSCDefaulter{}).SetupWithManager(mgr)
webhook.Init(mgr)

if err = (&dscictrl.DSCInitializationReconciler{
Client: mgr.GetClient(),
Expand Down

0 comments on commit e40c770

Please sign in to comment.