Skip to content

Commit ead5776

Browse files
CR-6132-uninstall-force-flag (#125)
* force flag * tested for unrecognized crd * local mod * making sure doesnt throw error with force flag * removed redundnat * tidy * less dangerous error logs * log suggestion in pre installation checks * before updated autopilot * missing codegen * no local ap * bump * tidy - before merging ap * codegen * bin name * with codegen * log with bin name
1 parent aebc44c commit ead5776

File tree

7 files changed

+39
-14
lines changed

7 files changed

+39
-14
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.119
1+
VERSION=v0.0.120
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/runtime.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ type (
7979
CloneOpts *git.CloneOptions
8080
KubeFactory kube.Factory
8181
SkipChecks bool
82+
Force bool
83+
FastExit bool
8284
}
8385

8486
RuntimeUpgradeOptions struct {
@@ -264,7 +266,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
264266
RuntimeVersion: runtimeVersion,
265267
IngressHost: &opts.IngressHost,
266268
ComponentNames: componentNames,
267-
Repo: &opts.InsCloneOpts.Repo,
269+
Repo: &opts.InsCloneOpts.Repo,
268270
})
269271
if err != nil {
270272
return fmt.Errorf("failed to create a new runtime: %w", err)
@@ -431,7 +433,7 @@ func checkRuntimeCollisions(ctx context.Context, runtime string, kube kube.Facto
431433
return fmt.Errorf("failed to get deployment '%s': %w", store.Get().ArgoCDServerName, err)
432434
}
433435

434-
return fmt.Errorf("argo-cd is already installed on this cluster in namespace '%s', you need to uninstall it first", subjNamespace)
436+
return fmt.Errorf("argo-cd is already installed on this cluster in namespace '%s', you can uninstall it by running '%s runtime uninstall %s --skip-checks --force'", subjNamespace, store.Get().BinaryName, subjNamespace)
435437
}
436438

437439
func checkExistingRuntimes(ctx context.Context, runtime string) error {
@@ -558,6 +560,8 @@ func NewRuntimeUninstallCommand() *cobra.Command {
558560
skipChecks bool
559561
f kube.Factory
560562
cloneOpts *git.CloneOptions
563+
force bool
564+
fastExit bool
561565
)
562566

563567
cmd := &cobra.Command{
@@ -597,12 +601,16 @@ func NewRuntimeUninstallCommand() *cobra.Command {
597601
CloneOpts: cloneOpts,
598602
KubeFactory: f,
599603
SkipChecks: skipChecks,
604+
Force: force,
605+
FastExit: fastExit,
600606
})
601607
},
602608
}
603609

604610
cmd.Flags().BoolVar(&skipChecks, "skip-checks", false, "If true, will not verify that runtime exists before uninstalling")
605611
cmd.Flags().DurationVar(&store.Get().WaitTimeout, "wait-timeout", store.Get().WaitTimeout, "How long to wait for the runtime components to be deleted")
612+
cmd.Flags().BoolVar(&force, "force", false, "If true, will guarantee the runtime is removed from the platform, even in case of errors while cleaning the repo and the cluster")
613+
cmd.Flags().BoolVar(&fastExit, "fast-exit", false, "If true, will not wait for deletion of cluster resources. This means that full resource deletion will not be verified")
606614

607615
cloneOpts = apu.AddCloneFlags(cmd, &apu.CloneFlagsOptions{})
608616
f = kube.AddFlags(cmd.Flags())
@@ -627,17 +635,32 @@ func RunRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err
627635
Timeout: opts.Timeout,
628636
CloneOptions: opts.CloneOpts,
629637
KubeFactory: opts.KubeFactory,
638+
Force: opts.Force,
639+
FastExit: opts.FastExit,
630640
}); err != nil {
631-
return fmt.Errorf("failed uninstalling runtime: %w", err)
641+
if !opts.Force {
642+
log.G(ctx).Warn("you can attempt to uninstall again with the \"--force\" flag")
643+
return err
644+
}
632645
}
633646

634-
log.G(ctx).Infof("Deleting runtime '%s' from the platform", opts.RuntimeName)
635-
636-
if _, err := cfConfig.NewClient().V2().Runtime().Delete(ctx, opts.RuntimeName); err != nil {
647+
err := deleteRuntimeFromPlatform(ctx, opts)
648+
if err != nil {
637649
return fmt.Errorf("failed to delete runtime from the platform: %w", err)
638650
}
639-
640651
log.G(ctx).Infof("Done uninstalling runtime '%s'", opts.RuntimeName)
652+
653+
return nil
654+
}
655+
656+
func deleteRuntimeFromPlatform(ctx context.Context, opts *RuntimeUninstallOptions) error {
657+
log.G(ctx).Infof("Deleting runtime '%s' from the platform", opts.RuntimeName)
658+
_, err := cfConfig.NewClient().V2().Runtime().Delete(ctx, opts.RuntimeName)
659+
if err != nil {
660+
return err
661+
}
662+
663+
log.G(ctx).Infof("Successfully deleted runtime '%s' from the platform", opts.RuntimeName)
641664
return nil
642665
}
643666

