Skip to content

Commit f12ceb2

Browse files
Runtime delete (#85)
1 parent 203aaa2 commit f12ceb2

File tree

7 files changed

+40
-22
lines changed

7 files changed

+40
-22
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.85
1+
VERSION=v0.0.86
22
OUT_DIR=dist
33
YEAR?=$(shell date +"%Y")
44

cmd/commands/runtime.go

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"fmt"
2020
"os"
21+
"strings"
2122
"sync"
2223
"time"
2324

@@ -75,6 +76,7 @@ type (
7576
Timeout time.Duration
7677
CloneOpts *git.CloneOptions
7778
KubeFactory kube.Factory
79+
SkipChecks bool
7880
}
7981

8082
RuntimeUpgradeOptions struct {
@@ -98,7 +100,7 @@ func NewRuntimeCommand() *cobra.Command {
98100

99101
cmd.AddCommand(NewRuntimeInstallCommand())
100102
cmd.AddCommand(NewRuntimeListCommand())
101-
cmd.AddCommand(NewRuntimeUninsatllCommand())
103+
cmd.AddCommand(NewRuntimeUninstallCommand())
102104
cmd.AddCommand(NewRuntimeUpgradeCommand())
103105

104106
return cmd
@@ -361,18 +363,16 @@ func checkRuntimeCollisions(ctx context.Context, runtime string, kube kube.Facto
361363
}
362364

363365
func checkExistingRuntimes(ctx context.Context, runtime string) error {
364-
runtimes, err := cfConfig.NewClient().V2().Runtime().List(ctx)
366+
_, err := cfConfig.NewClient().V2().Runtime().Get(ctx, runtime)
365367
if err != nil {
366-
return fmt.Errorf("failed to list runtimes: %w", err)
367-
}
368-
369-
for _, rt := range runtimes {
370-
if rt.Metadata.Name == runtime {
371-
return fmt.Errorf("runtime '%s' already exists", runtime)
368+
if strings.Contains(err.Error(), "does not exist") {
369+
return nil // runtime does exist
372370
}
371+
372+
return fmt.Errorf("failed to get runtime: %w", err)
373373
}
374374

375-
return nil
375+
return fmt.Errorf("runtime '%s' already exists", runtime)
376376
}
377377

378378
func intervalCheckIsRuntimePersisted(milliseconds int, ctx context.Context, runtimeName string, wg *sync.WaitGroup) error {
@@ -469,10 +469,11 @@ func RunRuntimeList(ctx context.Context) error {
469469
return tb.Flush()
470470
}
471471

472-
func NewRuntimeUninsatllCommand() *cobra.Command {
472+
func NewRuntimeUninstallCommand() *cobra.Command {
473473
var (
474-
f kube.Factory
475-
cloneOpts *git.CloneOptions
474+
skipChecks bool
475+
f kube.Factory
476+
cloneOpts *git.CloneOptions
476477
)
477478

478479
cmd := &cobra.Command{
@@ -506,10 +507,12 @@ func NewRuntimeUninsatllCommand() *cobra.Command {
506507
Timeout: store.Get().WaitTimeout,
507508
CloneOpts: cloneOpts,
508509
KubeFactory: f,
510+
SkipChecks: skipChecks,
509511
})
510512
},
511513
}
512514

515+
cmd.Flags().BoolVar(&skipChecks, "skip-checks", false, "If true, will not verify that runtime exists before uninstalling")
513516
cmd.Flags().DurationVar(&store.Get().WaitTimeout, "wait-timeout", store.Get().WaitTimeout, "How long to wait for the runtime components to be deleted")
514517

515518
cloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
@@ -521,17 +524,31 @@ func NewRuntimeUninsatllCommand() *cobra.Command {
521524
}
522525

523526
func RunRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) error {
527+
// check whether the runtime exists
528+
if !opts.SkipChecks {
529+
_, err := cfConfig.NewClient().V2().Runtime().Get(ctx, opts.RuntimeName)
530+
if err != nil {
531+
return err
532+
}
533+
}
534+
524535
log.G(ctx).Infof("uninstalling runtime '%s'", opts.RuntimeName)
525-
err := apcmd.RunRepoUninstall(ctx, &apcmd.RepoUninstallOptions{
536+
537+
if err := apcmd.RunRepoUninstall(ctx, &apcmd.RepoUninstallOptions{
526538
Namespace: opts.RuntimeName,
527539
Timeout: opts.Timeout,
528540
CloneOptions: opts.CloneOpts,
529541
KubeFactory: opts.KubeFactory,
530-
})
531-
if err != nil {
542+
}); err != nil {
532543
return fmt.Errorf("failed uninstalling runtime: %w", err)
533544
}
534545

546+
log.G(ctx).Infof("deleting runtime '%s' from the platform", opts.RuntimeName)
547+
548+
if _, err := cfConfig.NewClient().V2().Runtime().Delete(ctx, opts.RuntimeName); err != nil {
549+
return fmt.Errorf("failed to delete runtime from the platform: %w", err)
550+
}
551+
535552
log.G(ctx).Infof("done uninstalling runtime '%s'", opts.RuntimeName)
536553
return nil
537554
}

docs/commands/cli-v2_runtime_uninstall.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ cli-v2 runtime uninstall [runtime_name] [flags]
3333
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
3434
-n, --namespace string If present, the namespace scope for this CLI request
3535
--repo string Repository URL [GIT_REPO]
36+
--skip-checks If true, will not verify that runtime exists before uninstalling
3637
--wait-timeout duration How long to wait for the runtime components to be deleted (default 8m0s)
3738
```
3839

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.85/cf-linux-amd64.tar.gz | tar zx
23+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.86/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.85/cf-darwin-amd64.tar.gz | tar zx
35+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.86/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
@@ -10,7 +10,7 @@ require (
1010
github.com/argoproj/argo-events v1.4.0
1111
github.com/argoproj/argo-workflows/v3 v3.1.6
1212
github.com/briandowns/spinner v1.16.0
13-
github.com/codefresh-io/go-sdk v0.33.0
13+
github.com/codefresh-io/go-sdk v0.34.0
1414
github.com/fatih/color v1.12.0
1515
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
1616
github.com/go-git/go-billy/v5 v5.3.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
268268
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
269269
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
270270
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
271-
github.com/codefresh-io/go-sdk v0.33.0 h1:ZsiF41PKg/TdWIyXx/x+T4I9cpON3970Vyne4Mg//As=
272-
github.com/codefresh-io/go-sdk v0.33.0/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
271+
github.com/codefresh-io/go-sdk v0.34.0 h1:JvY71ZTu23F+mHrG+MiqLyUqNlvUAiVUzXjJHUFoP+I=
272+
github.com/codefresh-io/go-sdk v0.34.0/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
273273
github.com/colinmarc/hdfs v1.1.4-0.20180802165501-48eb8d6c34a9/go.mod h1:0DumPviB681UcSuJErAbDIOx6SIaJWj463TymfZG02I=
274274
github.com/colinmarc/hdfs v1.1.4-0.20180805212432-9746310a4d31/go.mod h1:vSBumefK4HA5uiRSwNP+3ofgrEoScpCS2MMWcWXEuQ4=
275275
github.com/container-storage-interface/spec v1.3.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=

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.85
8+
version: 0.0.86
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

0 commit comments

Comments
 (0)