Skip to content

Commit

Permalink
Hook up ctrl-runtime webhooks when the v1a2 FFS is enabled
Browse files Browse the repository at this point in the history
This is used for the version conversion wehbooks. This can also support
validation and mutation webhooks but our own webhook framework predates
ctrl-runtime support for that so that is an improvement for later.
  • Loading branch information
bryanv committed Sep 29, 2023
1 parent d424e4f commit 865f407
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 @@ -18,9 +18,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 @@ -265,6 +268,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 @@ -296,6 +305,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(opts *webhook.Options) {
tlsCfgFunc := func(cfg *tls.Config) {
cfg.MinVersion = tls.VersionTLS12
Expand Down

0 comments on commit 865f407

Please sign in to comment.