diff --git a/api/bootstrap/kubeadm/v1beta2/kubeadm_types.go b/api/bootstrap/kubeadm/v1beta2/kubeadm_types.go index b2be845f163b..17e3bfc7840f 100644 --- a/api/bootstrap/kubeadm/v1beta2/kubeadm_types.go +++ b/api/bootstrap/kubeadm/v1beta2/kubeadm_types.go @@ -695,11 +695,6 @@ type Discovery struct { TLSBootstrapToken string `json:"tlsBootstrapToken,omitempty"` } -// IsDefined returns true if the Discovery is defined. -func (r *Discovery) IsDefined() bool { - return !reflect.DeepEqual(r, &Discovery{}) -} - // BootstrapTokenDiscovery is used to set the options for bootstrap token based discovery. // +kubebuilder:validation:MinProperties=1 type BootstrapTokenDiscovery struct { diff --git a/controlplane/kubeadm/internal/controllers/helpers_test.go b/controlplane/kubeadm/internal/controllers/helpers_test.go index 7cf6b88bcc52..a4c88b03f44b 100644 --- a/controlplane/kubeadm/internal/controllers/helpers_test.go +++ b/controlplane/kubeadm/internal/controllers/helpers_test.go @@ -417,7 +417,9 @@ func TestCloneConfigsAndGenerateMachineAndSyncMachines(t *testing.T) { UID: kcp.UID, })) g.Expect(kubeadmConfig.Spec.InitConfiguration).To(BeComparableTo(bootstrapv1.InitConfiguration{})) - g.Expect(kubeadmConfig.Spec.JoinConfiguration).To(BeComparableTo(kcp.Spec.KubeadmConfigSpec.JoinConfiguration)) + expectedJoinConfiguration := kcp.Spec.KubeadmConfigSpec.JoinConfiguration.DeepCopy() + expectedJoinConfiguration.ControlPlane = &bootstrapv1.JoinControlPlane{} + g.Expect(kubeadmConfig.Spec.JoinConfiguration).To(BeComparableTo(*expectedJoinConfiguration)) // Note: capi-kubeadmcontrolplane should own ownerReferences and spec, labels and annotations should be orphaned. // Labels and annotations will be owned by capi-kubeadmcontrolplane-metadata after the next update // of labels and annotations. @@ -433,6 +435,7 @@ func TestCloneConfigsAndGenerateMachineAndSyncMachines(t *testing.T) { }, "f:spec":{ "f:joinConfiguration":{ + "f:controlPlane":{}, "f:nodeRegistration":{ "f:kubeletExtraArgs":{ "k:{\"name\":\"v\",\"value\":\"8\"}":{ @@ -508,6 +511,7 @@ func TestCloneConfigsAndGenerateMachineAndSyncMachines(t *testing.T) { }, "f:spec":{ "f:joinConfiguration":{ + "f:controlPlane":{}, "f:nodeRegistration":{ "f:kubeletExtraArgs":{ "k:{\"name\":\"v\",\"value\":\"8\"}":{ diff --git a/controlplane/kubeadm/internal/controllers/inplace_canupdatemachine_test.go b/controlplane/kubeadm/internal/controllers/inplace_canupdatemachine_test.go index 89832ccbf961..94c4a9c68de8 100644 --- a/controlplane/kubeadm/internal/controllers/inplace_canupdatemachine_test.go +++ b/controlplane/kubeadm/internal/controllers/inplace_canupdatemachine_test.go @@ -202,6 +202,9 @@ func Test_canExtensionsUpdateMachine(t *testing.T) { }, }, }, + JoinConfiguration: bootstrapv1.JoinConfiguration{ + ControlPlane: &bootstrapv1.JoinControlPlane{}, + }, }, } desiredKubeadmConfig := currentKubeadmConfig.DeepCopy() @@ -323,7 +326,7 @@ func Test_canExtensionsUpdateMachine(t *testing.T) { + "clusterConfiguration": map[string]any{"etcd": map[string]any{"local": map[string]any{"imageTag": string("3.6.4-0")}}}, "format": string("cloud-config"), "initConfiguration": map[string]any{"nodeRegistration": map[string]any{"imagePullPolicy": string("IfNotPresent")}}, - "joinConfiguration": map[string]any{"nodeRegistration": map[string]any{"imagePullPolicy": string("IfNotPresent")}}, + "joinConfiguration": map[string]any{"controlPlane": map[string]any{}, "nodeRegistration": map[string]any{"imagePullPolicy": string("IfNotPresent")}}, }, }, }`, @@ -424,7 +427,7 @@ func Test_canExtensionsUpdateMachine(t *testing.T) { + "clusterConfiguration": map[string]any{"etcd": map[string]any{"local": map[string]any{"imageTag": string("3.6.4-0")}}}, "format": string("cloud-config"), "initConfiguration": map[string]any{"nodeRegistration": map[string]any{"imagePullPolicy": string("IfNotPresent")}}, - "joinConfiguration": map[string]any{"nodeRegistration": map[string]any{"imagePullPolicy": string("IfNotPresent")}}, + "joinConfiguration": map[string]any{"controlPlane": map[string]any{}, "nodeRegistration": map[string]any{"imagePullPolicy": string("IfNotPresent")}}, }, }, }`, @@ -619,12 +622,7 @@ func Test_createRequest(t *testing.T) { }, }, JoinConfiguration: bootstrapv1.JoinConfiguration{ - // This field is technically set by CABPK, but adding it here so that matchesKubeadmConfig detects this correctly as a join KubeadmConfig. - Discovery: bootstrapv1.Discovery{ - BootstrapToken: bootstrapv1.BootstrapTokenDiscovery{ - APIServerEndpoint: "1.2.3.4:6443", - }, - }, + ControlPlane: &bootstrapv1.JoinControlPlane{}, NodeRegistration: bootstrapv1.NodeRegistrationOptions{ KubeletExtraArgs: []bootstrapv1.Arg{{ Name: "v", @@ -641,7 +639,6 @@ func Test_createRequest(t *testing.T) { currentKubeadmConfigCleanedUp.SetGroupVersionKind(bootstrapv1.GroupVersion.WithKind("KubeadmConfig")) // cleanupKubeadmConfig adds GVK. currentKubeadmConfigCleanedUp.Status = bootstrapv1.KubeadmConfigStatus{} // cleanupKubeadmConfig drops status. defaulting.ApplyPreviousKubeadmConfigDefaults(¤tKubeadmConfigCleanedUp.Spec) // PrepareKubeadmConfigsForDiff applies defaults. - currentKubeadmConfigCleanedUp.Spec.JoinConfiguration.Discovery = bootstrapv1.Discovery{} // PrepareKubeadmConfigsForDiff cleans up Discovery. currentKubeadmConfigWithOutdatedLabelsAndAnnotations := currentKubeadmConfig.DeepCopy() currentKubeadmConfigWithOutdatedLabelsAndAnnotations.Labels["outdated-label-1"] = "outdated-label-value-1" currentKubeadmConfigWithOutdatedLabelsAndAnnotations.Annotations["outdated-annotation-1"] = "outdated-annotation-value-1" @@ -655,7 +652,6 @@ func Test_createRequest(t *testing.T) { desiredKubeadmConfigCleanedUp.SetGroupVersionKind(bootstrapv1.GroupVersion.WithKind("KubeadmConfig")) // cleanupKubeadmConfig adds GVK. desiredKubeadmConfigCleanedUp.Status = bootstrapv1.KubeadmConfigStatus{} // cleanupKubeadmConfig drops status. defaulting.ApplyPreviousKubeadmConfigDefaults(&desiredKubeadmConfigCleanedUp.Spec) // PrepareKubeadmConfigsForDiff applies defaults. - desiredKubeadmConfigCleanedUp.Spec.JoinConfiguration.Discovery = bootstrapv1.Discovery{} // PrepareKubeadmConfigsForDiff cleans up Discovery. currentInfraMachine := &unstructured.Unstructured{ Object: map[string]interface{}{ diff --git a/controlplane/kubeadm/internal/desiredstate/desired_state.go b/controlplane/kubeadm/internal/desiredstate/desired_state.go index 072645628f13..5449f7cb9129 100644 --- a/controlplane/kubeadm/internal/desiredstate/desired_state.go +++ b/controlplane/kubeadm/internal/desiredstate/desired_state.go @@ -212,8 +212,13 @@ func ComputeDesiredKubeadmConfig(kcp *controlplanev1.KubeadmControlPlane, cluste if isJoin { // Note: When building a KubeadmConfig for a joining CP machine empty out the unnecessary InitConfiguration. spec.InitConfiguration = bootstrapv1.InitConfiguration{} - // NOTE: For the joining we are preserving the ClusterConfiguration in order to determine if the + // Note: For the joining we are preserving the ClusterConfiguration in order to determine if the // cluster is using an external etcd in the kubeadm bootstrap provider (even if this is not required by kubeadm Join). + // Note: We are always setting JoinConfiguration.ControlPlane so we can later identify this KubeadmConfig as a + // join KubeadmConfig. + if spec.JoinConfiguration.ControlPlane == nil { + spec.JoinConfiguration.ControlPlane = &bootstrapv1.JoinControlPlane{} + } } else { // Note: When building a KubeadmConfig for the first CP machine empty out the unnecessary JoinConfiguration. spec.JoinConfiguration = bootstrapv1.JoinConfiguration{} diff --git a/controlplane/kubeadm/internal/desiredstate/desired_state_test.go b/controlplane/kubeadm/internal/desiredstate/desired_state_test.go index b62830b34a7c..b7d5de7f8091 100644 --- a/controlplane/kubeadm/internal/desiredstate/desired_state_test.go +++ b/controlplane/kubeadm/internal/desiredstate/desired_state_test.go @@ -619,6 +619,7 @@ func Test_ComputeDesiredKubeadmConfig(t *testing.T) { if isJoin { expectedKubeadmConfigWithoutOwner.Spec.InitConfiguration = bootstrapv1.InitConfiguration{} expectedKubeadmConfigWithoutOwner.Spec.JoinConfiguration = kcp.Spec.KubeadmConfigSpec.JoinConfiguration + expectedKubeadmConfigWithoutOwner.Spec.JoinConfiguration.ControlPlane = &bootstrapv1.JoinControlPlane{} } else { expectedKubeadmConfigWithoutOwner.Spec.InitConfiguration = kcp.Spec.KubeadmConfigSpec.InitConfiguration expectedKubeadmConfigWithoutOwner.Spec.JoinConfiguration = bootstrapv1.JoinConfiguration{} diff --git a/controlplane/kubeadm/internal/filters.go b/controlplane/kubeadm/internal/filters.go index 71c28b6ee547..21aa383bf4da 100644 --- a/controlplane/kubeadm/internal/filters.go +++ b/controlplane/kubeadm/internal/filters.go @@ -19,7 +19,6 @@ package internal import ( "context" "fmt" - "reflect" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -308,10 +307,8 @@ func PrepareKubeadmConfigsForDiff(desiredKubeadmConfig, currentKubeadmConfig *bo currentKubeadmConfig.Spec.JoinConfiguration.Patches = currentKubeadmConfig.Spec.InitConfiguration.Patches currentKubeadmConfig.Spec.JoinConfiguration.SkipPhases = currentKubeadmConfig.Spec.InitConfiguration.SkipPhases currentKubeadmConfig.Spec.JoinConfiguration.NodeRegistration = currentKubeadmConfig.Spec.InitConfiguration.NodeRegistration - if currentKubeadmConfig.Spec.InitConfiguration.LocalAPIEndpoint.IsDefined() { - currentKubeadmConfig.Spec.JoinConfiguration.ControlPlane = &bootstrapv1.JoinControlPlane{ - LocalAPIEndpoint: currentKubeadmConfig.Spec.InitConfiguration.LocalAPIEndpoint, - } + currentKubeadmConfig.Spec.JoinConfiguration.ControlPlane = &bootstrapv1.JoinControlPlane{ + LocalAPIEndpoint: currentKubeadmConfig.Spec.InitConfiguration.LocalAPIEndpoint, } currentKubeadmConfig.Spec.InitConfiguration = bootstrapv1.InitConfiguration{} @@ -351,14 +348,6 @@ func PrepareKubeadmConfigsForDiff(desiredKubeadmConfig, currentKubeadmConfig *bo currentKubeadmConfig.Spec.InitConfiguration.Timeouts.ControlPlaneComponentHealthCheckSeconds = nil currentKubeadmConfig.Spec.JoinConfiguration.Timeouts.ControlPlaneComponentHealthCheckSeconds = nil - // If KCP JoinConfiguration.ControlPlane is nil and the Machine JoinConfiguration.ControlPlane is empty, - // set Machine JoinConfiguration.ControlPlane to nil. - // NOTE: This is required because CABPK applies an empty JoinConfiguration.ControlPlane in case it is nil. - if desiredKubeadmConfig.Spec.JoinConfiguration.ControlPlane == nil && - reflect.DeepEqual(currentKubeadmConfig.Spec.JoinConfiguration.ControlPlane, &bootstrapv1.JoinControlPlane{}) { - currentKubeadmConfig.Spec.JoinConfiguration.ControlPlane = nil - } - // Drop differences that do not lead to changes to Machines, but that might exist due // to changes in how we serialize objects or how webhooks work. dropOmittableFields(&desiredKubeadmConfig.Spec) @@ -542,15 +531,15 @@ func dropOmittableFields(spec *bootstrapv1.KubeadmConfigSpec) { // isKubeadmConfigForJoin returns true if the KubeadmConfig is for a control plane // or a worker machine that joined an existing cluster. // Note: This check is based on the assumption that KubeadmConfig for joining -// control plane and workers nodes always have a non-empty JoinConfiguration.Discovery, while -// instead the JoinConfiguration for the first control plane machine in the +// control plane always have a non-empty JoinConfiguration.ControlPlane, while +// instead the entire JoinConfiguration for the first control plane machine in the // cluster is emptied out by KCP. // Note: Previously we checked if the entire JoinConfiguration is defined, but that // is not safe because apiServer.timeoutForControlPlane in v1beta1 is also converted to // joinConfiguration.timeouts.controlPlaneComponentHealthCheckSeconds in v1beta2 and // accordingly we would also detect init KubeadmConfigs as join. func isKubeadmConfigForJoin(c *bootstrapv1.KubeadmConfig) bool { - return c.Spec.JoinConfiguration.Discovery.IsDefined() + return c.Spec.JoinConfiguration.ControlPlane != nil } // isKubeadmConfigForInit returns true if the KubeadmConfig is for the first control plane diff --git a/controlplane/kubeadm/internal/filters_test.go b/controlplane/kubeadm/internal/filters_test.go index 4e35928447d3..1e7c78a89f79 100644 --- a/controlplane/kubeadm/internal/filters_test.go +++ b/controlplane/kubeadm/internal/filters_test.go @@ -422,7 +422,7 @@ func TestMatchesKubeadmConfig(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) g.Expect(currentKubeadmConfig).ToNot(BeNil()) g.Expect(desiredKubeadmConfig).ToNot(BeNil()) - g.Expect(desiredKubeadmConfig.Spec.InitConfiguration).To(Equal(bootstrapv1.InitConfiguration{})) // Verify that this is a join. + g.Expect(isKubeadmConfigForJoin(desiredKubeadmConfig)).To(BeTrue()) g.Expect(match).To(BeTrue()) g.Expect(reason).To(BeEmpty()) }) @@ -480,7 +480,7 @@ func TestMatchesKubeadmConfig(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) g.Expect(currentKubeadmConfig).ToNot(BeNil()) g.Expect(desiredKubeadmConfig).ToNot(BeNil()) - g.Expect(desiredKubeadmConfig.Spec.InitConfiguration).To(Equal(bootstrapv1.InitConfiguration{})) // Verify that this is a join. + g.Expect(isKubeadmConfigForJoin(desiredKubeadmConfig)).To(BeTrue()) g.Expect(match).To(BeTrue()) g.Expect(reason).To(BeEmpty()) }) @@ -538,7 +538,7 @@ func TestMatchesKubeadmConfig(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) g.Expect(currentKubeadmConfig).ToNot(BeNil()) g.Expect(desiredKubeadmConfig).ToNot(BeNil()) - g.Expect(desiredKubeadmConfig.Spec.InitConfiguration).To(Equal(bootstrapv1.InitConfiguration{})) // Verify that this is a join. + g.Expect(isKubeadmConfigForJoin(desiredKubeadmConfig)).To(BeTrue()) g.Expect(match).To(BeFalse()) g.Expect(reason).To(BeComparableTo(`Machine KubeadmConfig is outdated: diff: &v1beta2.KubeadmConfigSpec{ ClusterConfiguration: {}, @@ -599,12 +599,7 @@ func TestMatchesKubeadmConfig(t *testing.T) { }, Spec: bootstrapv1.KubeadmConfigSpec{ JoinConfiguration: bootstrapv1.JoinConfiguration{ - // This field is technically set by CABPK, but adding it here so that matchesKubeadmConfig detects this correctly as a join KubeadmConfig. - Discovery: bootstrapv1.Discovery{ - BootstrapToken: bootstrapv1.BootstrapTokenDiscovery{ - APIServerEndpoint: "1.2.3.4:6443", - }, - }, + ControlPlane: &bootstrapv1.JoinControlPlane{}, NodeRegistration: bootstrapv1.NodeRegistrationOptions{ Name: "A new name", }, @@ -616,7 +611,7 @@ func TestMatchesKubeadmConfig(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) g.Expect(currentKubeadmConfig).ToNot(BeNil()) g.Expect(desiredKubeadmConfig).ToNot(BeNil()) - g.Expect(desiredKubeadmConfig.Spec.InitConfiguration).To(Equal(bootstrapv1.InitConfiguration{})) // Verify that this is a join. + g.Expect(isKubeadmConfigForJoin(desiredKubeadmConfig)).To(BeTrue()) g.Expect(match).To(BeTrue()) g.Expect(reason).To(BeEmpty()) }) @@ -664,16 +659,12 @@ func TestMatchesKubeadmConfig(t *testing.T) { }, Spec: bootstrapv1.KubeadmConfigSpec{ JoinConfiguration: bootstrapv1.JoinConfiguration{ + ControlPlane: &bootstrapv1.JoinControlPlane{}, NodeRegistration: bootstrapv1.NodeRegistrationOptions{ Name: "A new name", }, - // This field is technically set by CABPK, but adding it here so that matchesKubeadmConfig detects this correctly as a join KubeadmConfig. - // Discovery gets removed only for the diff because Discovery is not relevant for the rollout decision. - Discovery: bootstrapv1.Discovery{ - BootstrapToken: bootstrapv1.BootstrapTokenDiscovery{ - APIServerEndpoint: "1.2.3.4:6443", - }, - }, + // Discovery gets removed because Discovery is not relevant for the rollout decision. + Discovery: bootstrapv1.Discovery{TLSBootstrapToken: "bbb"}, Timeouts: bootstrapv1.Timeouts{ ControlPlaneComponentHealthCheckSeconds: ptr.To[int32](11), }, @@ -685,7 +676,7 @@ func TestMatchesKubeadmConfig(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) g.Expect(currentKubeadmConfig).ToNot(BeNil()) g.Expect(desiredKubeadmConfig).ToNot(BeNil()) - g.Expect(desiredKubeadmConfig.Spec.InitConfiguration).To(Equal(bootstrapv1.InitConfiguration{})) // Verify that this is a join. + g.Expect(isKubeadmConfigForJoin(desiredKubeadmConfig)).To(BeTrue()) g.Expect(match).To(BeTrue()) g.Expect(reason).To(BeEmpty()) }) @@ -729,16 +720,12 @@ func TestMatchesKubeadmConfig(t *testing.T) { }, Spec: bootstrapv1.KubeadmConfigSpec{ JoinConfiguration: bootstrapv1.JoinConfiguration{ - // This field is technically set by CABPK, but adding it here so that matchesKubeadmConfig detects this correctly as a join KubeadmConfig. - Discovery: bootstrapv1.Discovery{ - BootstrapToken: bootstrapv1.BootstrapTokenDiscovery{ - APIServerEndpoint: "1.2.3.4:6443", - }, - }, NodeRegistration: bootstrapv1.NodeRegistrationOptions{ Name: "A new name", }, - ControlPlane: &bootstrapv1.JoinControlPlane{}, // Machine gets a default JoinConfiguration.ControlPlane from CABPK + // Machine gets a default JoinConfiguration.ControlPlane from CABPK + // Note: This field is now also set by KCP, but leaving this case here for additional coverage. + ControlPlane: &bootstrapv1.JoinControlPlane{}, }, }, }, @@ -747,7 +734,7 @@ func TestMatchesKubeadmConfig(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) g.Expect(currentKubeadmConfig).ToNot(BeNil()) g.Expect(desiredKubeadmConfig).ToNot(BeNil()) - g.Expect(desiredKubeadmConfig.Spec.InitConfiguration).To(Equal(bootstrapv1.InitConfiguration{})) // Verify that this is a join. + g.Expect(isKubeadmConfigForJoin(desiredKubeadmConfig)).To(BeTrue()) g.Expect(match).To(BeTrue()) g.Expect(reason).To(BeEmpty()) }) @@ -805,7 +792,7 @@ func TestMatchesKubeadmConfig(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) g.Expect(currentKubeadmConfig).ToNot(BeNil()) g.Expect(desiredKubeadmConfig).ToNot(BeNil()) - g.Expect(desiredKubeadmConfig.Spec.InitConfiguration).To(Equal(bootstrapv1.InitConfiguration{})) // Verify that this is a join. + g.Expect(isKubeadmConfigForJoin(desiredKubeadmConfig)).To(BeTrue()) g.Expect(match).To(BeFalse()) g.Expect(reason).To(Equal(`Machine KubeadmConfig is outdated: diff: &v1beta2.KubeadmConfigSpec{ ClusterConfiguration: {}, @@ -867,12 +854,6 @@ func TestMatchesKubeadmConfig(t *testing.T) { }, Spec: bootstrapv1.KubeadmConfigSpec{ JoinConfiguration: bootstrapv1.JoinConfiguration{ - // This field is technically set by CABPK, but adding it here so that matchesKubeadmConfig detects this correctly as a join KubeadmConfig. - Discovery: bootstrapv1.Discovery{ - BootstrapToken: bootstrapv1.BootstrapTokenDiscovery{ - APIServerEndpoint: "1.2.3.4:6443", - }, - }, NodeRegistration: bootstrapv1.NodeRegistrationOptions{ Name: "name", }, @@ -890,7 +871,7 @@ func TestMatchesKubeadmConfig(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) g.Expect(currentKubeadmConfig).ToNot(BeNil()) g.Expect(desiredKubeadmConfig).ToNot(BeNil()) - g.Expect(desiredKubeadmConfig.Spec.InitConfiguration).To(Equal(bootstrapv1.InitConfiguration{})) // Verify that this is a join. + g.Expect(isKubeadmConfigForJoin(desiredKubeadmConfig)).To(BeTrue()) g.Expect(match).To(BeFalse()) g.Expect(reason).To(Equal(`Machine KubeadmConfig is outdated: diff: &v1beta2.KubeadmConfigSpec{ ClusterConfiguration: {}, @@ -899,13 +880,17 @@ func TestMatchesKubeadmConfig(t *testing.T) { NodeRegistration: {Name: "name", ImagePullPolicy: "IfNotPresent"}, CACertPath: "", Discovery: {}, -- ControlPlane: &v1beta2.JoinControlPlane{ -- LocalAPIEndpoint: v1beta2.APIEndpoint{AdvertiseAddress: "1.2.3.4", BindPort: 6443}, -- }, -+ ControlPlane: nil, - SkipPhases: nil, - Patches: {}, - Timeouts: {}, + ControlPlane: &v1beta2.JoinControlPlane{ + LocalAPIEndpoint: v1beta2.APIEndpoint{ +- AdvertiseAddress: "1.2.3.4", ++ AdvertiseAddress: "", +- BindPort: 6443, ++ BindPort: 0, + }, + }, + SkipPhases: nil, + Patches: {}, + Timeouts: {}, }, Files: nil, DiskSetup: {}, @@ -951,12 +936,7 @@ func TestMatchesKubeadmConfig(t *testing.T) { }, Spec: bootstrapv1.KubeadmConfigSpec{ JoinConfiguration: bootstrapv1.JoinConfiguration{ - // This field is technically set by CABPK, but adding it here so that matchesKubeadmConfig detects this correctly as a join KubeadmConfig. - Discovery: bootstrapv1.Discovery{ - BootstrapToken: bootstrapv1.BootstrapTokenDiscovery{ - APIServerEndpoint: "1.2.3.4:6443", - }, - }, + ControlPlane: &bootstrapv1.JoinControlPlane{}, NodeRegistration: bootstrapv1.NodeRegistrationOptions{ Name: "An old name", // This is a change }, @@ -968,7 +948,7 @@ func TestMatchesKubeadmConfig(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) g.Expect(currentKubeadmConfig).ToNot(BeNil()) g.Expect(desiredKubeadmConfig).ToNot(BeNil()) - g.Expect(desiredKubeadmConfig.Spec.InitConfiguration).To(Equal(bootstrapv1.InitConfiguration{})) // Verify that this is a join. + g.Expect(isKubeadmConfigForJoin(desiredKubeadmConfig)).To(BeTrue()) g.Expect(match).To(BeFalse()) g.Expect(reason).To(BeComparableTo(`Machine KubeadmConfig is outdated: diff: &v1beta2.KubeadmConfigSpec{ ClusterConfiguration: {}, @@ -1025,12 +1005,7 @@ func TestMatchesKubeadmConfig(t *testing.T) { }, Spec: bootstrapv1.KubeadmConfigSpec{ JoinConfiguration: bootstrapv1.JoinConfiguration{ - // This field is technically set by CABPK, but adding it here so that matchesKubeadmConfig detects this correctly as a join KubeadmConfig. - Discovery: bootstrapv1.Discovery{ - BootstrapToken: bootstrapv1.BootstrapTokenDiscovery{ - APIServerEndpoint: "1.2.3.4:6443", - }, - }, + ControlPlane: &bootstrapv1.JoinControlPlane{}, NodeRegistration: bootstrapv1.NodeRegistrationOptions{ Name: "An old name", // This is a change }, @@ -1114,12 +1089,7 @@ func TestMatchesKubeadmConfig(t *testing.T) { ClusterConfiguration: bootstrapv1.ClusterConfiguration{}, InitConfiguration: bootstrapv1.InitConfiguration{}, JoinConfiguration: bootstrapv1.JoinConfiguration{ - // This field is technically set by CABPK, but adding it here so that matchesKubeadmConfig detects this correctly as a join KubeadmConfig. - Discovery: bootstrapv1.Discovery{ - BootstrapToken: bootstrapv1.BootstrapTokenDiscovery{ - APIServerEndpoint: "1.2.3.4:6443", - }, - }, + ControlPlane: &bootstrapv1.JoinControlPlane{}, NodeRegistration: bootstrapv1.NodeRegistrationOptions{ Name: "name", }, @@ -1131,7 +1101,7 @@ func TestMatchesKubeadmConfig(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) g.Expect(currentKubeadmConfig).ToNot(BeNil()) g.Expect(desiredKubeadmConfig).ToNot(BeNil()) - g.Expect(desiredKubeadmConfig.Spec.InitConfiguration).To(Equal(bootstrapv1.InitConfiguration{})) // Verify that this is a join. + g.Expect(isKubeadmConfigForJoin(desiredKubeadmConfig)).To(BeTrue()) g.Expect(match).To(BeTrue()) g.Expect(reason).To(BeEmpty()) }) @@ -1174,12 +1144,7 @@ func TestMatchesKubeadmConfig(t *testing.T) { Spec: bootstrapv1.KubeadmConfigSpec{ Format: "", JoinConfiguration: bootstrapv1.JoinConfiguration{ - // This field is technically set by CABPK, but adding it here so that matchesKubeadmConfig detects this correctly as a join KubeadmConfig. - Discovery: bootstrapv1.Discovery{ - BootstrapToken: bootstrapv1.BootstrapTokenDiscovery{ - APIServerEndpoint: "1.2.3.4:6443", - }, - }, + ControlPlane: &bootstrapv1.JoinControlPlane{}, NodeRegistration: bootstrapv1.NodeRegistrationOptions{ Name: "name", }, @@ -1191,7 +1156,7 @@ func TestMatchesKubeadmConfig(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) g.Expect(currentKubeadmConfig).ToNot(BeNil()) g.Expect(desiredKubeadmConfig).ToNot(BeNil()) - g.Expect(desiredKubeadmConfig.Spec.InitConfiguration).To(Equal(bootstrapv1.InitConfiguration{})) // Verify that this is a join. + g.Expect(isKubeadmConfigForJoin(desiredKubeadmConfig)).To(BeTrue()) g.Expect(match).To(BeTrue()) g.Expect(reason).To(BeEmpty()) }) @@ -1235,12 +1200,7 @@ func TestMatchesKubeadmConfig(t *testing.T) { }, Spec: bootstrapv1.KubeadmConfigSpec{ JoinConfiguration: bootstrapv1.JoinConfiguration{ - // This field is technically set by CABPK, but adding it here so that matchesKubeadmConfig detects this correctly as a join KubeadmConfig. - Discovery: bootstrapv1.Discovery{ - BootstrapToken: bootstrapv1.BootstrapTokenDiscovery{ - APIServerEndpoint: "1.2.3.4:6443", - }, - }, + ControlPlane: &bootstrapv1.JoinControlPlane{}, NodeRegistration: bootstrapv1.NodeRegistrationOptions{ Name: "name", }, @@ -1252,12 +1212,12 @@ func TestMatchesKubeadmConfig(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) g.Expect(currentKubeadmConfig).ToNot(BeNil()) g.Expect(desiredKubeadmConfig).ToNot(BeNil()) - g.Expect(desiredKubeadmConfig.Spec.InitConfiguration).To(Equal(bootstrapv1.InitConfiguration{})) // Verify that this is a join. + g.Expect(isKubeadmConfigForJoin(desiredKubeadmConfig)).To(BeTrue()) g.Expect(match).To(BeFalse()) g.Expect(reason).To(BeComparableTo(`Machine KubeadmConfig is outdated: diff: &v1beta2.KubeadmConfigSpec{ ClusterConfiguration: {}, InitConfiguration: {NodeRegistration: {ImagePullPolicy: "IfNotPresent"}}, - JoinConfiguration: {NodeRegistration: {Name: "name", ImagePullPolicy: "IfNotPresent"}}, + JoinConfiguration: {NodeRegistration: {Name: "name", ImagePullPolicy: "IfNotPresent"}, ControlPlane: &{}}, - Files: nil, + Files: []v1beta2.File{{Path: "/tmp/foo"}}, DiskSetup: {},