Skip to content

Commit 43f13bc

Browse files
committed
Flag for old infra machine naming
There is a breaking change to the way InfraMachines are named in v1.7.0. This commit adds a flag to the KCP and core controller for getting the old behavior back. It defaults to disabled so the new behavior stays. It is also marked as deprecated and to be removed in v1.9. Signed-off-by: Lennart Jern <[email protected]>
1 parent 112ec8c commit 43f13bc

File tree

9 files changed

+76
-40
lines changed

9 files changed

+76
-40
lines changed

config/manager/manager.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ spec:
2323
- "--leader-elect"
2424
- "--diagnostics-address=${CAPI_DIAGNOSTICS_ADDRESS:=:8443}"
2525
- "--insecure-diagnostics=${CAPI_INSECURE_DIAGNOSTICS:=false}"
26+
- "--use-deprecated-infra-machine-naming=${CAPI_USE_DEPRECATED_INFRA_MACHINE_NAMING:=false}"
2627
- "--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}"
2728
image: controller:latest
2829
name: manager

controllers/alias.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,19 @@ type MachineSetReconciler struct {
9393

9494
// WatchFilterValue is the label value used to filter events prior to reconciliation.
9595
WatchFilterValue string
96+
97+
// Deprecated: DeprecatedInfraMachineNaming. Name the InfraStructureMachines after the InfraMachineTemplate.
98+
DeprecatedInfraMachineNaming bool
9699
}
97100

98101
func (r *MachineSetReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
99102
return (&machinesetcontroller.Reconciler{
100-
Client: r.Client,
101-
UnstructuredCachingClient: r.UnstructuredCachingClient,
102-
APIReader: r.APIReader,
103-
Tracker: r.Tracker,
104-
WatchFilterValue: r.WatchFilterValue,
103+
Client: r.Client,
104+
UnstructuredCachingClient: r.UnstructuredCachingClient,
105+
APIReader: r.APIReader,
106+
Tracker: r.Tracker,
107+
WatchFilterValue: r.WatchFilterValue,
108+
DeprecatedInfraMachineNaming: r.DeprecatedInfraMachineNaming,
105109
}).SetupWithManager(ctx, mgr, options)
106110
}
107111

controlplane/kubeadm/config/manager/manager.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ spec:
2222
- "--leader-elect"
2323
- "--diagnostics-address=${CAPI_DIAGNOSTICS_ADDRESS:=:8443}"
2424
- "--insecure-diagnostics=${CAPI_INSECURE_DIAGNOSTICS:=false}"
25+
- "--use-deprecated-infra-machine-naming=${CAPI_USE_DEPRECATED_INFRA_MACHINE_NAMING:=false}"
2526
- "--feature-gates=MachinePool=${EXP_MACHINE_POOL:=true},ClusterTopology=${CLUSTER_TOPOLOGY:=false},KubeadmBootstrapFormatIgnition=${EXP_KUBEADM_BOOTSTRAP_FORMAT_IGNITION:=false}"
2627
image: controller:latest
2728
name: manager

controlplane/kubeadm/controllers/alias.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,20 @@ type KubeadmControlPlaneReconciler struct {
3939

4040
// WatchFilterValue is the label value used to filter events prior to reconciliation.
4141
WatchFilterValue string
42+
43+
// Deprecated: DeprecatedInfraMachineNaming. Name the InfraStructureMachines after the InfraMachineTemplate.
44+
DeprecatedInfraMachineNaming bool
4245
}
4346

4447
// SetupWithManager sets up the reconciler with the Manager.
4548
func (r *KubeadmControlPlaneReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
4649
return (&kubeadmcontrolplanecontrollers.KubeadmControlPlaneReconciler{
47-
Client: r.Client,
48-
SecretCachingClient: r.SecretCachingClient,
49-
Tracker: r.Tracker,
50-
EtcdDialTimeout: r.EtcdDialTimeout,
51-
EtcdCallTimeout: r.EtcdCallTimeout,
52-
WatchFilterValue: r.WatchFilterValue,
50+
Client: r.Client,
51+
SecretCachingClient: r.SecretCachingClient,
52+
Tracker: r.Tracker,
53+
EtcdDialTimeout: r.EtcdDialTimeout,
54+
EtcdCallTimeout: r.EtcdCallTimeout,
55+
WatchFilterValue: r.WatchFilterValue,
56+
DeprecatedInfraMachineNaming: r.DeprecatedInfraMachineNaming,
5357
}).SetupWithManager(ctx, mgr, options)
5458
}

