Skip to content

Commit

Permalink
Hook up v1a2 webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanv committed Sep 8, 2023
1 parent bb8c2c0 commit 5d462a1
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 4 deletions.
13 changes: 11 additions & 2 deletions webhooks/virtualmachine/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@ import (
ctrlmgr "sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/vmware-tanzu/vm-operator/pkg/context"
"github.com/vmware-tanzu/vm-operator/pkg/lib"
"github.com/vmware-tanzu/vm-operator/webhooks/virtualmachine/v1alpha1"
"github.com/vmware-tanzu/vm-operator/webhooks/virtualmachine/v1alpha2"
)

func AddToManager(ctx *context.ControllerManagerContext, mgr ctrlmgr.Manager) error {
if err := v1alpha1.AddToManager(ctx, mgr); err != nil {
return errors.Wrap(err, "failed to initialize v1alpha1 webhooks")
if lib.IsVMServiceV1Alpha2FSSEnabled() {
// TODO: We'll likely still need the v1a1 mutation wehbook (at least some limited version of it)
if err := v1alpha2.AddToManager(ctx, mgr); err != nil {
return errors.Wrap(err, "failed to initialize v1alpha2 webhooks")
}
} else {
if err := v1alpha1.AddToManager(ctx, mgr); err != nil {
return errors.Wrap(err, "failed to initialize v1alpha1 webhooks")
}
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion webhooks/virtualmachineclass/v1alpha2/webhooks.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2019-2023 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package virtualmachineclass
package v1alpha2

import (
"github.com/pkg/errors"
Expand Down
6 changes: 6 additions & 0 deletions webhooks/virtualmachineclass/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ import (
ctrlmgr "sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/vmware-tanzu/vm-operator/pkg/context"
"github.com/vmware-tanzu/vm-operator/pkg/lib"
"github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineclass/v1alpha1"
"github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineclass/v1alpha2"
)

func AddToManager(ctx *context.ControllerManagerContext, mgr ctrlmgr.Manager) error {
if lib.IsVMServiceV1Alpha2FSSEnabled() {
return v1alpha2.AddToManager(ctx, mgr)
}

return v1alpha1.AddToManager(ctx, mgr)
}
2 changes: 1 addition & 1 deletion webhooks/virtualmachinepublishrequest/v1alpha2/webhooks.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022-2023 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package virtualmachinepublishrequest
package v1alpha2

import (
"github.com/pkg/errors"
Expand Down
5 changes: 5 additions & 0 deletions webhooks/virtualmachinepublishrequest/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import (
ctrlmgr "sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/vmware-tanzu/vm-operator/pkg/context"
"github.com/vmware-tanzu/vm-operator/pkg/lib"
"github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinepublishrequest/v1alpha1"
"github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinepublishrequest/v1alpha2"
)

func AddToManager(ctx *context.ControllerManagerContext, mgr ctrlmgr.Manager) error {
if lib.IsVMServiceV1Alpha2FSSEnabled() {
return v1alpha2.AddToManager(ctx, mgr)
}
return v1alpha1.AddToManager(ctx, mgr)
}
5 changes: 5 additions & 0 deletions webhooks/virtualmachineservice/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import (
ctrlmgr "sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/vmware-tanzu/vm-operator/pkg/context"
"github.com/vmware-tanzu/vm-operator/pkg/lib"
"github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineservice/v1alpha1"
"github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineservice/v1alpha2"
)

func AddToManager(ctx *context.ControllerManagerContext, mgr ctrlmgr.Manager) error {
if lib.IsVMServiceV1Alpha2FSSEnabled() {
return v1alpha2.AddToManager(ctx, mgr)
}
return v1alpha1.AddToManager(ctx, mgr)
}
5 changes: 5 additions & 0 deletions webhooks/virtualmachinesetresourcepolicy/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import (
ctrlmgr "sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/vmware-tanzu/vm-operator/pkg/context"
"github.com/vmware-tanzu/vm-operator/pkg/lib"
"github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinesetresourcepolicy/v1alpha1"
"github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinesetresourcepolicy/v1alpha2"
)

func AddToManager(ctx *context.ControllerManagerContext, mgr ctrlmgr.Manager) error {
if lib.IsVMServiceV1Alpha2FSSEnabled() {
return v1alpha2.AddToManager(ctx, mgr)
}
return v1alpha1.AddToManager(ctx, mgr)
}

0 comments on commit 5d462a1

Please sign in to comment.