Skip to content

Commit f9a0519

Browse files
committed
Feature gate for old infra machine naming
There is a breaking change to the way infra machines are named in v1.7.0. This commit adds a feature gate for getting the old behavior back. It defaults to disabled so the new behavior stays. It is also marked as deprecated so it can be removed in a future minor release. Signed-off-by: Lennart Jern <[email protected]>
1 parent 112ec8c commit f9a0519

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ issues:
243243
- linters:
244244
- staticcheck
245245
text: "SA1019: (clusterv1alpha3.*|clusterv1alpha4.*) is deprecated: This type will be removed in one of the next releases."
246+
# Specific exclude rules for deprecated featuregates that are still part of the codebase. These
247+
# should be removed as the referenced deprecated types are removed from the project.
248+
- linters:
249+
- staticcheck
250+
text: "SA1019: (feature.InfraMachineNameFromTemplate) is deprecated: This type will be removed in one of the next releases."
246251
- linters:
247252
- revive
248253
text: "exported: exported method .*\\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported"

config/manager/manager.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ spec:
2323
- "--leader-elect"
2424
- "--diagnostics-address=${CAPI_DIAGNOSTICS_ADDRESS:=:8443}"
2525
- "--insecure-diagnostics=${CAPI_INSECURE_DIAGNOSTICS:=false}"
26-
- "--feature-gates=MachinePool=${EXP_MACHINE_POOL:=true},ClusterResourceSet=${EXP_CLUSTER_RESOURCE_SET:=true},ClusterTopology=${CLUSTER_TOPOLOGY:=false},RuntimeSDK=${EXP_RUNTIME_SDK:=false},MachineSetPreflightChecks=${EXP_MACHINE_SET_PREFLIGHT_CHECKS:=false}"
26+
- "--feature-gates=MachinePool=${EXP_MACHINE_POOL:=true},ClusterResourceSet=${EXP_CLUSTER_RESOURCE_SET:=true},ClusterTopology=${CLUSTER_TOPOLOGY:=false},RuntimeSDK=${EXP_RUNTIME_SDK:=false},MachineSetPreflightChecks=${EXP_MACHINE_SET_PREFLIGHT_CHECKS:=false},InfraMachineNameFromTemplate=${INFRA_MACHINE_NAME_FROM_TEMPLATE:=false}"
2727
image: controller:latest
2828
name: manager
2929
env:

controlplane/kubeadm/config/manager/manager.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ spec:
2222
- "--leader-elect"
2323
- "--diagnostics-address=${CAPI_DIAGNOSTICS_ADDRESS:=:8443}"
2424
- "--insecure-diagnostics=${CAPI_INSECURE_DIAGNOSTICS:=false}"
25-
- "--feature-gates=MachinePool=${EXP_MACHINE_POOL:=true},ClusterTopology=${CLUSTER_TOPOLOGY:=false},KubeadmBootstrapFormatIgnition=${EXP_KUBEADM_BOOTSTRAP_FORMAT_IGNITION:=false}"
25+
- "--feature-gates=MachinePool=${EXP_MACHINE_POOL:=true},ClusterTopology=${CLUSTER_TOPOLOGY:=false},KubeadmBootstrapFormatIgnition=${EXP_KUBEADM_BOOTSTRAP_FORMAT_IGNITION:=false},InfraMachineNameFromTemplate=${INFRA_MACHINE_NAME_FROM_TEMPLATE:=false}"
2626
image: controller:latest
2727
name: manager
2828
env:

controlplane/kubeadm/internal/controllers/helpers.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"sigs.k8s.io/cluster-api/controllers/external"
3838
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
3939
"sigs.k8s.io/cluster-api/controlplane/kubeadm/internal"
40+
"sigs.k8s.io/cluster-api/feature"
4041
"sigs.k8s.io/cluster-api/internal/util/ssa"
4142
"sigs.k8s.io/cluster-api/util"
4243
"sigs.k8s.io/cluster-api/util/certs"
@@ -180,12 +181,16 @@ func (r *KubeadmControlPlaneReconciler) cloneConfigsAndGenerateMachine(ctx conte
180181
UID: kcp.UID,
181182
}
182183