docs/commands/cli-v2_runtime_uninstall.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ cli-v2 runtime uninstall [runtime_name] [flags]
2828
### Options
2929

3030
```
31+
--fast-exit If true, will not wait for deletion of cluster resources. This means that full resource deletion will not be verified
32+
--force If true, will guarantee the runtime is removed from the platform, even in case of errors while cleaning the repo and the cluster
3133
-t, --git-token string Your git provider api token [GIT_TOKEN]
3234
-u, --git-user string Your git provider user name [GIT_USER] (not required in GitHub)
3335
-h, --help help for uninstall

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ cf version
2020
### Linux
2121
```bash
2222
# download and extract the binary
23-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.119/cf-linux-amd64.tar.gz | tar zx
23+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.120/cf-linux-amd64.tar.gz | tar zx
2424

2525
# move the binary to your $PATH
2626
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -32,7 +32,7 @@ cf version
3232
### Mac
3333
```bash
3434
# download and extract the binary
35-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.119/cf-darwin-amd64.tar.gz | tar zx
35+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.120/cf-darwin-amd64.tar.gz | tar zx
3636

3737
# move the binary to your $PATH
3838
mv ./cf-darwin-amd64 /usr/local/bin/cf

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.16
55
require (
66
github.com/Masterminds/semver/v3 v3.1.1
77
github.com/argoproj-labs/applicationset v0.2.0
8-
github.com/argoproj-labs/argocd-autopilot v0.2.21
8+
github.com/argoproj-labs/argocd-autopilot v0.2.22
99
github.com/argoproj/argo-cd/v2 v2.1.2
1010
github.com/argoproj/argo-events v1.4.0
1111
github.com/argoproj/argo-workflows/v3 v3.1.6

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ github.com/ardielle/ardielle-go v1.5.2/go.mod h1:I4hy1n795cUhaVt/ojz83SNVCYIGsAF
172172
github.com/ardielle/ardielle-tools v1.5.4/go.mod h1:oZN+JRMnqGiIhrzkRN9l26Cej9dEx4jeNG6A+AdkShk=
173173
github.com/argoproj-labs/applicationset v0.2.0 h1:yq3u88VtH9bXAl8DkIzBi0Q5FCe/ExZHlnGHDxxsyY4=
174174
github.com/argoproj-labs/applicationset v0.2.0/go.mod h1:vElTdgajynEAIRuQMqQwYWSWTbdgrQPW6zDsxNPs+NE=
175-
github.com/argoproj-labs/argocd-autopilot v0.2.21 h1:zMYftMCDZnmRtNmOvjUQCL2Hyfehn9KnWwB31ZoHIko=
176-
github.com/argoproj-labs/argocd-autopilot v0.2.21/go.mod h1:YKl9+scJtfTi4418Z4AbQrCL5FXvMByDuDNLyV4axa0=
175+
github.com/argoproj-labs/argocd-autopilot v0.2.22 h1:lStk1nwElB1T8YaCZm42QGmsR5eIbcGTdAzxeMzhfew=
176+
github.com/argoproj-labs/argocd-autopilot v0.2.22/go.mod h1:YKl9+scJtfTi4418Z4AbQrCL5FXvMByDuDNLyV4axa0=
177177
github.com/argoproj/argo-cd/v2 v2.1.0-rc2/go.mod h1:a21F1IEszRrCLvXXYc1sML3mjlMN3pp6rpDxy+7E0os=
178178
github.com/argoproj/argo-cd/v2 v2.1.0/go.mod h1:/e8fSyHanaAHLR5YsIIWfCGujTN452K6L7DaYep5KRU=
179179
github.com/argoproj/argo-cd/v2 v2.1.2 h1:Ls+nJQJ7HWHeg9AKtFeeUCQTsSFvzDpbZq+ALxHL680=

manifests/runtime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: "{{ namespace }}"
66
spec:
77
defVersion: 1.0.0
8-
version: 0.0.119
8+
version: 0.0.120
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

0 commit comments

Comments
 (0)