Skip to content

Commit

Permalink
Fix NPE when validating KCP etcd settings
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Goldstein <[email protected]>
  • Loading branch information
ncdc committed Mar 10, 2020
1 parent f2a71f4 commit f2555be
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 f2555be

Please sign in to comment.