controlplane/kubeadm/internal/controllers/controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ type KubeadmControlPlaneReconciler struct {
8484
// WatchFilterValue is the label value used to filter events prior to reconciliation.
8585
WatchFilterValue string
8686

87+
// Deprecated: DeprecatedInfraMachineNaming. Name the InfraStructureMachines after the InfraMachineTemplate.
88+
DeprecatedInfraMachineNaming bool
89+
8790
managementCluster internal.ManagementCluster
8891
managementClusterUncached internal.ManagementCluster
8992
ssaCache ssa.Cache

controlplane/kubeadm/internal/controllers/helpers.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,16 @@ func (r *KubeadmControlPlaneReconciler) cloneConfigsAndGenerateMachine(ctx conte
180180
UID: kcp.UID,
181181
}
182182

183+
infraMachineName := machine.Name
184+
if r.DeprecatedInfraMachineNaming {
185+
infraMachineName = names.SimpleNameGenerator.GenerateName(kcp.Spec.MachineTemplate.InfrastructureRef.Name + "-")
186+
}
183187
// Clone the infrastructure template
184188
infraRef, err := external.CreateFromTemplate(ctx, &external.CreateFromTemplateInput{
185189
Client: r.Client,
186190
TemplateRef: &kcp.Spec.MachineTemplate.InfrastructureRef,
187191
Namespace: kcp.Namespace,
188-
Name: machine.Name,
192+
Name: infraMachineName,
189193
OwnerRef: infraCloneOwner,
190194
ClusterName: cluster.Name,
191195
Labels: internal.ControlPlaneMachineLabelsForCluster(kcp, cluster.Name),

controlplane/kubeadm/main.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ var (
8484
diagnosticsOptions = flags.DiagnosticsOptions{}
8585
logOptions = logs.NewOptions()
8686
// KCP specific flags.
87-
kubeadmControlPlaneConcurrency int
88-
clusterCacheTrackerConcurrency int
89-
etcdDialTimeout time.Duration
90-
etcdCallTimeout time.Duration
87+
kubeadmControlPlaneConcurrency int
88+
clusterCacheTrackerConcurrency int
89+
etcdDialTimeout time.Duration
90+
etcdCallTimeout time.Duration
91+
useDeprecatedInfraMachineNaming bool
9192
)
9293

9394
func init() {
@@ -159,6 +160,10 @@ func InitFlags(fs *pflag.FlagSet) {
159160
fs.DurationVar(&etcdCallTimeout, "etcd-call-timeout-duration", etcd.DefaultCallTimeout,
160161
"Duration that the etcd client waits at most for read and write operations to etcd.")
161162

163+
fs.BoolVar(&useDeprecatedInfraMachineNaming, "use-deprecated-infra-machine-naming", false,
164+
"Use the deprecated naming convention for infra machines where they are named after the InfraMachineTemplate.")
165+
_ = fs.MarkDeprecated("use-deprecated-infra-machine-naming", "This flag will be removed in v1.9.")
166+
162167
flags.AddDiagnosticsOptions(fs, &diagnosticsOptions)
163168
flags.AddTLSOptions(fs, &tlsOptions)
164169

@@ -332,12 +337,13 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
332337
}
333338

334339
if err := (&kubeadmcontrolplanecontrollers.KubeadmControlPlaneReconciler{
335-
Client: mgr.GetClient(),
336-
SecretCachingClient: secretCachingClient,
337-
Tracker: tracker,
338-
WatchFilterValue: watchFilterValue,
339-
EtcdDialTimeout: etcdDialTimeout,
340-
EtcdCallTimeout: etcdCallTimeout,
340+
Client: mgr.GetClient(),
341+
SecretCachingClient: secretCachingClient,
342+
Tracker: tracker,
343+
WatchFilterValue: watchFilterValue,
344+
EtcdDialTimeout: etcdDialTimeout,
345+
EtcdCallTimeout: etcdCallTimeout,
346+
DeprecatedInfraMachineNaming: useDeprecatedInfraMachineNaming,
341347
}).SetupWithManager(ctx, mgr, concurrency(kubeadmControlPlaneConcurrency)); err != nil {
342348
setupLog.Error(err, "unable to create controller", "controller", "KubeadmControlPlane")
343349
os.Exit(1)

internal/controllers/machineset/machineset_controller.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ type Reconciler struct {
8787
// WatchFilterValue is the label value used to filter events prior to reconciliation.
8888
WatchFilterValue string
8989

90+
// Deprecated: DeprecatedInfraMachineNaming. Name the InfraStructureMachines after the InfraMachineTemplate.
91+
DeprecatedInfraMachineNaming bool
92+
9093
ssaCache ssa.Cache
9194
recorder record.EventRecorder
9295
}
@@ -497,12 +500,16 @@ func (r *Reconciler) syncReplicas(ctx context.Context, cluster *clusterv1.Cluste
497500
log = log.WithValues(bootstrapRef.Kind, klog.KRef(bootstrapRef.Namespace, bootstrapRef.Name))
498501
}
499502

503+
infraMachineName := machine.Name
504+
if r.DeprecatedInfraMachineNaming {
505+
infraMachineName = names.SimpleNameGenerator.GenerateName(ms.Spec.Template.Spec.InfrastructureRef.Name + "-")
506+
}
500507
// Create the InfraMachine.
501508
infraRef, err = external.CreateFromTemplate(ctx, &external.CreateFromTemplateInput{
502509
Client: r.UnstructuredCachingClient,
503510
TemplateRef: &ms.Spec.Template.Spec.InfrastructureRef,
504511
Namespace: machine.Namespace,
505-
Name: machine.Name,
512+
Name: infraMachineName,
506513
ClusterName: machine.Spec.ClusterName,
507514
Labels: machine.Labels,
508515
Annotations: machine.Annotations,

main.go

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,19 @@ var (
101101
diagnosticsOptions = flags.DiagnosticsOptions{}
102102
logOptions = logs.NewOptions()
103103
// core Cluster API specific flags.
104-
clusterTopologyConcurrency int
105-
clusterCacheTrackerConcurrency int
106-
clusterClassConcurrency int
107-
clusterConcurrency int
108-
extensionConfigConcurrency int
109-
machineConcurrency int
110-
machineSetConcurrency int
111-
machineDeploymentConcurrency int
112-
machinePoolConcurrency int
113-
clusterResourceSetConcurrency int
114-
machineHealthCheckConcurrency int
115-
nodeDrainClientTimeout time.Duration
104+
clusterTopologyConcurrency int
105+
clusterCacheTrackerConcurrency int
106+
clusterClassConcurrency int
107+
clusterConcurrency int
108+
extensionConfigConcurrency int
109+
machineConcurrency int
110+
machineSetConcurrency int
111+
machineDeploymentConcurrency int
112+
machinePoolConcurrency int
113+
clusterResourceSetConcurrency int
114+
machineHealthCheckConcurrency int
115+
nodeDrainClientTimeout time.Duration
116+
useDeprecatedInfraMachineNaming bool
116117
)
117118

118119
func init() {
@@ -221,6 +222,10 @@ func InitFlags(fs *pflag.FlagSet) {
221222
fs.StringVar(&healthAddr, "health-addr", ":9440",
222223
"The address the health endpoint binds to.")
223224

225+
fs.BoolVar(&useDeprecatedInfraMachineNaming, "use-deprecated-infra-machine-naming", false,
226+
"Use deprecated infrastructure machine naming")
227+
_ = fs.MarkDeprecated("use-deprecated-infra-machine-naming", "This flag will be removed in v1.9.")
228+
224229
flags.AddDiagnosticsOptions(fs, &diagnosticsOptions)
225230
flags.AddTLSOptions(fs, &tlsOptions)
226231

@@ -506,11 +511,12 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) webhooks.ClusterCac
506511
os.Exit(1)
507512
}
508513
if err := (&controllers.MachineSetReconciler{
509-
Client: mgr.GetClient(),
510-
UnstructuredCachingClient: unstructuredCachingClient,
511-
APIReader: mgr.GetAPIReader(),
512-
Tracker: tracker,
513-
WatchFilterValue: watchFilterValue,
514+
Client: mgr.GetClient(),
515+
UnstructuredCachingClient: unstructuredCachingClient,
516+
APIReader: mgr.GetAPIReader(),
517+
Tracker: tracker,
518+
WatchFilterValue: watchFilterValue,
519+
DeprecatedInfraMachineNaming: useDeprecatedInfraMachineNaming,
514520
}).SetupWithManager(ctx, mgr, concurrency(machineSetConcurrency)); err != nil {
515521
setupLog.Error(err, "unable to create controller", "controller", "MachineSet")
516522
os.Exit(1)

0 commit comments

Comments
 (0)