From 0ed18ee58ee3728933ae721fdd4aff597e85b705 Mon Sep 17 00:00:00 2001 From: Martina Iglesias Date: Fri, 10 Jul 2020 10:25:51 +0200 Subject: [PATCH] Fix cluster upgrading to default version always (#2414) --- pkg/ctl/update/cluster.go | 2 ++ pkg/ctl/upgrade/cluster.go | 2 ++ pkg/ctl/upgrade/cluster_test.go | 21 +++++++++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pkg/ctl/update/cluster.go b/pkg/ctl/update/cluster.go index bb23305ef7..df14e74dfe 100644 --- a/pkg/ctl/update/cluster.go +++ b/pkg/ctl/update/cluster.go @@ -14,6 +14,8 @@ import ( func updateClusterCmd(cmd *cmdutils.Cmd) { cfg := api.NewClusterConfig() + // Reset version before loading + cfg.Metadata.Version = "" cmd.ClusterConfig = cfg cmd.SetDescription("cluster", "DEPRECATED: use 'upgrade cluster' instead. Upgrade control plane to the next version. ", diff --git a/pkg/ctl/upgrade/cluster.go b/pkg/ctl/upgrade/cluster.go index a5af9e4788..7c76daafc0 100644 --- a/pkg/ctl/upgrade/cluster.go +++ b/pkg/ctl/upgrade/cluster.go @@ -21,6 +21,8 @@ func upgradeCluster(cmd *cmdutils.Cmd) { func upgradeClusterWithRunFunc(cmd *cmdutils.Cmd, runFunc func(cmd *cmdutils.Cmd) error) { cfg := api.NewClusterConfig() + // Reset version + cfg.Metadata.Version = "" cmd.ClusterConfig = cfg cmd.SetDescription("cluster", "Upgrade control plane to the next version", diff --git a/pkg/ctl/upgrade/cluster_test.go b/pkg/ctl/upgrade/cluster_test.go index 355a8af105..7e12037194 100644 --- a/pkg/ctl/upgrade/cluster_test.go +++ b/pkg/ctl/upgrade/cluster_test.go @@ -61,8 +61,13 @@ var _ = Describe("upgrade cluster", func() { cfg := cmd.Cmd.ClusterConfig Expect(cfg.Metadata.Name).To(Equal("clus-1")) + + // The version should be empty when not specified as a flag + Expect(cfg.Metadata.Version).To(Equal("")) + // I cannot test the region here because this flag is loaded into the cmd.ProviderConfig.Region //Expect(cfg.Metadata.Region).To(Equal("us-west-2")) + Expect(cmd.Cmd.ProviderConfig.Region).To(Equal("us-west-2")) Expect(cmd.Cmd.Plan).To(BeFalse()) Expect(cmd.Cmd.ProviderConfig.WaitTimeout).To(Equal(123 * time.Minute)) @@ -147,6 +152,18 @@ var _ = Describe("upgrade cluster", func() { Expect(loadedCfg.Region).To(Equal("us-west-2")) Expect(loadedCfg.Version).To(Equal("1.16")) }) + + It("when not specified in the config file the version is empty", func() { + cfg.Metadata.Version = "" + configFile = CreateConfigFile(cfg) + + cmd := newMockUpgradeClusterCmd("cluster", "--config-file", configFile) + _, err := cmd.Execute() + Expect(err).To(Not(HaveOccurred())) + + loadedCfg := cmd.Cmd.ClusterConfig.Metadata + Expect(loadedCfg.Version).To(Equal("")) + }) }) type upgradeCase struct { @@ -175,8 +192,8 @@ var _ = Describe("upgrade cluster", func() { Entry("upgrades by default when the version is not specified", upgradeCase{ givenVersion: "", - eksVersion: "1.15", - expectedUpgradeVersion: "1.16", + eksVersion: "1.16", + expectedUpgradeVersion: "1.17", expectedUpgrade: true, }),