Skip to content

Commit 0477fe7

Browse files
lentzi90k8s-infra-cherrypick-robot
authored andcommitted
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 d8585d7 commit 0477fe7

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
@@ -86,10 +86,11 @@ var (
8686
diagnosticsOptions = flags.DiagnosticsOptions{}
8787
logOptions = logs.NewOptions()
8888
// KCP specific flags.
89-
kubeadmControlPlaneConcurrency int
90-
clusterCacheTrackerConcurrency int
91-
etcdDialTimeout time.Duration
92-
etcdCallTimeout time.Duration
89+
kubeadmControlPlaneConcurrency int
90+
clusterCacheTrackerConcurrency int
91+
etcdDialTimeout time.Duration
92+
etcdCallTimeout time.Duration
93+
useDeprecatedInfraMachineNaming bool
9394
)
9495

9596
func init() {
@@ -167,6 +168,10 @@ func InitFlags(fs *pflag.FlagSet) {
167168
fs.DurationVar(&etcdCallTimeout, "etcd-call-timeout-duration", etcd.DefaultCallTimeout,
168169
"Duration that the etcd client waits at most for read and write operations to etcd.")
169170

171+
fs.BoolVar(&useDeprecatedInfraMachineNaming, "use-deprecated-infra-machine-naming", false,
172+
"Use the deprecated naming convention for infra machines where they are named after the InfraMachineTemplate.")
173+
_ = fs.MarkDeprecated("use-deprecated-infra-machine-naming", "This flag will be removed in v1.9.")
174+
170175
flags.AddDiagnosticsOptions(fs, &diagnosticsOptions)
171176
flags.AddTLSOptions(fs, &tlsOptions)
172177

@@ -342,12 +347,13 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
342347
}
343348

344349
if err := (&kubeadmcontrolplanecontrollers.KubeadmControlPlaneReconciler{
345-
Client: mgr.GetClient(),
346-
SecretCachingClient: secretCachingClient,
347-
Tracker: tracker,
348-
WatchFilterValue: watchFilterValue,
349-
EtcdDialTimeout: etcdDialTimeout,
350-
EtcdCallTimeout: etcdCallTimeout,
350+
Client: mgr.GetClient(),
351+
SecretCachingClient: secretCachingClient,
352+
Tracker: tracker,
353+
WatchFilterValue: watchFilterValue,
354+
EtcdDialTimeout: etcdDialTimeout,
355+
EtcdCallTimeout: etcdCallTimeout,
356+
DeprecatedInfraMachineNaming: useDeprecatedInfraMachineNaming,
351357
}).SetupWithManager(ctx, mgr, concurrency(kubeadmControlPlaneConcurrency)); err != nil {
352358
setupLog.Error(err, "unable to create controller", "controller", "KubeadmControlPlane")
353359
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
}
@@ -496,12 +499,16 @@ func (r *Reconciler) syncReplicas(ctx context.Context, cluster *clusterv1.Cluste
496499
log = log.WithValues(bootstrapRef.Kind, klog.KRef(bootstrapRef.Namespace, bootstrapRef.Name))
497500
}
498501

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

main.go

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

120121
func init() {
@@ -229,6 +230,10 @@ func InitFlags(fs *pflag.FlagSet) {
229230
fs.StringVar(&healthAddr, "health-addr", ":9440",
230231
"The address the health endpoint binds to.")
231232

233+
fs.BoolVar(&useDeprecatedInfraMachineNaming, "use-deprecated-infra-machine-naming", false,
234+
"Use deprecated infrastructure machine naming")
235+
_ = fs.MarkDeprecated("use-deprecated-infra-machine-naming", "This flag will be removed in v1.9.")
236+
232237
flags.AddDiagnosticsOptions(fs, &diagnosticsOptions)
233238
flags.AddTLSOptions(fs, &tlsOptions)
234239

@@ -516,11 +521,12 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) webhooks.ClusterCac
516521
os.Exit(1)
517522
}
518523
if err := (&controllers.MachineSetReconciler{
519-
Client: mgr.GetClient(),
520-
UnstructuredCachingClient: unstructuredCachingClient,
521-
APIReader: mgr.GetAPIReader(),
522-
Tracker: tracker,
523-
WatchFilterValue: watchFilterValue,
524+
Client: mgr.GetClient(),
525+
UnstructuredCachingClient: unstructuredCachingClient,
526+
APIReader: mgr.GetAPIReader(),
527+
Tracker: tracker,
528+
WatchFilterValue: watchFilterValue,
529+
DeprecatedInfraMachineNaming: useDeprecatedInfraMachineNaming,
524530
}).SetupWithManager(ctx, mgr, concurrency(machineSetConcurrency)); err != nil {
525531
setupLog.Error(err, "unable to create controller", "controller", "MachineSet")
526532
os.Exit(1)

0 commit comments

Comments
 (0)