Skip to content

Commit 113f9db

Browse files
authored
feat: give mutators a clusterGetter function (#514)
<!-- Copyright 2023 D2iQ, Inc. All rights reserved. SPDX-License-Identifier: Apache-2.0 --> **What problem does this PR solve?**: Adds a reusable function across mutators to return a cluster. This is lazily evaluated and happens once per mutation **Which issue(s) this PR fixes**: **How Has This Been Tested?**: <!-- Please describe the tests that you ran to verify your changes. Provide output from the tests and any manual steps needed to replicate the tests. --> tested manually be creating a docker cluster ``` apiVersion: v1 items: - apiVersion: controlplane.cluster.x-k8s.io/v1beta1 kind: KubeadmControlPlane metadata: annotations: cluster.x-k8s.io/cloned-from-groupkind: KubeadmControlPlaneTemplate.controlplane.cluster.x-k8s.io cluster.x-k8s.io/cloned-from-name: docker-quick-start-control-plane creationTimestamp: "2024-04-15T21:20:06Z" finalizers: - kubeadm.controlplane.cluster.x-k8s.io generation: 1 labels: cluster.x-k8s.io/cluster-name: docker-cluster-cilium-helm-addon topology.cluster.x-k8s.io/owned: "" name: docker-cluster-cilium-helm-addon-kr6lc namespace: default ownerReferences: - apiVersion: cluster.x-k8s.io/v1beta1 blockOwnerDeletion: true controller: true kind: Cluster name: docker-cluster-cilium-helm-addon uid: d7d3b9b5-3a4c-4a2f-b5b1-1b46b3c6f9e9 resourceVersion: "2512" uid: 11809f5a-5202-4fac-bd7b-7c96b17d437c spec: kubeadmConfigSpec: clusterConfiguration: apiServer: certSANs: - localhost - 127.0.0.1 - 0.0.0.0 - host.docker.internal ``` **Special notes for your reviewer**: <!-- Use this to provide any additional information to the reviewers. This may include: - Best way to review the PR. - Where the author wants the most review attention on. - etc. -->
1 parent 86b23e7 commit 113f9db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+222
-57
lines changed

cmd/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func main() {
120120
awsclusterconfig.NewVariable(),
121121
awsworkerconfig.NewVariable(),
122122
awsmutation.MetaPatchHandler(mgr),
123-
awsmutation.MetaWorkerPatchHandler(),
123+
awsmutation.MetaWorkerPatchHandler(mgr),
124124
}
125125

126126
// dockerMetaHandlers combines all Docker patch and variable handlers under a single handler.
@@ -129,7 +129,7 @@ func main() {
129129
dockerclusterconfig.NewVariable(),
130130
dockerworkerconfig.NewVariable(),
131131
dockermutation.MetaPatchHandler(mgr),
132-
dockermutation.MetaWorkerPatchHandler(),
132+
dockermutation.MetaWorkerPatchHandler(mgr),
133133
}
134134

135135
// nutanixMetaHandlers combines all Nutanix patch and variable handlers under a single handler.
@@ -138,7 +138,7 @@ func main() {
138138
nutanixclusterconfig.NewVariable(),
139139
nutanixworkerconfig.NewVariable(),
140140
nutanixmutation.MetaPatchHandler(mgr),
141-
nutanixmutation.MetaWorkerPatchHandler(),
141+
nutanixmutation.MetaWorkerPatchHandler(mgr),
142142
}
143143

144144
var allHandlers []handlers.Named

common/pkg/capi/clustertopology/handlers/mutation/meta.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ package mutation
55

66
import (
77
"context"
8+
"fmt"
9+
"sync"
810

911
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1012
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1113
"k8s.io/apimachinery/pkg/runtime"
14+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1215
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
1316
"sigs.k8s.io/cluster-api/exp/runtime/topologymutation"
1417
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -24,27 +27,33 @@ type MutateFunc func(
2427
clusterKey client.ObjectKey,
2528
) error
2629

30+
type ClusterGetter func(context.Context) (*clusterv1.Cluster, error)
31+
2732
type MetaMutator interface {
2833
Mutate(
2934
ctx context.Context,
3035
obj *unstructured.Unstructured,
3136
vars map[string]apiextensionsv1.JSON,
3237
holderRef runtimehooksv1.HolderReference,
3338
clusterKey client.ObjectKey,
39+
getCluster ClusterGetter,
3440
) error
3541
}
3642

3743
type metaGeneratePatches struct {
3844
name string
3945
mutators []MetaMutator
46+
cl client.Client
4047
}
4148

4249
func NewMetaGeneratePatchesHandler(
4350
name string,
51+
cl client.Client,
4452
mutators ...MetaMutator,
4553
) handlers.Named {
4654
return metaGeneratePatches{
4755
name: name,
56+
cl: cl,
4857
mutators: mutators,
4958
}
5059
}
@@ -53,13 +62,32 @@ func (mgp metaGeneratePatches) Name() string {
5362
return mgp.name
5463
}
5564

65+
func (mgp metaGeneratePatches) CreateClusterGetter(
66+
clusterKey client.ObjectKey,
67+
) func(context.Context) (*clusterv1.Cluster, error) {
68+
return func(ctx context.Context) (*clusterv1.Cluster, error) {
69+
var (
70+
cluster clusterv1.Cluster
71+
err error
72+
once sync.Once
73+
)
74+
once.Do(func() {
75+
err = mgp.cl.Get(ctx, clusterKey, &cluster)
76+
})
77+
if err != nil {
78+
return nil, fmt.Errorf("failed to fetch cluster %w", err)
79+
}
80+
return &cluster, nil
81+
}
82+
}
83+
5684
func (mgp metaGeneratePatches) GeneratePatches(
5785
ctx context.Context,
5886
req *runtimehooksv1.GeneratePatchesRequest,
5987
resp *runtimehooksv1.GeneratePatchesResponse,
6088
) {
6189
clusterKey := handlers.ClusterKeyFromReq(req)
62-
90+
clusterGetter := mgp.CreateClusterGetter(clusterKey)
6391
topologymutation.WalkTemplates(
6492
ctx,
6593
unstructured.UnstructuredJSONScheme,
@@ -72,7 +100,7 @@ func (mgp metaGeneratePatches) GeneratePatches(
72100
holderRef runtimehooksv1.HolderReference,
73101
) error {
74102
for _, h := range mgp.mutators {
75-
if err := h.Mutate(ctx, obj.(*unstructured.Unstructured), vars, holderRef, clusterKey); err != nil {
103+
if err := h.Mutate(ctx, obj.(*unstructured.Unstructured), vars, holderRef, clusterKey, clusterGetter); err != nil {
76104
return err
77105
}
78106
}

common/pkg/capi/clustertopology/handlers/mutation/meta_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func (h *testHandler) Mutate(
3737
_ map[string]apiextensionsv1.JSON,
3838
holderRef runtimehooksv1.HolderReference,
3939
_ client.ObjectKey,
40+
_ ClusterGetter,
4041
) error {
4142
if h.returnErr {
4243
return fmt.Errorf("This is a failure")
@@ -219,7 +220,7 @@ func TestMetaGeneratePatches(t *testing.T) {
219220

220221
g := gomega.NewWithT(t)
221222

222-
h := NewMetaGeneratePatchesHandler("", tt.mutaters...).(GeneratePatches)
223+
h := NewMetaGeneratePatchesHandler("", nil, tt.mutaters...).(GeneratePatches)
223224

224225
resp := &runtimehooksv1.GeneratePatchesResponse{}
225226
h.GeneratePatches(context.Background(), &runtimehooksv1.GeneratePatchesRequest{

pkg/handlers/aws/mutation/ami/inject.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
capav1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
1717
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
18+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
1819
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches"
1920
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
2021
)
@@ -48,6 +49,7 @@ func (h *awsAMISpecPatchHandler) Mutate(
4849
vars map[string]apiextensionsv1.JSON,
4950
holderRef runtimehooksv1.HolderReference,
5051
_ client.ObjectKey,
52+
_ mutation.ClusterGetter,
5153
) error {
5254
log := ctrl.LoggerFrom(ctx).WithValues(
5355
"holderRef", holderRef,

pkg/handlers/aws/mutation/ami/inject_control_plane_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ import (
1313
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
1414
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
1515
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig"
16+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/helpers"
1617
)
1718

1819
var _ = Describe("Generate AMI patches for ControlPlane", func() {
1920
patchGenerator := func() mutation.GeneratePatches {
20-
return mutation.NewMetaGeneratePatchesHandler("", NewControlPlanePatch()).(mutation.GeneratePatches)
21+
return mutation.NewMetaGeneratePatchesHandler("",
22+
helpers.TestEnv.Client,
23+
NewControlPlanePatch(),
24+
).(mutation.GeneratePatches)
2125
}
2226

2327
testDefs := []capitest.PatchTestDef{

pkg/handlers/aws/mutation/ami/inject_worker_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ import (
1414
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
1515
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
1616
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/workerconfig"
17+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/helpers"
1718
)
1819

1920
var _ = Describe("Generate AMI patches for Worker", func() {
2021
patchGenerator := func() mutation.GeneratePatches {
21-
return mutation.NewMetaGeneratePatchesHandler("", NewWorkerPatch()).(mutation.GeneratePatches)
22+
return mutation.NewMetaGeneratePatchesHandler("", helpers.TestEnv.Client, NewWorkerPatch()).(mutation.GeneratePatches)
2223
}
2324

2425
testDefs := []capitest.PatchTestDef{

pkg/handlers/aws/mutation/cni/calico/inject.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
capav1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
1818
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
19+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
1920
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches"
2021
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors"
2122
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
@@ -56,6 +57,7 @@ func (h *calicoPatchHandler) Mutate(
5657
vars map[string]apiextensionsv1.JSON,
5758
holderRef runtimehooksv1.HolderReference,
5859
_ client.ObjectKey,
60+
_ mutation.ClusterGetter,
5961
) error {
6062
log := ctrl.LoggerFrom(ctx).WithValues(
6163
"holderRef", holderRef,

pkg/handlers/aws/mutation/cni/calico/inject_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
1717
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
1818
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig"
19+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/helpers"
1920
)
2021

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

2627
var _ = Describe("Generate AWS Calico CNI ingress patches", func() {
2728
patchGenerator := func() mutation.GeneratePatches {
28-
return mutation.NewMetaGeneratePatchesHandler("", NewPatch()).(mutation.GeneratePatches)
29+
return mutation.NewMetaGeneratePatchesHandler("", helpers.TestEnv.Client, NewPatch()).(mutation.GeneratePatches)
2930
}
3031

3132
testDefs := []capitest.PatchTestDef{

pkg/handlers/aws/mutation/controlplaneloadbalancer/inject.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
capav1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
1616
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
17+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
1718
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches"
1819
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors"
1920
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
@@ -54,6 +55,7 @@ func (h *awsControlPlaneLoadBalancer) Mutate(
5455
vars map[string]apiextensionsv1.JSON,
5556
holderRef runtimehooksv1.HolderReference,
5657
_ client.ObjectKey,
58+
_ mutation.ClusterGetter,
5759
) error {
5860
log := ctrl.LoggerFrom(ctx).WithValues(
5961
"holderRef", holderRef,

pkg/handlers/aws/mutation/controlplaneloadbalancer/inject_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
1717
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
1818
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig"
19+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/helpers"
1920
)
2021

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

2627
var _ = Describe("Generate AWS ControlPlane LoadBalancer patches", func() {
2728
patchGenerator := func() mutation.GeneratePatches {
28-
return mutation.NewMetaGeneratePatchesHandler("", NewPatch()).(mutation.GeneratePatches)
29+
return mutation.NewMetaGeneratePatchesHandler("", helpers.TestEnv.Client, NewPatch()).(mutation.GeneratePatches)
2930
}
3031

3132
testDefs := []capitest.PatchTestDef{

pkg/handlers/aws/mutation/iaminstanceprofile/inject_control_plane.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
capav1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
1616
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
17+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
1718
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches"
1819
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors"
1920
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
@@ -55,6 +56,7 @@ func (h *awsIAMInstanceProfileControlPlanePatchHandler) Mutate(
5556
vars map[string]apiextensionsv1.JSON,
5657
holderRef runtimehooksv1.HolderReference,
5758
_ client.ObjectKey,
59+
_ mutation.ClusterGetter,
5860
) error {
5961
log := ctrl.LoggerFrom(ctx).WithValues(
6062
"holderRef", holderRef,

pkg/handlers/aws/mutation/iaminstanceprofile/inject_control_plane_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ import (
1313
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
1414
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
1515
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig"
16+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/helpers"
1617
)
1718

1819
var _ = Describe("Generate IAMInstanceProfile patches for ControlPlane", func() {
1920
patchGenerator := func() mutation.GeneratePatches {
20-
return mutation.NewMetaGeneratePatchesHandler("", NewControlPlanePatch()).(mutation.GeneratePatches)
21+
return mutation.NewMetaGeneratePatchesHandler(
22+
"",
23+
helpers.TestEnv.Client,
24+
NewControlPlanePatch(),
25+
).(mutation.GeneratePatches)
2126
}
2227

2328
testDefs := []capitest.PatchTestDef{

pkg/handlers/aws/mutation/iaminstanceprofile/inject_worker.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
capav1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
1616
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
17+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
1718
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches"
1819
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors"
1920
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
@@ -49,6 +50,7 @@ func (h *awsIAMInstanceProfileWorkerPatchHandler) Mutate(
4950
vars map[string]apiextensionsv1.JSON,
5051
holderRef runtimehooksv1.HolderReference,
5152
_ client.ObjectKey,
53+
_ mutation.ClusterGetter,
5254
) error {
5355
log := ctrl.LoggerFrom(ctx).WithValues(
5456
"holderRef", holderRef,

pkg/handlers/aws/mutation/iaminstanceprofile/inject_worker_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ import (
1414
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
1515
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
1616
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/workerconfig"
17+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/helpers"
1718
)
1819

1920
var _ = Describe("Generate IAMInstanceProfile patches for Worker", func() {
2021
patchGenerator := func() mutation.GeneratePatches {
21-
return mutation.NewMetaGeneratePatchesHandler("", NewWorkerPatch()).(mutation.GeneratePatches)
22+
return mutation.NewMetaGeneratePatchesHandler("", helpers.TestEnv.Client, NewWorkerPatch()).(mutation.GeneratePatches)
2223
}
2324

2425
testDefs := []capitest.PatchTestDef{

pkg/handlers/aws/mutation/instancetype/inject_control_plane.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
capav1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
1616
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
17+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
1718
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches"
1819
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors"
1920
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
@@ -55,6 +56,7 @@ func (h *awsInstanceTypeControlPlanePatchHandler) Mutate(
5556
vars map[string]apiextensionsv1.JSON,
5657
holderRef runtimehooksv1.HolderReference,
5758
_ client.ObjectKey,
59+
_ mutation.ClusterGetter,
5860
) error {
5961
log := ctrl.LoggerFrom(ctx).WithValues(
6062
"holderRef", holderRef,

pkg/handlers/aws/mutation/instancetype/inject_control_plane_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ import (
1313
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
1414
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
1515
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig"
16+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/helpers"
1617
)
1718

1819
var _ = Describe("Generate InstanceType patches for ControlPlane", func() {
1920
patchGenerator := func() mutation.GeneratePatches {
20-
return mutation.NewMetaGeneratePatchesHandler("", NewControlPlanePatch()).(mutation.GeneratePatches)
21+
return mutation.NewMetaGeneratePatchesHandler(
22+
"",
23+
helpers.TestEnv.Client,
24+
NewControlPlanePatch(),
25+
).(mutation.GeneratePatches)
2126
}
2227

2328
testDefs := []capitest.PatchTestDef{

pkg/handlers/aws/mutation/instancetype/inject_worker.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
capav1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
1616
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
17+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
1718
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches"
1819
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors"
1920
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
@@ -49,6 +50,7 @@ func (h *awsInstanceTypeWorkerPatchHandler) Mutate(
4950
vars map[string]apiextensionsv1.JSON,
5051
holderRef runtimehooksv1.HolderReference,
5152
_ client.ObjectKey,
53+
_ mutation.ClusterGetter,
5254
) error {
5355
log := ctrl.LoggerFrom(ctx).WithValues(
5456
"holderRef", holderRef,

pkg/handlers/aws/mutation/instancetype/inject_worker_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ import (
1414
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
1515
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
1616
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/workerconfig"
17+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/test/helpers"
1718
)
1819

1920
var _ = Describe("Generate InstanceType patches for Worker", func() {
2021
patchGenerator := func() mutation.GeneratePatches {
21-
return mutation.NewMetaGeneratePatchesHandler("", NewWorkerPatch()).(mutation.GeneratePatches)
22+
return mutation.NewMetaGeneratePatchesHandler("", helpers.TestEnv.Client, NewWorkerPatch()).(mutation.GeneratePatches)
2223
}
2324

2425
testDefs := []capitest.PatchTestDef{

pkg/handlers/aws/mutation/metapatch_handler.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ func MetaPatchHandler(mgr manager.Manager) handlers.Named {
3737

3838
return mutation.NewMetaGeneratePatchesHandler(
3939
"awsClusterConfigPatch",
40+
mgr.GetClient(),
4041
patchHandlers...,
4142
)
4243
}
4344

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

5354
return mutation.NewMetaGeneratePatchesHandler(
5455
"awsWorkerConfigPatch",
56+
mgr.GetClient(),
5557
patchHandlers...,
5658
)
5759
}

0 commit comments

Comments
 (0)