Skip to content

Commit 4f6b121

Browse files
Address comments
1 parent b3b3f41 commit 4f6b121

File tree

29 files changed

+356
-82
lines changed

29 files changed

+356
-82
lines changed

api/bootstrap/kubeadm/v1beta1/conversion.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func RestoreKubeadmConfigSpec(restored *bootstrapv1.KubeadmConfigSpec, dst *boot
6767

6868
func (src *KubeadmConfigSpec) ConvertTo(dst *bootstrapv1.KubeadmConfigSpec) {
6969
// Override with timeouts values already existing in v1beta1.
70+
var initControlPlaneComponentHealthCheckSeconds *int32
7071
if src.ClusterConfiguration != nil && src.ClusterConfiguration.APIServer.TimeoutForControlPlane != nil {
7172
if dst.InitConfiguration == nil {
7273
dst.InitConfiguration = &bootstrapv1.InitConfiguration{}
@@ -75,15 +76,19 @@ func (src *KubeadmConfigSpec) ConvertTo(dst *bootstrapv1.KubeadmConfigSpec) {
7576
dst.InitConfiguration.Timeouts = &bootstrapv1.Timeouts{}
7677
}
7778
dst.InitConfiguration.Timeouts.ControlPlaneComponentHealthCheckSeconds = utilconversion.ConvertToSeconds(src.ClusterConfiguration.APIServer.TimeoutForControlPlane)
79+
initControlPlaneComponentHealthCheckSeconds = dst.InitConfiguration.Timeouts.ControlPlaneComponentHealthCheckSeconds
7880
}
79-
if src.JoinConfiguration != nil && src.JoinConfiguration.Discovery.Timeout != nil {
81+
if (src.JoinConfiguration != nil && src.JoinConfiguration.Discovery.Timeout != nil) || initControlPlaneComponentHealthCheckSeconds != nil {
8082
if dst.JoinConfiguration == nil {
8183
dst.JoinConfiguration = &bootstrapv1.JoinConfiguration{}
8284
}
8385
if dst.JoinConfiguration.Timeouts == nil {
8486
dst.JoinConfiguration.Timeouts = &bootstrapv1.Timeouts{}
8587
}
86-
dst.JoinConfiguration.Timeouts.TLSBootstrapSeconds = utilconversion.ConvertToSeconds(src.JoinConfiguration.Discovery.Timeout)
88+
dst.JoinConfiguration.Timeouts.ControlPlaneComponentHealthCheckSeconds = initControlPlaneComponentHealthCheckSeconds
89+
if src.JoinConfiguration != nil && src.JoinConfiguration.Discovery.Timeout != nil {
90+
dst.JoinConfiguration.Timeouts.TLSBootstrapSeconds = utilconversion.ConvertToSeconds(src.JoinConfiguration.Discovery.Timeout)
91+
}
8792
}
8893

8994
if reflect.DeepEqual(dst.ClusterConfiguration, &bootstrapv1.ClusterConfiguration{}) {

api/bootstrap/kubeadm/v1beta1/conversion_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func KubeadmConfigFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
6262
spokeKubeadmConfigStatus,
6363
hubBootstrapTokenString,
6464
spokeBootstrapTokenString,
65+
hubKubeadmConfigSpec,
6566
}
6667
}
6768

@@ -70,8 +71,9 @@ func KubeadmConfigTemplateFuzzFuncs(_ runtimeserializer.CodecFactory) []interfac
7071
spokeAPIServer,
7172
spokeDiscovery,
7273
spokeKubeadmConfigSpec,
73-
hubBootstrapTokenString,
7474
spokeBootstrapTokenString,
75+
hubBootstrapTokenString,
76+
hubKubeadmConfigSpec,
7577
}
7678
}
7779

@@ -103,6 +105,25 @@ func hubKubeadmConfigStatus(in *bootstrapv1.KubeadmConfigStatus, c randfill.Cont
103105
}
104106
}
105107

