Skip to content

fix: use a new version for control-plane and worker mutation handlers #1104

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 1 commit into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ See [upstream documentation](https://cluster-api.sigs.k8s.io/tasks/experimental-

## Development

### Implementing Topology Mutation Handler

See examples of existing [topology mutation handlers] in the `pkg/handlers/../mutation/` directory.
When adding a new handler, or modifying an existing one, pay close attention to what happens to existing clusters
when a new version of this extension is deployed in the management cluster,
and avoid rollouts of Machines in those existing clusters.

During CAPI provider upgrades, and periodically, all managed clusters are reconciled and mutation handler patches
are applied.
Any new handlers that return a new set of patches, or updated handlers that return a different set of patches,
will be applied causing a rollout of Machines in all managed clusters.

For example, when adding a new handler, a handler that is enabled by default and returns CAPI resources patches,
will cause a rollout of Machines.
Similarly, if a handler is modified to return a different set of patches, it will also cause a rollout of Machines.

### Run Locally

Install tools

- [Devbox](https://github.com/jetpack-io/devbox?tab=readme-ov-file#installing-devbox)
Expand Down Expand Up @@ -153,3 +171,5 @@ To delete the dev KinD cluster, run:
```shell
make kind.delete
```

[topology mutation handlers]: https://cluster-api.sigs.k8s.io/tasks/experimental-features/runtime-sdk/implement-topology-mutation-hook#implementing-topology-mutation-hook-runtime-extensions
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ spec:
name: cluster-config
- external:
discoverVariablesExtension: awsworkerconfigvars-dv.cluster-api-runtime-extensions-nutanix
generateExtension: awsworkerconfigpatch-gp.cluster-api-runtime-extensions-nutanix
generateExtension: awsworkerv3configpatch-gp.cluster-api-runtime-extensions-nutanix
name: worker-config
- definitions:
- jsonPatches:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ spec:
name: cluster-config
- external:
discoverVariablesExtension: dockerworkerconfigvars-dv.cluster-api-runtime-extensions-nutanix
generateExtension: dockerworkerconfigpatch-gp.cluster-api-runtime-extensions-nutanix
generateExtension: dockerworkerv3configpatch-gp.cluster-api-runtime-extensions-nutanix
name: worker-config
workers:
machineDeployments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ spec:
name: cluster-config
- external:
discoverVariablesExtension: nutanixworkerconfigvars-dv.cluster-api-runtime-extensions-nutanix
generateExtension: nutanixworkerconfigpatch-gp.cluster-api-runtime-extensions-nutanix
generateExtension: nutanixworkerv3configpatch-gp.cluster-api-runtime-extensions-nutanix
name: worker-config
workers:
machineDeployments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ The required values are shown below per provider.
patches:
- external:
discoverVariablesExtension: awsclusterconfigvars.cluster-api-runtime-extensions-nutanix
generateExtension: awsclusterconfigpatch.cluster-api-runtime-extensions-nutanix
generateExtension: awsclusterv3configpatch.cluster-api-runtime-extensions-nutanix
name: cluster-config
- external:
discoverVariablesExtension: awsworkerconfigvars.cluster-api-runtime-extensions-nutanix
generateExtension: awsworkerconfigpatch.cluster-api-runtime-extensions-nutanix
generateExtension: awsworkerv3configpatch.cluster-api-runtime-extensions-nutanix
name: worker-config
```

Expand All @@ -35,11 +35,11 @@ The required values are shown below per provider.
patches:
- external:
discoverVariablesExtension: nutanixclusterconfigvars.cluster-api-runtime-extensions-nutanix
generateExtension: nutanixclusterconfigpatch.cluster-api-runtime-extensions-nutanix
generateExtension: nutanixclusterv3configpatch.cluster-api-runtime-extensions-nutanix
name: cluster-config
- external:
discoverVariablesExtension: nutanixworkerconfigvars.cluster-api-runtime-extensions-nutanix
generateExtension: nutanixworkerconfigpatch.cluster-api-runtime-extensions-nutanix
generateExtension: nutanixworkerv3configpatch.cluster-api-runtime-extensions-nutanix
name: worker-config
```

Expand All @@ -49,11 +49,11 @@ The required values are shown below per provider.
patches:
- external:
discoverVariablesExtension: dockerclusterconfigvars.cluster-api-runtime-extensions-nutanix
generateExtension: dockerclusterconfigpatch.cluster-api-runtime-extensions-nutanix
generateExtension: dockerclusterv3configpatch.cluster-api-runtime-extensions-nutanix
name: cluster-config
- external:
discoverVariablesExtension: dockerworkerconfigvars.cluster-api-runtime-extensions-nutanix
generateExtension: dockerworkerconfigpatch.cluster-api-runtime-extensions-nutanix
generateExtension: dockerworkerv3configpatch.cluster-api-runtime-extensions-nutanix
name: worker-config
```

Expand All @@ -63,7 +63,7 @@ The required values are shown below per provider.
patches:
- external:
discoverVariablesExtension: genericclusterconfigvars.cluster-api-runtime-extensions-nutanix
generateExtension: genericclusterconfigpatch.cluster-api-runtime-extensions-nutanix
generateExtension: genericclusterv3configpatch.cluster-api-runtime-extensions-nutanix
name: cluster-config
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ patches:
discoverVariablesExtension: "awsclusterconfigvars-dv.cluster-api-runtime-extensions-nutanix"
- name: "worker-config"
external:
generateExtension: "awsworkerconfigpatch-gp.cluster-api-runtime-extensions-nutanix"
generateExtension: "awsworkerv3configpatch-gp.cluster-api-runtime-extensions-nutanix"
discoverVariablesExtension: "awsworkerconfigvars-dv.cluster-api-runtime-extensions-nutanix"
- name: identityRef
definitions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ patches:
discoverVariablesExtension: "dockerclusterconfigvars-dv.cluster-api-runtime-extensions-nutanix"
- name: "worker-config"
external:
generateExtension: "dockerworkerconfigpatch-gp.cluster-api-runtime-extensions-nutanix"
generateExtension: "dockerworkerv3configpatch-gp.cluster-api-runtime-extensions-nutanix"
discoverVariablesExtension: "dockerworkerconfigvars-dv.cluster-api-runtime-extensions-nutanix"
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ patches:
discoverVariablesExtension: "nutanixclusterconfigvars-dv.cluster-api-runtime-extensions-nutanix"
- name: "worker-config"
external:
generateExtension: "nutanixworkerconfigpatch-gp.cluster-api-runtime-extensions-nutanix"
generateExtension: "nutanixworkerv3configpatch-gp.cluster-api-runtime-extensions-nutanix"
discoverVariablesExtension: "nutanixworkerconfigvars-dv.cluster-api-runtime-extensions-nutanix"
1 change: 1 addition & 0 deletions pkg/handlers/aws/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (h *Handlers) AllHandlers(mgr manager.Manager) []handlers.Named {
awsmutation.MetaPatchHandler(mgr),
v2awsmutation.MetaPatchHandler(mgr),
awsmutation.MetaWorkerPatchHandler(mgr),
v2awsmutation.MetaWorkerPatchHandler(mgr),
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/aws/mutation/metapatch_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func MetaWorkerPatchHandler(mgr manager.Manager) handlers.Named {
patchHandlers = append(patchHandlers, genericmutation.WorkerMetaMutators()...)

return mutation.NewMetaGeneratePatchesHandler(
"awsWorkerConfigPatch",
"awsWorkerv3ConfigPatch",
mgr.GetClient(),
patchHandlers...,
)
Expand Down
1 change: 1 addition & 0 deletions pkg/handlers/docker/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (h *Handlers) AllHandlers(mgr manager.Manager) []handlers.Named {
dockermutation.MetaPatchHandler(mgr),
v2dockermutation.MetaPatchHandler(mgr),
dockermutation.MetaWorkerPatchHandler(mgr),
v2dockermutation.MetaWorkerPatchHandler(mgr),
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/docker/mutation/metapatch_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func MetaWorkerPatchHandler(mgr manager.Manager) handlers.Named {
patchHandlers = append(patchHandlers, genericmutation.WorkerMetaMutators()...)

return mutation.NewMetaGeneratePatchesHandler(
"dockerWorkerConfigPatch",
"dockerWorkerV3ConfigPatch",
mgr.GetClient(),
patchHandlers...,
)
Expand Down
1 change: 1 addition & 0 deletions pkg/handlers/generic/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ func (h *Handlers) AllHandlers(mgr manager.Manager) []handlers.Named {
genericmutation.MetaPatchHandler(mgr),
v2genericmutation.MetaPatchHandler(mgr),
genericmutation.MetaWorkerPatchHandler(mgr),
v2genericmutation.MetaWorkerPatchHandler(mgr),
}
}
4 changes: 2 additions & 2 deletions pkg/handlers/generic/mutation/metapatch_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func MetaPatchHandler(mgr manager.Manager) handlers.Named {
patchHandlers := MetaMutators(mgr)
patchHandlers = append(patchHandlers, ControlPlaneMetaMutators()...)
return mutation.NewMetaGeneratePatchesHandler(
"genericClusterV2ConfigPatch",
"genericClusterV3ConfigPatch",
mgr.GetClient(),
patchHandlers...,
)
Expand All @@ -26,7 +26,7 @@ func MetaWorkerPatchHandler(mgr manager.Manager) handlers.Named {
patchHandlers := WorkerMetaMutators()

return mutation.NewMetaGeneratePatchesHandler(
"genericWorkerConfigPatch",
"genericWorkerV3ConfigPatch",
mgr.GetClient(),
patchHandlers...,
)
Expand Down
1 change: 1 addition & 0 deletions pkg/handlers/nutanix/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (h *Handlers) AllHandlers(mgr manager.Manager) []handlers.Named {
nutanixmutation.MetaPatchHandler(mgr),
v2nutanixmutation.MetaPatchHandler(mgr, h.controlPlaneVirtualIPConfig),
nutanixmutation.MetaWorkerPatchHandler(mgr),
v2nutanixmutation.MetaWorkerPatchHandler(mgr),
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/nutanix/mutation/metapatch_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func MetaWorkerPatchHandler(mgr manager.Manager) handlers.Named {
patchHandlers = append(patchHandlers, genericmutation.WorkerMetaMutators()...)

return mutation.NewMetaGeneratePatchesHandler(
"nutanixWorkerConfigPatch",
"nutanixWorkerV3ConfigPatch",
mgr.GetClient(),
patchHandlers...,
)
Expand Down
24 changes: 21 additions & 3 deletions pkg/handlers/v2/aws/mutation/metapatch_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/mutation/network"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/mutation/region"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/mutation/securitygroups"
genericmutation "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/mutation"
genericmutationv2 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/v2/generic/mutation"
)

// MetaPatchHandler returns a meta patch handler for mutating CAPA clusters.
Expand All @@ -31,12 +31,30 @@ func MetaPatchHandler(mgr manager.Manager) handlers.Named {
ami.NewControlPlanePatch(),
securitygroups.NewControlPlanePatch(),
}
patchHandlers = append(patchHandlers, genericmutation.MetaMutators(mgr)...)
patchHandlers = append(patchHandlers, genericmutation.ControlPlaneMetaMutators()...)
patchHandlers = append(patchHandlers, genericmutationv2.MetaMutators(mgr)...)
patchHandlers = append(patchHandlers, genericmutationv2.ControlPlaneMetaMutators()...)

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

// MetaWorkerPatchHandler returns a meta patch handler for mutating CAPA workers.
func MetaWorkerPatchHandler(mgr manager.Manager) handlers.Named {
patchHandlers := []mutation.MetaMutator{
iaminstanceprofile.NewWorkerPatch(),
instancetype.NewWorkerPatch(),
ami.NewWorkerPatch(),
securitygroups.NewWorkerPatch(),
}
patchHandlers = append(patchHandlers, genericmutationv2.WorkerMetaMutators()...)

// The previous handler did not have "v2" in the name.
return mutation.NewMetaGeneratePatchesHandler(
"awsWorkerConfigPatch",
mgr.GetClient(),
patchHandlers...,
)
}
21 changes: 18 additions & 3 deletions pkg/handlers/v2/docker/mutation/metapatch_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,35 @@ import (
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers"
"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/pkg/handlers/docker/mutation/customimage"
genericmutation "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/mutation"
genericmutationv2 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/v2/generic/mutation"
)

// MetaPatchHandler returns a meta patch handler for mutating CAPD clusters.
func MetaPatchHandler(mgr manager.Manager) handlers.Named {
patchHandlers := []mutation.MetaMutator{
customimage.NewControlPlanePatch(),
}
patchHandlers = append(patchHandlers, genericmutation.MetaMutators(mgr)...)
patchHandlers = append(patchHandlers, genericmutation.ControlPlaneMetaMutators()...)
patchHandlers = append(patchHandlers, genericmutationv2.MetaMutators(mgr)...)
patchHandlers = append(patchHandlers, genericmutationv2.ControlPlaneMetaMutators()...)

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

// MetaWorkerPatchHandler returns a meta patch handler for mutating CAPD workers.
func MetaWorkerPatchHandler(mgr manager.Manager) handlers.Named {
patchHandlers := []mutation.MetaMutator{
customimage.NewWorkerPatch(),
}
patchHandlers = append(patchHandlers, genericmutationv2.WorkerMetaMutators()...)

// The previous handler did not have "v2" in the name.
return mutation.NewMetaGeneratePatchesHandler(
"dockerWorkerConfigPatch",
mgr.GetClient(),
patchHandlers...,
)
}
19 changes: 19 additions & 0 deletions pkg/handlers/v2/generic/mutation/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/mutation/imageregistries/credentials"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/mutation/kubernetesimagerepository"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/mutation/mirrors"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/mutation/taints"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/mutation/users"
)

Expand Down Expand Up @@ -54,3 +55,21 @@ func MetaMutators(mgr manager.Manager) []mutation.MetaMutator {
containerdapplypatchesandrestart.NewPatch(),
}
}

func ControlPlaneMetaMutators() []mutation.MetaMutator {
return []mutation.MetaMutator{
taints.NewControlPlanePatch(),
// Intentionally not include this patch as it was not available in previous version the hook,
// and it uses an API is on by default, which causes a rollout of all Machines in all managed clusters.
// noderegistration.NewControlPlanePatch(),
}
}

func WorkerMetaMutators() []mutation.MetaMutator {
return []mutation.MetaMutator{
taints.NewWorkerPatch(),
// Intentionally not include this patch as it was not available in previous version the hook,
// and it uses an API is on by default, which causes a rollout of all Machines in all managed clusters.
// noderegistration.NewControlPlanePatch(),
}
}
14 changes: 12 additions & 2 deletions pkg/handlers/v2/generic/mutation/metapatch_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,26 @@ import (

"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
genericmutation "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/mutation"
)

// MetaPatchHandler returns a meta patch handler for mutating generic Kubernetes clusters.
func MetaPatchHandler(mgr manager.Manager) handlers.Named {
patchHandlers := MetaMutators(mgr)
patchHandlers = append(patchHandlers, genericmutation.ControlPlaneMetaMutators()...)
patchHandlers = append(patchHandlers, ControlPlaneMetaMutators()...)
return mutation.NewMetaGeneratePatchesHandler(
"genericClusterConfigPatch",
mgr.GetClient(),
patchHandlers...,
)
}

// MetaWorkerPatchHandler returns a meta patch handler for mutating generic workers.
func MetaWorkerPatchHandler(mgr manager.Manager) handlers.Named {
patchHandlers := WorkerMetaMutators()

return mutation.NewMetaGeneratePatchesHandler(
"genericWorkerConfigPatch",
mgr.GetClient(),
patchHandlers...,
)
}
21 changes: 18 additions & 3 deletions pkg/handlers/v2/nutanix/mutation/metapatch_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
genericmutation "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/mutation"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/mutation/controlplaneendpoint"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/mutation/machinedetails"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/mutation/prismcentralendpoint"
genericmutationv2 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/v2/generic/mutation"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/v2/generic/mutation/controlplanevirtualip"
nutanixcontrolplanevirtualip "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/v2/nutanix/mutation/controlplanevirtualip"
)
Expand All @@ -24,12 +24,27 @@ func MetaPatchHandler(mgr manager.Manager, cfg *controlplanevirtualip.Config) ha
prismcentralendpoint.NewPatch(),
machinedetails.NewControlPlanePatch(),
}
patchHandlers = append(patchHandlers, genericmutation.MetaMutators(mgr)...)
patchHandlers = append(patchHandlers, genericmutation.ControlPlaneMetaMutators()...)
patchHandlers = append(patchHandlers, genericmutationv2.MetaMutators(mgr)...)
patchHandlers = append(patchHandlers, genericmutationv2.ControlPlaneMetaMutators()...)

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

// MetaWorkerPatchHandler returns a meta patch handler for mutating CAPA workers.
func MetaWorkerPatchHandler(mgr manager.Manager) handlers.Named {
patchHandlers := []mutation.MetaMutator{
machinedetails.NewWorkerPatch(),
}
patchHandlers = append(patchHandlers, genericmutationv2.WorkerMetaMutators()...)

// The previous handler did not have "v2" in the name.
return mutation.NewMetaGeneratePatchesHandler(
"nutanixWorkerConfigPatch",
mgr.GetClient(),
patchHandlers...,
)
}
Loading