184+
infraMachineName := machine.Name
185+
if feature.Gates.Enabled(feature.InfraMachineNameFromTemplate) {
186+
infraMachineName = names.SimpleNameGenerator.GenerateName(kcp.Spec.MachineTemplate.InfrastructureRef.Name)
187+
}
183188
// Clone the infrastructure template
184189
infraRef, err := external.CreateFromTemplate(ctx, &external.CreateFromTemplateInput{
185190
Client: r.Client,
186191
TemplateRef: &kcp.Spec.MachineTemplate.InfrastructureRef,
187192
Namespace: kcp.Namespace,
188-
Name: machine.Name,
193+
Name: infraMachineName,
189194
OwnerRef: infraCloneOwner,
190195
ClusterName: cluster.Name,
191196
Labels: internal.ControlPlaneMachineLabelsForCluster(kcp, cluster.Name),

feature/feature.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ const (
6161
//
6262
// alpha: v1.5
6363
MachineSetPreflightChecks featuregate.Feature = "MachineSetPreflightChecks"
64+
65+
// InfraMachineNameFromTemplate is a feature gate for the now deprecated way of naming infra machines.
66+
// With this feature gate enabled, infra machines will be named based on the infra machine template.
67+
// The new behavior is that they get the same name as the machine.
68+
//
69+
// Deprecated: v1.7.
70+
InfraMachineNameFromTemplate featuregate.Feature = "InfraMachineNameFromTemplate"
6471
)
6572

6673
func init() {
@@ -77,4 +84,5 @@ var defaultClusterAPIFeatureGates = map[featuregate.Feature]featuregate.FeatureS
7784
KubeadmBootstrapFormatIgnition: {Default: false, PreRelease: featuregate.Alpha},
7885
RuntimeSDK: {Default: false, PreRelease: featuregate.Alpha},
7986
MachineSetPreflightChecks: {Default: false, PreRelease: featuregate.Alpha},
87+
InfraMachineNameFromTemplate: {Default: false, PreRelease: featuregate.Deprecated},
8088
}

internal/controllers/machineset/machineset_controller.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
"sigs.k8s.io/cluster-api/controllers/external"
4444
"sigs.k8s.io/cluster-api/controllers/noderefutil"
4545
"sigs.k8s.io/cluster-api/controllers/remote"
46+
"sigs.k8s.io/cluster-api/feature"
4647
"sigs.k8s.io/cluster-api/internal/contract"
4748
"sigs.k8s.io/cluster-api/internal/controllers/machine"
4849
"sigs.k8s.io/cluster-api/internal/util/ssa"
@@ -497,12 +498,16 @@ func (r *Reconciler) syncReplicas(ctx context.Context, cluster *clusterv1.Cluste
497498
log = log.WithValues(bootstrapRef.Kind, klog.KRef(bootstrapRef.Namespace, bootstrapRef.Name))
498499
}
499500

501+
infraMachineName := machine.Name
502+
if feature.Gates.Enabled(feature.InfraMachineNameFromTemplate) {
503+
infraMachineName = names.SimpleNameGenerator.GenerateName(ms.Spec.Template.Spec.InfrastructureRef.Name)
504+
}
500505
// Create the InfraMachine.
501506
infraRef, err = external.CreateFromTemplate(ctx, &external.CreateFromTemplateInput{
502507
Client: r.UnstructuredCachingClient,
503508
TemplateRef: &ms.Spec.Template.Spec.InfrastructureRef,
504509
Namespace: machine.Namespace,
505-
Name: machine.Name,
510+
Name: infraMachineName,
506511
ClusterName: machine.Spec.ClusterName,
507512
Labels: machine.Labels,
508513
Annotations: machine.Annotations,

0 commit comments

Comments
 (0)