Skip to content

Commit

Permalink
Hook up the ctrl-runtime wehbook into the Manager
Browse files Browse the repository at this point in the history
These are used for version conversions
  • Loading branch information
bryanv committed Sep 8, 2023
1 parent 5d462a1 commit 6ab7bfa
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ import (
klog "k8s.io/klog/v2"
"k8s.io/klog/v2/klogr"

"github.com/vmware-tanzu/vm-operator/api/v1alpha1"
"github.com/vmware-tanzu/vm-operator/api/v1alpha2"
"github.com/vmware-tanzu/vm-operator/controllers"
"github.com/vmware-tanzu/vm-operator/pkg"
"github.com/vmware-tanzu/vm-operator/pkg/context"
"github.com/vmware-tanzu/vm-operator/pkg/lib"
"github.com/vmware-tanzu/vm-operator/pkg/manager"
"github.com/vmware-tanzu/vm-operator/webhooks"

Expand Down Expand Up @@ -268,6 +271,12 @@ func main() {
return err
}

if lib.IsVMServiceV1Alpha2FSSEnabled() {
if err := addConversionWebhooksToManager(ctx, mgr); err != nil {
return err
}
}

return webhooks.AddToManager(ctx, mgr)
}

Expand Down Expand Up @@ -298,6 +307,57 @@ func main() {
}
}

// addConversionWebhooksToManager adds the ctrl-runtime managed webhooks. We just use these
// for version conversion, but they can also do mutation and validation webhook callbacks
// instead of our separate webhooks.
func addConversionWebhooksToManager(_ *context.ControllerManagerContext, mgr ctrlmgr.Manager) error {
if err := (&v1alpha1.VirtualMachine{}).SetupWebhookWithManager(mgr); err != nil {
return err
}
if err := (&v1alpha1.VirtualMachineClass{}).SetupWebhookWithManager(mgr); err != nil {
return err
}
if err := (&v1alpha1.VirtualMachineImage{}).SetupWebhookWithManager(mgr); err != nil {
return err
}
if err := (&v1alpha1.ClusterVirtualMachineImage{}).SetupWebhookWithManager(mgr); err != nil {
return err
}
if err := (&v1alpha1.VirtualMachinePublishRequest{}).SetupWebhookWithManager(mgr); err != nil {
return err
}
if err := (&v1alpha1.VirtualMachineService{}).SetupWebhookWithManager(mgr); err != nil {
return err
}
if err := (&v1alpha1.VirtualMachineSetResourcePolicy{}).SetupWebhookWithManager(mgr); err != nil {
return err
}

if err := (&v1alpha2.VirtualMachine{}).SetupWebhookWithManager(mgr); err != nil {
return err
}
if err := (&v1alpha2.VirtualMachineClass{}).SetupWebhookWithManager(mgr); err != nil {
return err
}
if err := (&v1alpha2.VirtualMachineImage{}).SetupWebhookWithManager(mgr); err != nil {
return err
}
if err := (&v1alpha2.ClusterVirtualMachineImage{}).SetupWebhookWithManager(mgr); err != nil {
return err
}
if err := (&v1alpha2.VirtualMachinePublishRequest{}).SetupWebhookWithManager(mgr); err != nil {
return err
}
if err := (&v1alpha2.VirtualMachineService{}).SetupWebhookWithManager(mgr); err != nil {
return err
}
if err := (&v1alpha2.VirtualMachineSetResourcePolicy{}).SetupWebhookWithManager(mgr); err != nil {
return err
}

return nil
}

func configureWebhookTLS(server *webhook.Server) {
tlsCfgFunc := func(cfg *tls.Config) {
cfg.MinVersion = tls.VersionTLS12
Expand Down

0 comments on commit 6ab7bfa

Please sign in to comment.