Skip to content

feat: give mutators a clusterGetter function #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func main() {
awsclusterconfig.NewVariable(),
awsworkerconfig.NewVariable(),
awsmutation.MetaPatchHandler(mgr),
awsmutation.MetaWorkerPatchHandler(),
awsmutation.MetaWorkerPatchHandler(mgr),
}

// dockerMetaHandlers combines all Docker patch and variable handlers under a single handler.
Expand All @@ -129,7 +129,7 @@ func main() {
dockerclusterconfig.NewVariable(),
dockerworkerconfig.NewVariable(),
dockermutation.MetaPatchHandler(mgr),
dockermutation.MetaWorkerPatchHandler(),
dockermutation.MetaWorkerPatchHandler(mgr),
}

// nutanixMetaHandlers combines all Nutanix patch and variable handlers under a single handler.
Expand All @@ -138,7 +138,7 @@ func main() {
nutanixclusterconfig.NewVariable(),
nutanixworkerconfig.NewVariable(),
nutanixmutation.MetaPatchHandler(mgr),
nutanixmutation.MetaWorkerPatchHandler(),
nutanixmutation.MetaWorkerPatchHandler(mgr),
}

var allHandlers []handlers.Named
Expand Down
32 changes: 30 additions & 2 deletions common/pkg/capi/clustertopology/handlers/mutation/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ package mutation

