Skip to content

Commit

Permalink
Merge pull request #10587 from k8s-infra-cherrypick-robot/cherry-pick…
Browse files Browse the repository at this point in the history
…-10576-to-release-1.7

[release-1.7] 🌱 Flag for old infra machine naming
  • Loading branch information
k8s-ci-robot committed May 10, 2024
2 parents d8585d7 + 0477fe7 commit e226702
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 40 deletions.
1 change: 1 addition & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions controllers/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
1 change: 1 addition & 0 deletions controlplane/kubeadm/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions controlplane/kubeadm/controllers/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 3 additions & 0 deletions controlplane/kubeadm/internal/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion controlplane/kubeadm/internal/controllers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
26 changes: 16 additions & 10 deletions controlplane/kubeadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion internal/controllers/machineset/machineset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
40 changes: 23 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e226702

Please sign in to comment.