Skip to content

Commit

Permalink
fix matchClusterConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziopandini committed Jul 17, 2020
1 parent 19afe6c commit a75ad0e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ func matchClusterConfiguration(kcp *controlplanev1.KubeadmControlPlane, machine
if ok {
machineClusterConfig := &kubeadmv1.ClusterConfiguration{}
// ClusterConfiguration annotation is not correct, only solution is to rollout.
if err := json.Unmarshal([]byte(machineClusterConfigStr), machineClusterConfig); err != nil {
// NOTE: it is required to handle a nil ClusterConfiguration (that is serialized into "null")
// see https://github.com/kubernetes-sigs/cluster-api/issues/3353
if err := json.Unmarshal([]byte(machineClusterConfigStr), &machineClusterConfig); err != nil {
return false
}
return reflect.DeepEqual(machineClusterConfig, kcp.Spec.KubeadmConfigSpec.ClusterConfiguration)
Expand Down
16 changes: 16 additions & 0 deletions controlplane/kubeadm/internal/machinefilters/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ func TestMatchClusterConfiguration(t *testing.T) {
}
g.Expect(matchClusterConfiguration(kcp, m)).To(gomega.BeFalse())
})
t.Run("Return true if cluster configuration is nil (special case)", func(t *testing.T) {
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{
Spec: controlplanev1.KubeadmControlPlaneSpec{
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{},
},
}
m := &clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
controlplanev1.KubeadmClusterConfigurationAnnotation: "null",
},
},
}
g.Expect(matchClusterConfiguration(kcp, m)).To(gomega.BeTrue())
})
}

func TestGetAdjustedKcpConfig(t *testing.T) {
Expand Down

0 comments on commit a75ad0e

Please sign in to comment.