diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 31868aed12a2..27047f97286d 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -23,6 +23,7 @@ spec: - "--leader-elect" - "--diagnostics-address=${CAPI_DIAGNOSTICS_ADDRESS:=:8443}" - "--insecure-diagnostics=${CAPI_INSECURE_DIAGNOSTICS:=false}" + - "--use-deprecated-infra-machine-naming=${CAPI_USE_DEPRECATED_INFRA_MACHINE_NAMING:=false}" - "--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}" image: controller:latest name: manager diff --git a/controllers/alias.go b/controllers/alias.go index 1bc4c7d90322..fba47941cb7e 100644 --- a/controllers/alias.go +++ b/controllers/alias.go @@ -93,15 +93,19 @@ type MachineSetReconciler struct { // WatchFilterValue is the label value used to filter events prior to reconciliation. WatchFilterValue string + + // Deprecated: DeprecatedInfraMachineNaming. Name the InfraStructureMachines after the InfraMachineTemplate. + DeprecatedInfraMachineNaming bool } func (r *MachineSetReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error { return (&machinesetcontroller.Reconciler{ - Client: r.Client, - UnstructuredCachingClient: r.UnstructuredCachingClient, - APIReader: r.APIReader, - Tracker: r.Tracker, - WatchFilterValue: r.WatchFilterValue, + Client: r.Client, + UnstructuredCachingClient: r.UnstructuredCachingClient, + APIReader: r.APIReader, + Tracker: r.Tracker, + WatchFilterValue: r.WatchFilterValue, + DeprecatedInfraMachineNaming: r.DeprecatedInfraMachineNaming, }).SetupWithManager(ctx, mgr, options) } diff --git a/controlplane/kubeadm/config/manager/manager.yaml b/controlplane/kubeadm/config/manager/manager.yaml index 314d8c395742..c8c18dcaecee 100644 --- a/controlplane/kubeadm/config/manager/manager.yaml +++ b/controlplane/kubeadm/config/manager/manager.yaml @@ -22,6 +22,7 @@ spec: - "--leader-elect" - "--diagnostics-address=${CAPI_DIAGNOSTICS_ADDRESS:=:8443}" - "--insecure-diagnostics=${CAPI_INSECURE_DIAGNOSTICS:=false}" + - "--use-deprecated-infra-machine-naming=${CAPI_USE_DEPRECATED_INFRA_MACHINE_NAMING:=false}" - "--feature-gates=MachinePool=${EXP_MACHINE_POOL:=true},ClusterTopology=${CLUSTER_TOPOLOGY:=false},KubeadmBootstrapFormatIgnition=${EXP_KUBEADM_BOOTSTRAP_FORMAT_IGNITION:=false}" image: controller:latest name: manager diff --git a/controlplane/kubeadm/controllers/alias.go b/controlplane/kubeadm/controllers/alias.go index 7b03abff618a..270f5222ba61 100644 --- a/controlplane/kubeadm/controllers/alias.go +++ b/controlplane/kubeadm/controllers/alias.go @@ -39,16 +39,20 @@ type KubeadmControlPlaneReconciler struct { // WatchFilterValue is the label value used to filter events prior to reconciliation. WatchFilterValue string + + // Deprecated: DeprecatedInfraMachineNaming. Name the InfraStructureMachines after the InfraMachineTemplate. + DeprecatedInfraMachineNaming bool } // SetupWithManager sets up the reconciler with the Manager. func (r *KubeadmControlPlaneReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error { return (&kubeadmcontrolplanecontrollers.KubeadmControlPlaneReconciler{ - Client: r.Client, - SecretCachingClient: r.SecretCachingClient, - Tracker: r.Tracker, - EtcdDialTimeout: r.EtcdDialTimeout, - EtcdCallTimeout: r.EtcdCallTimeout, - WatchFilterValue: r.WatchFilterValue, + Client: r.Client, + SecretCachingClient: r.SecretCachingClient, + Tracker: r.Tracker, + EtcdDialTimeout: r.EtcdDialTimeout, + EtcdCallTimeout: r.EtcdCallTimeout, + WatchFilterValue: r.WatchFilterValue, + DeprecatedInfraMachineNaming: r.DeprecatedInfraMachineNaming, }).SetupWithManager(ctx, mgr, options) } diff --git a/controlplane/kubeadm/internal/controllers/controller.go b/controlplane/kubeadm/internal/controllers/controller.go index 22ba4f0ae2a1..ae6f8325e318 100644 --- a/controlplane/kubeadm/internal/controllers/controller.go +++ b/controlplane/kubeadm/internal/controllers/controller.go @@ -84,6 +84,9 @@ type KubeadmControlPlaneReconciler struct { // WatchFilterValue is the label value used to filter events prior to reconciliation. WatchFilterValue string + // Deprecated: DeprecatedInfraMachineNaming. Name the InfraStructureMachines after the InfraMachineTemplate. + DeprecatedInfraMachineNaming bool + managementCluster internal.ManagementCluster managementClusterUncached internal.ManagementCluster ssaCache ssa.Cache diff --git a/controlplane/kubeadm/internal/controllers/helpers.go b/controlplane/kubeadm/internal/controllers/helpers.go index 4d74c70be1c1..45def5207fbd 100644 --- a/controlplane/kubeadm/internal/controllers/helpers.go +++ b/controlplane/kubeadm/internal/controllers/helpers.go @@ -180,12 +180,16 @@ func (r *KubeadmControlPlaneReconciler) cloneConfigsAndGenerateMachine(ctx conte UID: kcp.UID, } + infraMachineName := machine.Name + if r.DeprecatedInfraMachineNaming { + infraMachineName = names.SimpleNameGenerator.GenerateName(kcp.Spec.MachineTemplate.InfrastructureRef.Name + "-") + } // Clone the infrastructure template infraRef, err := external.CreateFromTemplate(ctx, &external.CreateFromTemplateInput{ Client: r.Client, TemplateRef: &kcp.Spec.MachineTemplate.InfrastructureRef, Namespace: kcp.Namespace, - Name: machine.Name, + Name: infraMachineName, OwnerRef: infraCloneOwner, ClusterName: cluster.Name, Labels: internal.ControlPlaneMachineLabelsForCluster(kcp, cluster.Name), diff --git a/controlplane/kubeadm/main.go b/controlplane/kubeadm/main.go index 53ccad2e95f9..71215f9df0ef 100644 --- a/controlplane/kubeadm/main.go +++ b/controlplane/kubeadm/main.go @@ -86,10 +86,11 @@ var ( diagnosticsOptions = flags.DiagnosticsOptions{} logOptions = logs.NewOptions() // KCP specific flags. - kubeadmControlPlaneConcurrency int - clusterCacheTrackerConcurrency int - etcdDialTimeout time.Duration - etcdCallTimeout time.Duration + kubeadmControlPlaneConcurrency int + clusterCacheTrackerConcurrency int + etcdDialTimeout time.Duration + etcdCallTimeout time.Duration + useDeprecatedInfraMachineNaming bool ) func init() { @@ -167,6 +168,10 @@ func InitFlags(fs *pflag.FlagSet) { fs.DurationVar(&etcdCallTimeout, "etcd-call-timeout-duration", etcd.DefaultCallTimeout, "Duration that the etcd client waits at most for read and write operations to etcd.") + fs.BoolVar(&useDeprecatedInfraMachineNaming, "use-deprecated-infra-machine-naming", false, + "Use the deprecated naming convention for infra machines where they are named after the InfraMachineTemplate.") + _ = fs.MarkDeprecated("use-deprecated-infra-machine-naming", "This flag will be removed in v1.9.") + flags.AddDiagnosticsOptions(fs, &diagnosticsOptions) flags.AddTLSOptions(fs, &tlsOptions) @@ -342,12 +347,13 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) { } if err := (&kubeadmcontrolplanecontrollers.KubeadmControlPlaneReconciler{ - Client: mgr.GetClient(), - SecretCachingClient: secretCachingClient, - Tracker: tracker, - WatchFilterValue: watchFilterValue, - EtcdDialTimeout: etcdDialTimeout, - EtcdCallTimeout: etcdCallTimeout, + Client: mgr.GetClient(), + SecretCachingClient: secretCachingClient, + Tracker: tracker, + WatchFilterValue: watchFilterValue, + EtcdDialTimeout: etcdDialTimeout, + EtcdCallTimeout: etcdCallTimeout, + DeprecatedInfraMachineNaming: useDeprecatedInfraMachineNaming, }).SetupWithManager(ctx, mgr, concurrency(kubeadmControlPlaneConcurrency)); err != nil { setupLog.Error(err, "unable to create controller", "controller", "KubeadmControlPlane") os.Exit(1) diff --git a/internal/controllers/machineset/machineset_controller.go b/internal/controllers/machineset/machineset_controller.go index 58682dba2c7c..cd231a5ab4d9 100644 --- a/internal/controllers/machineset/machineset_controller.go +++ b/internal/controllers/machineset/machineset_controller.go @@ -87,6 +87,9 @@ type Reconciler struct { // WatchFilterValue is the label value used to filter events prior to reconciliation. WatchFilterValue string + // Deprecated: DeprecatedInfraMachineNaming. Name the InfraStructureMachines after the InfraMachineTemplate. + DeprecatedInfraMachineNaming bool + ssaCache ssa.Cache recorder record.EventRecorder } @@ -496,12 +499,16 @@ func (r *Reconciler) syncReplicas(ctx context.Context, cluster *clusterv1.Cluste log = log.WithValues(bootstrapRef.Kind, klog.KRef(bootstrapRef.Namespace, bootstrapRef.Name)) } + infraMachineName := machine.Name + if r.DeprecatedInfraMachineNaming { + infraMachineName = names.SimpleNameGenerator.GenerateName(ms.Spec.Template.Spec.InfrastructureRef.Name + "-") + } // Create the InfraMachine. infraRef, err = external.CreateFromTemplate(ctx, &external.CreateFromTemplateInput{ Client: r.UnstructuredCachingClient, TemplateRef: &ms.Spec.Template.Spec.InfrastructureRef, Namespace: machine.Namespace, - Name: machine.Name, + Name: infraMachineName, ClusterName: machine.Spec.ClusterName, Labels: machine.Labels, Annotations: machine.Annotations, diff --git a/main.go b/main.go index 177c7839448f..b79e367d3cf8 100644 --- a/main.go +++ b/main.go @@ -103,18 +103,19 @@ var ( diagnosticsOptions = flags.DiagnosticsOptions{} logOptions = logs.NewOptions() // core Cluster API specific flags. - clusterTopologyConcurrency int - clusterCacheTrackerConcurrency int - clusterClassConcurrency int - clusterConcurrency int - extensionConfigConcurrency int - machineConcurrency int - machineSetConcurrency int - machineDeploymentConcurrency int - machinePoolConcurrency int - clusterResourceSetConcurrency int - machineHealthCheckConcurrency int - nodeDrainClientTimeout time.Duration + clusterTopologyConcurrency int + clusterCacheTrackerConcurrency int + clusterClassConcurrency int + clusterConcurrency int + extensionConfigConcurrency int + machineConcurrency int + machineSetConcurrency int + machineDeploymentConcurrency int + machinePoolConcurrency int + clusterResourceSetConcurrency int + machineHealthCheckConcurrency int + nodeDrainClientTimeout time.Duration + useDeprecatedInfraMachineNaming bool ) func init() { @@ -229,6 +230,10 @@ func InitFlags(fs *pflag.FlagSet) { fs.StringVar(&healthAddr, "health-addr", ":9440", "The address the health endpoint binds to.") + fs.BoolVar(&useDeprecatedInfraMachineNaming, "use-deprecated-infra-machine-naming", false, + "Use deprecated infrastructure machine naming") + _ = fs.MarkDeprecated("use-deprecated-infra-machine-naming", "This flag will be removed in v1.9.") + flags.AddDiagnosticsOptions(fs, &diagnosticsOptions) flags.AddTLSOptions(fs, &tlsOptions) @@ -516,11 +521,12 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) webhooks.ClusterCac os.Exit(1) } if err := (&controllers.MachineSetReconciler{ - Client: mgr.GetClient(), - UnstructuredCachingClient: unstructuredCachingClient, - APIReader: mgr.GetAPIReader(), - Tracker: tracker, - WatchFilterValue: watchFilterValue, + Client: mgr.GetClient(), + UnstructuredCachingClient: unstructuredCachingClient, + APIReader: mgr.GetAPIReader(), + Tracker: tracker, + WatchFilterValue: watchFilterValue, + DeprecatedInfraMachineNaming: useDeprecatedInfraMachineNaming, }).SetupWithManager(ctx, mgr, concurrency(machineSetConcurrency)); err != nil { setupLog.Error(err, "unable to create controller", "controller", "MachineSet") os.Exit(1)