108+
func hubKubeadmConfigSpec(in *bootstrapv1.KubeadmConfigSpec, c randfill.Continue) {
109+
c.FillNoCustom(in)
110+
111+
// enforce ControlPlaneComponentHealthCheckSeconds to be equal on init and join configuration
112+
var initControlPlaneComponentHealthCheckSeconds *int32
113+
if in.InitConfiguration != nil && in.InitConfiguration.Timeouts != nil {
114+
initControlPlaneComponentHealthCheckSeconds = in.InitConfiguration.Timeouts.ControlPlaneComponentHealthCheckSeconds
115+
}
116+
if (in.JoinConfiguration != nil && in.JoinConfiguration.Timeouts != nil) || initControlPlaneComponentHealthCheckSeconds != nil {
117+
if in.JoinConfiguration == nil {
118+
in.JoinConfiguration = &bootstrapv1.JoinConfiguration{}
119+
}
120+
if in.JoinConfiguration.Timeouts == nil {
121+
in.JoinConfiguration.Timeouts = &bootstrapv1.Timeouts{}
122+
}
123+
in.JoinConfiguration.Timeouts.ControlPlaneComponentHealthCheckSeconds = initControlPlaneComponentHealthCheckSeconds
124+
}
125+
}
126+
106127
func spokeKubeadmConfigSpec(in *KubeadmConfigSpec, c randfill.Continue) {
107128
c.FillNoCustom(in)
108129

api/bootstrap/kubeadm/v1beta2/kubeadm_types.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ type ClusterConfiguration struct {
212212
// ControlPlaneComponent holds settings common to control plane component of the cluster.
213213
type ControlPlaneComponent struct {
214214
// extraArgs is a list of args to pass to the control plane component.
215-
// The arg name must match be the command line flag name except without leading dash(es).
215+
// The arg name must match the command line flag name except without leading dash(es).
216216
// Extra arguments will override existing default arguments set by kubeadm.
217217
// +optional
218218
// +listType=map
@@ -330,7 +330,7 @@ type NodeRegistrationOptions struct {
330330
Taints []corev1.Taint `json:"taints,omitempty"`
331331

332332
// kubeletExtraArgs is a list of args to pass to kubelet.
333-
// The arg name must match be the command line flag name except without leading dash(es).
333+
// The arg name must match the command line flag name except without leading dash(es).
334334
// Extra arguments will override existing default arguments set by kubeadm.
335335
// +optional
336336
// +listType=map
@@ -502,13 +502,15 @@ type LocalEtcd struct {
502502
DataDir string `json:"dataDir,omitempty"`
503503

504504
// extraArgs is a list of args to pass to etcd.
505-
// The arg name must match be the command line flag name except without leading dash(es).
505+
// The arg name must match the command line flag name except without leading dash(es).
506506
// Extra arguments will override existing default arguments set by kubeadm.
507507
// +optional
508-
// +listType=atomic
508+
// +listType=map
509+
// +listMapKey=name
510+
// +listMapKey=value
509511
// +kubebuilder:validation:MinItems=1
510512
// +kubebuilder:validation:MaxItems=100
511-
// +kubebuilder:validation:XValidation:rule="self.all(x, self.exists_one(y, x == y))",message="extraArgs name must be unique"
513+
// +kubebuilder:validation:XValidation:rule="self.all(x, self.exists_one(y, x.name == y.name))",message="extraArgs name must be unique"
512514
ExtraArgs []Arg `json:"extraArgs,omitempty"`
513515

514516
// extraEnvs is an extra set of environment variables to pass to etcd.

api/bootstrap/kubeadm/v1beta2/kubeadmconfig_types.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,31 @@ func (c *KubeadmConfigSpec) Validate(pathPrefix *field.Path) field.ErrorList {
184184
}
185185
}
186186

187+
// Validate timeouts
188+
// Note: When v1beta1 will be removed, we can drop this limitation.
189+
tInit := "unset"
190+
if c.InitConfiguration != nil && c.InitConfiguration.Timeouts != nil && c.InitConfiguration.Timeouts.ControlPlaneComponentHealthCheckSeconds != nil {
191+
tInit = fmt.Sprintf("%d", *c.InitConfiguration.Timeouts.ControlPlaneComponentHealthCheckSeconds)
192+
}
193+
tJoin := "unset"
194+
if c.JoinConfiguration != nil && c.JoinConfiguration.Timeouts != nil && c.JoinConfiguration.Timeouts.ControlPlaneComponentHealthCheckSeconds != nil {
195+
tJoin = fmt.Sprintf("%d", *c.JoinConfiguration.Timeouts.ControlPlaneComponentHealthCheckSeconds)
196+
}
197+
if tInit != tJoin {
198+
allErrs = append(allErrs,
199+
field.Invalid(
200+
pathPrefix.Child("initConfiguration", "timeouts", "controlPlaneComponentHealthCheckSeconds"),
201+
tInit,
202+
fmt.Sprintf("controlPlaneComponentHealthCheckSeconds must be set to the same value both in initConfiguration.timeouts (%s) and in joinConfiguration.timeouts (%s)", tInit, tJoin),
203+
),
204+
field.Invalid(
205+
pathPrefix.Child("joinConfiguration", "timeouts", "controlPlaneComponentHealthCheckSeconds"),
206+
tJoin,
207+
fmt.Sprintf("controlPlaneComponentHealthCheckSeconds must be set to the same value both in initConfiguration.timeouts (%s) and in joinConfiguration.timeouts (%s)", tInit, tJoin),
208+
),
209+
)
210+
}
211+
187212
return allErrs
188213
}
189214

api/controlplane/kubeadm/v1beta1/conversion_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func KubeadmControlPlaneFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{
6464
spokeBootstrapTokenString,
6565
spokeAPIServer,
6666
spokeDiscovery,
67+
hubKubeadmConfigSpec,
6768
}
6869
}
6970

@@ -74,6 +75,26 @@ func KubeadmControlPlaneTemplateFuzzFuncs(_ runtimeserializer.CodecFactory) []in
7475
spokeBootstrapTokenString,
7576
spokeAPIServer,
7677
spokeDiscovery,
78+
hubKubeadmConfigSpec,
79+
}
80+
}
81+
82+
func hubKubeadmConfigSpec(in *bootstrapv1.KubeadmConfigSpec, c randfill.Continue) {
83+
c.FillNoCustom(in)
84+
85+
// enforce ControlPlaneComponentHealthCheckSeconds to be equal on init and join configuration
86+
var initControlPlaneComponentHealthCheckSeconds *int32
87+
if in.InitConfiguration != nil && in.InitConfiguration.Timeouts != nil {
88+
initControlPlaneComponentHealthCheckSeconds = in.InitConfiguration.Timeouts.ControlPlaneComponentHealthCheckSeconds
89+
}
90+
if (in.JoinConfiguration != nil && in.JoinConfiguration.Timeouts != nil) || initControlPlaneComponentHealthCheckSeconds != nil {
91+
if in.JoinConfiguration == nil {
92+
in.JoinConfiguration = &bootstrapv1.JoinConfiguration{}
93+
}
94+
if in.JoinConfiguration.Timeouts == nil {
95+
in.JoinConfiguration.Timeouts = &bootstrapv1.Timeouts{}
96+
}
97+
in.JoinConfiguration.Timeouts.ControlPlaneComponentHealthCheckSeconds = initControlPlaneComponentHealthCheckSeconds
7798
}
7899
}
79100

bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml

Lines changed: 11 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml

Lines changed: 12 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,6 @@ func (r *KubeadmConfigReconciler) handleClusterNotInitialized(ctx context.Contex
564564
return ctrl.Result{}, err
565565
}
566566

567-
// NOTE: It is required to provide in input the ClusterConfiguration because clusterConfiguration.APIServer.TimeoutForControlPlane
568-
// has been migrated to InitConfiguration in the kubeadm v1beta4 API version.
569567
initdata, err := kubeadmtypes.MarshalInitConfigurationForVersion(scope.Config.Spec.InitConfiguration, parsedVersion)
570568
if err != nil {
571569
scope.Error(err, "Failed to marshal init configuration")
@@ -894,8 +892,6 @@ func (r *KubeadmConfigReconciler) joinControlplane(ctx context.Context, scope *S
894892
return ctrl.Result{}, errors.Wrapf(err, "failed to parse kubernetes version %q", kubernetesVersion)
895893
}
896894

897-
// NOTE: It is required to provide in input the ClusterConfiguration because clusterConfiguration.APIServer.TimeoutForControlPlane
898-
// has been migrated to JoinConfiguration in the kubeadm v1beta4 API version.
899895
joinData, err := kubeadmtypes.MarshalJoinConfigurationForVersion(scope.Config.Spec.JoinConfiguration, parsedVersion)
900896
if err != nil {
901897
scope.Error(err, "Failed to marshal join configuration")

0 commit comments

Comments
 (0)