From c3a5f27c7742991a81c6bbc7bb8e15478f68a20d Mon Sep 17 00:00:00 2001 From: Mayank Shah Date: Tue, 12 Nov 2024 16:58:47 +0530 Subject: [PATCH 1/6] Add --take-ownership flag for install and upgrade commands The `TakeOwnership` setting was added to the install and upgrade actions in https://github.com/helm/helm/pull/12876 This PR allows setting this option on install and upgrade via the CLI using a --take-ownership flag Signed-off-by: Mayank Shah --- cmd/helm/install.go | 1 + cmd/helm/install_test.go | 6 ++++++ cmd/helm/testdata/output/install-and-take-ownership.txt | 6 ++++++ cmd/helm/testdata/output/upgrade-and-take-ownership.txt | 7 +++++++ cmd/helm/upgrade.go | 1 + cmd/helm/upgrade_test.go | 6 ++++++ 6 files changed, 27 insertions(+) create mode 100644 cmd/helm/testdata/output/install-and-take-ownership.txt create mode 100644 cmd/helm/testdata/output/upgrade-and-take-ownership.txt diff --git a/cmd/helm/install.go b/cmd/helm/install.go index 23ff29d95..80163137e 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -201,6 +201,7 @@ func addInstallFlags(cmd *cobra.Command, f *pflag.FlagSet, client *action.Instal f.StringToStringVarP(&client.Labels, "labels", "l", nil, "Labels that would be added to release metadata. Should be divided by comma.") f.BoolVar(&client.EnableDNS, "enable-dns", false, "enable DNS lookups when rendering templates") f.BoolVar(&client.HideNotes, "hide-notes", false, "if set, do not show notes in install output. Does not affect presence in chart metadata") + f.BoolVar(&client.TakeOwnership, "take-ownership", false, "if set, install will ignore the check for helm annotations and take ownership of the existing resources.") addValueOptionsFlags(f, valueOpts) addChartPathOptionsFlags(f, &client.ChartPathOptions) diff --git a/cmd/helm/install_test.go b/cmd/helm/install_test.go index 3709c393e..f81778eab 100644 --- a/cmd/helm/install_test.go +++ b/cmd/helm/install_test.go @@ -102,6 +102,12 @@ func TestInstall(t *testing.T) { cmd: "install aeneas testdata/testcharts/empty --replace", golden: "output/install-and-replace.txt", }, + // Install, take ownership + { + name: "install and replace release", + cmd: "install aeneas-take-ownership testdata/testcharts/empty --take-ownership", + golden: "output/install-and-take-ownership.txt", + }, // Install, with timeout { name: "install with a timeout", diff --git a/cmd/helm/testdata/output/install-and-take-ownership.txt b/cmd/helm/testdata/output/install-and-take-ownership.txt new file mode 100644 index 000000000..51e626446 --- /dev/null +++ b/cmd/helm/testdata/output/install-and-take-ownership.txt @@ -0,0 +1,6 @@ +NAME: aeneas-take-ownership +LAST DEPLOYED: Fri Sep 2 22:04:05 1977 +NAMESPACE: default +STATUS: deployed +REVISION: 1 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/upgrade-and-take-ownership.txt b/cmd/helm/testdata/output/upgrade-and-take-ownership.txt new file mode 100644 index 000000000..bea42db54 --- /dev/null +++ b/cmd/helm/testdata/output/upgrade-and-take-ownership.txt @@ -0,0 +1,7 @@ +Release "funny-bunny" has been upgraded. Happy Helming! +NAME: funny-bunny +LAST DEPLOYED: Fri Sep 2 22:04:05 1977 +NAMESPACE: default +STATUS: deployed +REVISION: 3 +TEST SUITE: None diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index 108550cbf..a0bec29ad 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -280,6 +280,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { f.StringVar(&client.Description, "description", "", "add a custom description") f.BoolVar(&client.DependencyUpdate, "dependency-update", false, "update dependencies if they are missing before installing the chart") f.BoolVar(&client.EnableDNS, "enable-dns", false, "enable DNS lookups when rendering templates") + f.BoolVar(&client.TakeOwnership, "take-ownership", false, "if set, upgrade will ignore the check for helm annotations and take ownership of the existing resources.") addChartPathOptionsFlags(f, &client.ChartPathOptions) addValueOptionsFlags(f, valueOpts) bindOutputFlag(cmd, &outfmt) diff --git a/cmd/helm/upgrade_test.go b/cmd/helm/upgrade_test.go index 497c78d71..6065647b9 100644 --- a/cmd/helm/upgrade_test.go +++ b/cmd/helm/upgrade_test.go @@ -114,6 +114,12 @@ func TestUpgradeCmd(t *testing.T) { golden: "output/upgrade-with-reset-values2.txt", rels: []*release.Release{relMock("funny-bunny", 5, ch2)}, }, + { + name: "upgrade a release with --take-ownership", + cmd: fmt.Sprintf("upgrade funny-bunny '%s' --take-ownership", chartPath), + golden: "output/upgrade-and-take-ownership.txt", + rels: []*release.Release{relMock("funny-bunny", 2, ch)}, + }, { name: "install a release with 'upgrade --install'", cmd: fmt.Sprintf("upgrade zany-bunny -i '%s'", chartPath), From 7efa2862ad48be335b5e2346f53db36bfe7bbcb2 Mon Sep 17 00:00:00 2001 From: Mayank Shah Date: Tue, 19 Nov 2024 10:03:03 +0530 Subject: [PATCH 2/6] Update cmd/helm/install.go Co-authored-by: George Jenkins Signed-off-by: Mayank Shah --- cmd/helm/install.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/helm/install.go b/cmd/helm/install.go index 80163137e..bf9519f5d 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -201,7 +201,7 @@ func addInstallFlags(cmd *cobra.Command, f *pflag.FlagSet, client *action.Instal f.StringToStringVarP(&client.Labels, "labels", "l", nil, "Labels that would be added to release metadata. Should be divided by comma.") f.BoolVar(&client.EnableDNS, "enable-dns", false, "enable DNS lookups when rendering templates") f.BoolVar(&client.HideNotes, "hide-notes", false, "if set, do not show notes in install output. Does not affect presence in chart metadata") - f.BoolVar(&client.TakeOwnership, "take-ownership", false, "if set, install will ignore the check for helm annotations and take ownership of the existing resources.") + f.BoolVar(&client.TakeOwnership, "take-ownership", false, "if set, install will ignore the check for helm annotations and take ownership of the existing resources") addValueOptionsFlags(f, valueOpts) addChartPathOptionsFlags(f, &client.ChartPathOptions) From 885e938793203383abb9331b4a0662df85d2cbeb Mon Sep 17 00:00:00 2001 From: Mayank Shah Date: Tue, 19 Nov 2024 10:03:09 +0530 Subject: [PATCH 3/6] Update cmd/helm/upgrade.go Co-authored-by: George Jenkins Signed-off-by: Mayank Shah --- cmd/helm/upgrade.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index a0bec29ad..1fe793a92 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -280,7 +280,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { f.StringVar(&client.Description, "description", "", "add a custom description") f.BoolVar(&client.DependencyUpdate, "dependency-update", false, "update dependencies if they are missing before installing the chart") f.BoolVar(&client.EnableDNS, "enable-dns", false, "enable DNS lookups when rendering templates") - f.BoolVar(&client.TakeOwnership, "take-ownership", false, "if set, upgrade will ignore the check for helm annotations and take ownership of the existing resources.") + f.BoolVar(&client.TakeOwnership, "take-ownership", false, "if set, upgrade will ignore the check for helm annotations and take ownership of the existing resources") addChartPathOptionsFlags(f, &client.ChartPathOptions) addValueOptionsFlags(f, valueOpts) bindOutputFlag(cmd, &outfmt) From 2541e465c402002a973682918ac8ee14bc8d7784 Mon Sep 17 00:00:00 2001 From: Mayank Shah Date: Wed, 11 Dec 2024 20:56:52 +0530 Subject: [PATCH 4/6] fix upgrade Signed-off-by: Mayank Shah --- cmd/helm/upgrade.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index 1fe793a92..75788459b 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -151,6 +151,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { instClient.Labels = client.Labels instClient.EnableDNS = client.EnableDNS instClient.HideSecret = client.HideSecret + instClient.TakeOwnership = client.TakeOwnership if isReleaseUninstalled(versions) { instClient.Replace = true From b9d58a19f1fdb58da7cb84370e60bcd29cc534f6 Mon Sep 17 00:00:00 2001 From: Mayank Shah Date: Thu, 12 Dec 2024 21:45:07 +0530 Subject: [PATCH 5/6] fix test Signed-off-by: Mayank Shah --- cmd/helm/testdata/output/upgrade-and-take-ownership.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/helm/testdata/output/upgrade-and-take-ownership.txt b/cmd/helm/testdata/output/upgrade-and-take-ownership.txt index bea42db54..59267651f 100644 --- a/cmd/helm/testdata/output/upgrade-and-take-ownership.txt +++ b/cmd/helm/testdata/output/upgrade-and-take-ownership.txt @@ -4,4 +4,5 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 3 +DESCRIPTION: Upgrade complete TEST SUITE: None From edf7b66ae92b16f84d86fb98bc1508d66be7bcfb Mon Sep 17 00:00:00 2001 From: Mayank Shah Date: Fri, 13 Dec 2024 10:25:04 +0530 Subject: [PATCH 6/6] fix test output Signed-off-by: Mayank Shah --- cmd/helm/testdata/output/install-and-take-ownership.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/helm/testdata/output/install-and-take-ownership.txt b/cmd/helm/testdata/output/install-and-take-ownership.txt index 51e626446..413329ae1 100644 --- a/cmd/helm/testdata/output/install-and-take-ownership.txt +++ b/cmd/helm/testdata/output/install-and-take-ownership.txt @@ -3,4 +3,5 @@ LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default STATUS: deployed REVISION: 1 +DESCRIPTION: Install complete TEST SUITE: None