Skip to content

Commit

Permalink
fix matchClusterConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziopandini committed Jul 16, 2020
1 parent 19afe6c commit 6d9699a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
10 changes: 8 additions & 2 deletions controlplane/kubeadm/internal/machinefilters/machine_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,14 @@ 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 {
return false
// NOTE: it is required to handle a nil ClusterConfiguration (that is serialized into "null") as a special case,
// because Unmarshal returns &kubeadmv1.ClusterConfiguration{}, not nil; see https://github.com/kubernetes-sigs/cluster-api/issues/3353
if machineClusterConfigStr != "null" {
if err := json.Unmarshal([]byte(machineClusterConfigStr), machineClusterConfig); err != nil {
return false
}
} else {
machineClusterConfig = nil
}
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 6d9699a

Please sign in to comment.