Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-0.19] Add check for nil eksaversion when setting etcd url #8032

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/clusterapi/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// SetUbuntuConfigInEtcdCluster sets up the etcd config in EtcdadmCluster.
func SetUbuntuConfigInEtcdCluster(etcd *etcdv1.EtcdadmCluster, versionsBundle *cluster.VersionsBundle, eksaVersion string) {
func SetUbuntuConfigInEtcdCluster(etcd *etcdv1.EtcdadmCluster, versionsBundle *cluster.VersionsBundle, eksaVersion *v1alpha1.EksaVersion) {
etcd.Spec.EtcdadmConfigSpec.Format = etcdbootstrapv1.Format("cloud-config")
etcd.Spec.EtcdadmConfigSpec.CloudInitConfig = &etcdbootstrapv1.CloudInitConfig{
Version: versionsBundle.KubeDistro.EtcdVersion,
Expand Down
6 changes: 2 additions & 4 deletions pkg/clusterapi/etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
func TestSetUbuntuConfigInEtcdCluster(t *testing.T) {
g := newApiBuilerTest(t)
eksaVersion := anywherev1.EksaVersion("v0.19.2")
g.clusterSpec.Cluster.Spec.EksaVersion = &eksaVersion
got := wantEtcdCluster()
versionBundle := g.clusterSpec.VersionsBundles["1.21"]

Expand All @@ -26,14 +25,13 @@ func TestSetUbuntuConfigInEtcdCluster(t *testing.T) {
InstallDir: "/usr/bin",
EtcdReleaseURL: versionBundle.KubeDistro.EtcdURL,
}
clusterapi.SetUbuntuConfigInEtcdCluster(got, versionBundle, string(eksaVersion))
clusterapi.SetUbuntuConfigInEtcdCluster(got, versionBundle, &eksaVersion)
g.Expect(got).To(Equal(want))
}

func TestSetUbuntuConfigInEtcdClusterNoEtcdUrl(t *testing.T) {
g := newApiBuilerTest(t)
eksaVersion := anywherev1.EksaVersion("v0.18.2")
g.clusterSpec.Cluster.Spec.EksaVersion = &eksaVersion
got := wantEtcdCluster()
versionBundle := g.clusterSpec.VersionsBundles["1.21"]

Expand All @@ -43,7 +41,7 @@ func TestSetUbuntuConfigInEtcdClusterNoEtcdUrl(t *testing.T) {
Version: versionBundle.KubeDistro.EtcdVersion,
InstallDir: "/usr/bin",
}
clusterapi.SetUbuntuConfigInEtcdCluster(got, versionBundle, string(eksaVersion))
clusterapi.SetUbuntuConfigInEtcdCluster(got, versionBundle, &eksaVersion)
g.Expect(got).To(Equal(want))
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/cloudstack/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func buildTemplateMapCP(clusterSpec *cluster.Spec) (map[string]interface{}, erro
values["externalEtcd"] = true
values["externalEtcdReplicas"] = clusterSpec.Cluster.Spec.ExternalEtcdConfiguration.Count
values["etcdSshUsername"] = etcdMachineSpec.Users[0].Name
etcdURL, _ := common.GetExternalEtcdReleaseURL(string(*clusterSpec.Cluster.Spec.EksaVersion), versionsBundle)
etcdURL, _ := common.GetExternalEtcdReleaseURL(clusterSpec.Cluster.Spec.EksaVersion, versionsBundle)
if etcdURL != "" {
values["externalEtcdReleaseUrl"] = etcdURL
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/providers/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,12 @@ func GetCAPIBottlerocketSettingsConfig(config *v1alpha1.BottlerocketConfiguratio

// GetExternalEtcdReleaseURL returns a valid etcd URL from version bundles if the eksaVersion is greater than
// MinEksAVersionWithEtcdURL. Return "" if eksaVersion < MinEksAVersionWithEtcdURL to prevent etcd node rolled out.
func GetExternalEtcdReleaseURL(clusterVersion string, versionBundle *cluster.VersionsBundle) (string, error) {
clusterVersionSemVer, err := semver.New(clusterVersion)
func GetExternalEtcdReleaseURL(clusterVersion *v1alpha1.EksaVersion, versionBundle *cluster.VersionsBundle) (string, error) {
if clusterVersion == nil {
logger.V(4).Info("Eks-a cluster version is not specified. Skip setting etcd url")
return "", nil
}
clusterVersionSemVer, err := semver.New(string(*clusterVersion))
if err != nil {
return "", fmt.Errorf("invalid semver for clusterVersion: %v", err)
}
Expand Down
10 changes: 9 additions & 1 deletion pkg/providers/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ func TestGetExternalEtcdReleaseURL(t *testing.T) {
}
for _, tt := range testcases {
t.Run(tt.name, func(t *testing.T) {
got, err := common.GetExternalEtcdReleaseURL(tt.clusterVersion, test.VersionBundle())
eksaVersion := v1alpha1.EksaVersion(tt.clusterVersion)
got, err := common.GetExternalEtcdReleaseURL(&eksaVersion, test.VersionBundle())
if tt.err == nil {
g.Expect(err).ToNot(HaveOccurred())
} else {
Expand All @@ -185,3 +186,10 @@ func TestGetExternalEtcdReleaseURL(t *testing.T) {
})
}
}

func TestGetExternalEtcdReleaseURLWithNilEksaVersion(t *testing.T) {
g := NewWithT(t)
got, err := common.GetExternalEtcdReleaseURL(nil, test.VersionBundle())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(got).To(BeEmpty())
}
2 changes: 1 addition & 1 deletion pkg/providers/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func buildTemplateMapCP(clusterSpec *cluster.Spec) (map[string]interface{}, erro
if clusterSpec.Cluster.Spec.ExternalEtcdConfiguration != nil {
values["externalEtcd"] = true
values["externalEtcdReplicas"] = clusterSpec.Cluster.Spec.ExternalEtcdConfiguration.Count
etcdURL, _ := common.GetExternalEtcdReleaseURL(string(*clusterSpec.Cluster.Spec.EksaVersion), versionsBundle)
etcdURL, _ := common.GetExternalEtcdReleaseURL(clusterSpec.Cluster.Spec.EksaVersion, versionsBundle)
if etcdURL != "" {
values["externalEtcdReleaseUrl"] = etcdURL
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/nutanix/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func buildTemplateMapCP(
values["maxSurge"] = clusterSpec.Cluster.Spec.ControlPlaneConfiguration.UpgradeRolloutStrategy.RollingUpdate.MaxSurge
}

etcdURL, _ := common.GetExternalEtcdReleaseURL(string(*clusterSpec.Cluster.Spec.EksaVersion), versionsBundle)
etcdURL, _ := common.GetExternalEtcdReleaseURL(clusterSpec.Cluster.Spec.EksaVersion, versionsBundle)
if etcdURL != "" {
values["externalEtcdReleaseUrl"] = etcdURL
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/snow/apibuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func EtcdadmCluster(log logr.Logger, clusterSpec *cluster.Spec, snowMachineTempl
clusterapi.SetBottlerocketHostConfigInEtcdCluster(etcd, machineConfig.Spec.HostOSConfiguration)

case v1alpha1.Ubuntu:
clusterapi.SetUbuntuConfigInEtcdCluster(etcd, versionsBundle, string(*clusterSpec.Cluster.Spec.EksaVersion))
clusterapi.SetUbuntuConfigInEtcdCluster(etcd, versionsBundle, clusterSpec.Cluster.Spec.EksaVersion)
etcd.Spec.EtcdadmConfigSpec.PreEtcdadmCommands = append(etcd.Spec.EtcdadmConfigSpec.PreEtcdadmCommands,
"/etc/eks/bootstrap.sh",
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/tinkerbell/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@
values["etcdSshUsername"] = etcdMachineSpec.Users[0].Name
values["etcdTemplateOverride"] = etcdTemplateOverride
values["etcdHardwareSelector"] = etcdMachineSpec.HardwareSelector
etcdURL, _ := common.GetExternalEtcdReleaseURL(string(*clusterSpec.Cluster.Spec.EksaVersion), versionsBundle)
etcdURL, _ := common.GetExternalEtcdReleaseURL(clusterSpec.Cluster.Spec.EksaVersion, versionsBundle)

Check warning on line 484 in pkg/providers/tinkerbell/template.go

View check run for this annotation

Codecov / codecov/patch

pkg/providers/tinkerbell/template.go#L484

Added line #L484 was not covered by tests
if etcdURL != "" {
values["externalEtcdReleaseUrl"] = etcdURL
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/vsphere/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func buildTemplateMapCP(
}
}
}
etcdURL, _ := common.GetExternalEtcdReleaseURL(string(*clusterSpec.Cluster.Spec.EksaVersion), versionsBundle)
etcdURL, _ := common.GetExternalEtcdReleaseURL(clusterSpec.Cluster.Spec.EksaVersion, versionsBundle)
if etcdURL != "" {
values["externalEtcdReleaseUrl"] = etcdURL
}
Expand Down
Loading