import (
"context"
"fmt"
"sync"

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
"sigs.k8s.io/cluster-api/exp/runtime/topologymutation"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -24,27 +27,33 @@ type MutateFunc func(
clusterKey client.ObjectKey,
) error

type ClusterGetter func(context.Context) (*clusterv1.Cluster, error)

type MetaMutator interface {
Mutate(
ctx context.Context,
obj *unstructured.Unstructured,
vars map[string]apiextensionsv1.JSON,
holderRef runtimehooksv1.HolderReference,
clusterKey client.ObjectKey,
getCluster ClusterGetter,
) error
}

type metaGeneratePatches struct {
name string
mutators []MetaMutator
cl client.Client
}

func NewMetaGeneratePatchesHandler(
name string,
cl client.Client,
mutators ...MetaMutator,
) handlers.Named {
return metaGeneratePatches{
name: name,
cl: cl,
mutators: mutators,
}
}
Expand All @@ -53,13 +62,32 @@ func (mgp metaGeneratePatches) Name() string {
return mgp.name
}

func (mgp metaGeneratePatches) CreateClusterGetter(
clusterKey client.ObjectKey,
) func(context.Context) (*clusterv1.Cluster, error) {
return func(ctx context.Context) (*clusterv1.Cluster, error) {
var (
cluster clusterv1.Cluster
err error
once sync.Once
)
once.Do(func() {
err = mgp.cl.Get(ctx, clusterKey, &cluster)
})
if err != nil {
return nil, fmt.Errorf("failed to fetch cluster %w", err)
}
return &cluster, nil
}
}

func (mgp metaGeneratePatches) GeneratePatches(
ctx context.Context,
req *runtimehooksv1.GeneratePatchesRequest,
resp *runtimehooksv1.GeneratePatchesResponse,
) {
clusterKey := handlers.ClusterKeyFromReq(req)

clusterGetter := mgp.CreateClusterGetter(clusterKey)
topologymutation.WalkTemplates(
ctx,
unstructured.UnstructuredJSONScheme,
Expand All @@ -72,7 +100,7 @@ func (mgp metaGeneratePatches) GeneratePatches(
holderRef runtimehooksv1.HolderReference,
) error {
for _, h := range mgp.mutators {
if err := h.Mutate(ctx, obj.(*unstructured.Unstructured), vars, holderRef, clusterKey); err != nil {
if err := h.Mutate(ctx, obj.(*unstructured.Unstructured), vars, holderRef, clusterKey, clusterGetter); err != nil {
return err
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (h *testHandler) Mutate(
_ map[string]apiextensionsv1.JSON,
holderRef runtimehooksv1.HolderReference,
_ client.ObjectKey,
_ ClusterGetter,
) error {
if h.returnErr {
return fmt.Errorf("This is a failure")
Expand Down Expand Up @@ -219,7 +220,7 @@ func TestMetaGeneratePatches(t *testing.T) {

g := gomega.NewWithT(t)

h := NewMetaGeneratePatchesHandler("", tt.mutaters...).(GeneratePatches)
h := NewMetaGeneratePatchesHandler("", nil, tt.mutaters...).(GeneratePatches)

resp := &runtimehooksv1.GeneratePatchesResponse{}
h.GeneratePatches(context.Background(), &runtimehooksv1.GeneratePatchesRequest{
Expand Down
2 changes: 2 additions & 0 deletions pkg/handlers/aws/mutation/ami/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

capav1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
)
Expand Down Expand Up @@ -48,6 +49,7 @@ func (h *awsAMISpecPatchHandler) Mutate(
vars map[string]apiextensionsv1.JSON,
holderRef runtimehooksv1.HolderReference,
_ client.ObjectKey,
_ mutation.ClusterGetter,
) error {
log := ctrl.LoggerFrom(ctx).WithValues(
"holderRef", holderRef,
Expand Down
6 changes: 5 additions & 1 deletion pkg/handlers/aws/mutation/ami/inject_control_plane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ import (
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/helpers"
)

var _ = Describe("Generate AMI patches for ControlPlane", func() {
patchGenerator := func() mutation.GeneratePatches {
return mutation.NewMetaGeneratePatchesHandler("", NewControlPlanePatch()).(mutation.GeneratePatches)
return mutation.NewMetaGeneratePatchesHandler("",
helpers.TestEnv.Client,
NewControlPlanePatch(),
).(mutation.GeneratePatches)
}

testDefs := []capitest.PatchTestDef{
Expand Down
3 changes: 2 additions & 1 deletion pkg/handlers/aws/mutation/ami/inject_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import (
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/workerconfig"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/helpers"
)

var _ = Describe("Generate AMI patches for Worker", func() {
patchGenerator := func() mutation.GeneratePatches {
return mutation.NewMetaGeneratePatchesHandler("", NewWorkerPatch()).(mutation.GeneratePatches)
return mutation.NewMetaGeneratePatchesHandler("", helpers.TestEnv.Client, NewWorkerPatch()).(mutation.GeneratePatches)
}

testDefs := []capitest.PatchTestDef{
Expand Down
2 changes: 2 additions & 0 deletions pkg/handlers/aws/mutation/cni/calico/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

capav1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
Expand Down Expand Up @@ -56,6 +57,7 @@ func (h *calicoPatchHandler) Mutate(
vars map[string]apiextensionsv1.JSON,
holderRef runtimehooksv1.HolderReference,
_ client.ObjectKey,
_ mutation.ClusterGetter,
) error {
log := ctrl.LoggerFrom(ctx).WithValues(
"holderRef", holderRef,
Expand Down
3 changes: 2 additions & 1 deletion pkg/handlers/aws/mutation/cni/calico/inject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/helpers"
)

func TestCalicoPatch(t *testing.T) {
Expand All @@ -25,7 +26,7 @@ func TestCalicoPatch(t *testing.T) {

var _ = Describe("Generate AWS Calico CNI ingress patches", func() {
patchGenerator := func() mutation.GeneratePatches {
return mutation.NewMetaGeneratePatchesHandler("", NewPatch()).(mutation.GeneratePatches)
return mutation.NewMetaGeneratePatchesHandler("", helpers.TestEnv.Client, NewPatch()).(mutation.GeneratePatches)
}

testDefs := []capitest.PatchTestDef{
Expand Down
2 changes: 2 additions & 0 deletions pkg/handlers/aws/mutation/controlplaneloadbalancer/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

capav1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
Expand Down Expand Up @@ -54,6 +55,7 @@ func (h *awsControlPlaneLoadBalancer) Mutate(
vars map[string]apiextensionsv1.JSON,
holderRef runtimehooksv1.HolderReference,
_ client.ObjectKey,
_ mutation.ClusterGetter,
) error {
log := ctrl.LoggerFrom(ctx).WithValues(
"holderRef", holderRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/helpers"
)

func TestControlPlaneLoadBalancerPatch(t *testing.T) {
Expand All @@ -25,7 +26,7 @@ func TestControlPlaneLoadBalancerPatch(t *testing.T) {

var _ = Describe("Generate AWS ControlPlane LoadBalancer patches", func() {
patchGenerator := func() mutation.GeneratePatches {
return mutation.NewMetaGeneratePatchesHandler("", NewPatch()).(mutation.GeneratePatches)
return mutation.NewMetaGeneratePatchesHandler("", helpers.TestEnv.Client, NewPatch()).(mutation.GeneratePatches)
}

testDefs := []capitest.PatchTestDef{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

capav1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
Expand Down Expand Up @@ -55,6 +56,7 @@ func (h *awsIAMInstanceProfileControlPlanePatchHandler) Mutate(
vars map[string]apiextensionsv1.JSON,
holderRef runtimehooksv1.HolderReference,
_ client.ObjectKey,
_ mutation.ClusterGetter,
) error {
log := ctrl.LoggerFrom(ctx).WithValues(
"holderRef", holderRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ import (
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/helpers"
)

var _ = Describe("Generate IAMInstanceProfile patches for ControlPlane", func() {
patchGenerator := func() mutation.GeneratePatches {
return mutation.NewMetaGeneratePatchesHandler("", NewControlPlanePatch()).(mutation.GeneratePatches)
return mutation.NewMetaGeneratePatchesHandler(
"",
helpers.TestEnv.Client,
NewControlPlanePatch(),
).(mutation.GeneratePatches)
}

testDefs := []capitest.PatchTestDef{
Expand Down
2 changes: 2 additions & 0 deletions pkg/handlers/aws/mutation/iaminstanceprofile/inject_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

capav1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
Expand Down Expand Up @@ -49,6 +50,7 @@ func (h *awsIAMInstanceProfileWorkerPatchHandler) Mutate(
vars map[string]apiextensionsv1.JSON,
holderRef runtimehooksv1.HolderReference,
_ client.ObjectKey,
_ mutation.ClusterGetter,
) error {
log := ctrl.LoggerFrom(ctx).WithValues(
"holderRef", holderRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import (
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/workerconfig"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/helpers"
)

var _ = Describe("Generate IAMInstanceProfile patches for Worker", func() {
patchGenerator := func() mutation.GeneratePatches {
return mutation.NewMetaGeneratePatchesHandler("", NewWorkerPatch()).(mutation.GeneratePatches)
return mutation.NewMetaGeneratePatchesHandler("", helpers.TestEnv.Client, NewWorkerPatch()).(mutation.GeneratePatches)
}

testDefs := []capitest.PatchTestDef{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

capav1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
Expand Down Expand Up @@ -55,6 +56,7 @@ func (h *awsInstanceTypeControlPlanePatchHandler) Mutate(
vars map[string]apiextensionsv1.JSON,
holderRef runtimehooksv1.HolderReference,
_ client.ObjectKey,
_ mutation.ClusterGetter,
) error {
log := ctrl.LoggerFrom(ctx).WithValues(
"holderRef", holderRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ import (
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/helpers"
)

var _ = Describe("Generate InstanceType patches for ControlPlane", func() {
patchGenerator := func() mutation.GeneratePatches {
return mutation.NewMetaGeneratePatchesHandler("", NewControlPlanePatch()).(mutation.GeneratePatches)
return mutation.NewMetaGeneratePatchesHandler(
"",
helpers.TestEnv.Client,
NewControlPlanePatch(),
).(mutation.GeneratePatches)
}

testDefs := []capitest.PatchTestDef{
Expand Down
2 changes: 2 additions & 0 deletions pkg/handlers/aws/mutation/instancetype/inject_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

capav1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
Expand Down Expand Up @@ -49,6 +50,7 @@ func (h *awsInstanceTypeWorkerPatchHandler) Mutate(
vars map[string]apiextensionsv1.JSON,
holderRef runtimehooksv1.HolderReference,
_ client.ObjectKey,
_ mutation.ClusterGetter,
) error {
log := ctrl.LoggerFrom(ctx).WithValues(
"holderRef", holderRef,
Expand Down
3 changes: 2 additions & 1 deletion pkg/handlers/aws/mutation/instancetype/inject_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import (
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/workerconfig"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/helpers"
)

var _ = Describe("Generate InstanceType patches for Worker", func() {
patchGenerator := func() mutation.GeneratePatches {
return mutation.NewMetaGeneratePatchesHandler("", NewWorkerPatch()).(mutation.GeneratePatches)
return mutation.NewMetaGeneratePatchesHandler("", helpers.TestEnv.Client, NewWorkerPatch()).(mutation.GeneratePatches)
}

testDefs := []capitest.PatchTestDef{
Expand Down
4 changes: 3 additions & 1 deletion pkg/handlers/aws/mutation/metapatch_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ func MetaPatchHandler(mgr manager.Manager) handlers.Named {

return mutation.NewMetaGeneratePatchesHandler(
"awsClusterConfigPatch",
mgr.GetClient(),
patchHandlers...,
)
}

// MetaWorkerPatchHandler returns a meta patch handler for mutating CAPA workers.
func MetaWorkerPatchHandler() handlers.Named {
func MetaWorkerPatchHandler(mgr manager.Manager) handlers.Named {
patchHandlers := []mutation.MetaMutator{
iaminstanceprofile.NewWorkerPatch(),
instancetype.NewWorkerPatch(),
Expand All @@ -52,6 +53,7 @@ func MetaWorkerPatchHandler() handlers.Named {

return mutation.NewMetaGeneratePatchesHandler(
"awsWorkerConfigPatch",
mgr.GetClient(),
patchHandlers...,
)
}
Loading
Loading