Skip to content

Commit

Permalink
Merge pull request #2616 from ncdc/fix-kcp-validation-etcd-npe
Browse files Browse the repository at this point in the history
🐛 Fix NPE when validating KCP etcd settings
  • Loading branch information
k8s-ci-robot authored Mar 10, 2020
2 parents f2a71f4 + f2555be commit 37706a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ func (in *KubeadmControlPlane) validateCommon() (allErrs field.ErrorList) {
}

func (in *KubeadmControlPlane) validateEtcd(prev *KubeadmControlPlane) (allErrs field.ErrorList) {
if in.Spec.KubeadmConfigSpec.ClusterConfiguration == nil {
return allErrs
}

if in.Spec.KubeadmConfigSpec.ClusterConfiguration.Etcd.External != nil && prev.Spec.KubeadmConfigSpec.ClusterConfiguration.Etcd.Local != nil {
allErrs = append(
allErrs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) {
},
}

withoutClusterConfiguration := before.DeepCopy()
withoutClusterConfiguration.Spec.KubeadmConfigSpec.ClusterConfiguration = nil

tests := []struct {
name string
expectErr bool
Expand Down Expand Up @@ -476,6 +479,12 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) {
before: beforeInvalidEtcdCluster,
kcp: afterInvalidEtcdCluster,
},
{
name: "should pass if ClusterConfiguration is nil",
expectErr: false,
before: withoutClusterConfiguration,
kcp: withoutClusterConfiguration,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 37706a1

Please sign in to comment.