Skip to content

Commit

Permalink
Runtime delete (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
roi-codefresh authored Aug 30, 2021
1 parent 203aaa2 commit f12ceb2
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=v0.0.85
VERSION=v0.0.86
OUT_DIR=dist
YEAR?=$(shell date +"%Y")

Expand Down
47 changes: 32 additions & 15 deletions cmd/commands/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"os"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -75,6 +76,7 @@ type (
Timeout time.Duration
CloneOpts *git.CloneOptions
KubeFactory kube.Factory
SkipChecks bool
}

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

cmd.AddCommand(NewRuntimeInstallCommand())
cmd.AddCommand(NewRuntimeListCommand())
cmd.AddCommand(NewRuntimeUninsatllCommand())
cmd.AddCommand(NewRuntimeUninstallCommand())
cmd.AddCommand(NewRuntimeUpgradeCommand())

return cmd
Expand Down Expand Up @@ -361,18 +363,16 @@ func checkRuntimeCollisions(ctx context.Context, runtime string, kube kube.Facto
}

func checkExistingRuntimes(ctx context.Context, runtime string) error {
runtimes, err := cfConfig.NewClient().V2().Runtime().List(ctx)
_, err := cfConfig.NewClient().V2().Runtime().Get(ctx, runtime)
if err != nil {
return fmt.Errorf("failed to list runtimes: %w", err)
}

for _, rt := range runtimes {
if rt.Metadata.Name == runtime {
return fmt.Errorf("runtime '%s' already exists", runtime)
if strings.Contains(err.Error(), "does not exist") {
return nil // runtime does exist
}

return fmt.Errorf("failed to get runtime: %w", err)
}

return nil
return fmt.Errorf("runtime '%s' already exists", runtime)
}

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

func NewRuntimeUninsatllCommand() *cobra.Command {
func NewRuntimeUninstallCommand() *cobra.Command {
var (
f kube.Factory
cloneOpts *git.CloneOptions
skipChecks bool
f kube.Factory
cloneOpts *git.CloneOptions
)

cmd := &cobra.Command{
Expand Down Expand Up @@ -506,10 +507,12 @@ func NewRuntimeUninsatllCommand() *cobra.Command {
Timeout: store.Get().WaitTimeout,
CloneOpts: cloneOpts,
KubeFactory: f,
SkipChecks: skipChecks,
})
},
}

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

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

func RunRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) error {
// check whether the runtime exists
if !opts.SkipChecks {
_, err := cfConfig.NewClient().V2().Runtime().Get(ctx, opts.RuntimeName)
if err != nil {
return err
}
}

log.G(ctx).Infof("uninstalling runtime '%s'", opts.RuntimeName)
err := apcmd.RunRepoUninstall(ctx, &apcmd.RepoUninstallOptions{

if err := apcmd.RunRepoUninstall(ctx, &apcmd.RepoUninstallOptions{
Namespace: opts.RuntimeName,
Timeout: opts.Timeout,
CloneOptions: opts.CloneOpts,
KubeFactory: opts.KubeFactory,
})
if err != nil {
}); err != nil {
return fmt.Errorf("failed uninstalling runtime: %w", err)
}

log.G(ctx).Infof("deleting runtime '%s' from the platform", opts.RuntimeName)

if _, err := cfConfig.NewClient().V2().Runtime().Delete(ctx, opts.RuntimeName); err != nil {
return fmt.Errorf("failed to delete runtime from the platform: %w", err)
}

log.G(ctx).Infof("done uninstalling runtime '%s'", opts.RuntimeName)
return nil
}
Expand Down
1 change: 1 addition & 0 deletions docs/commands/cli-v2_runtime_uninstall.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ cli-v2 runtime uninstall [runtime_name] [flags]
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
-n, --namespace string If present, the namespace scope for this CLI request
--repo string Repository URL [GIT_REPO]
--skip-checks If true, will not verify that runtime exists before uninstalling
--wait-timeout duration How long to wait for the runtime components to be deleted (default 8m0s)
```

Expand Down
4 changes: 2 additions & 2 deletions docs/releases/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cf version
### Linux
```bash
# download and extract the binary
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.85/cf-linux-amd64.tar.gz | tar zx
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.86/cf-linux-amd64.tar.gz | tar zx

# move the binary to your $PATH
mv ./cf-linux-amd64 /usr/local/bin/cf
Expand All @@ -32,7 +32,7 @@ cf version
### Mac
```bash
# download and extract the binary
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.85/cf-darwin-amd64.tar.gz | tar zx
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.86/cf-darwin-amd64.tar.gz | tar zx

# move the binary to your $PATH
mv ./cf-darwin-amd64 /usr/local/bin/cf
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/argoproj/argo-events v1.4.0
github.com/argoproj/argo-workflows/v3 v3.1.6
github.com/briandowns/spinner v1.16.0
github.com/codefresh-io/go-sdk v0.33.0
github.com/codefresh-io/go-sdk v0.34.0
github.com/fatih/color v1.12.0
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/go-git/go-billy/v5 v5.3.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/codefresh-io/go-sdk v0.33.0 h1:ZsiF41PKg/TdWIyXx/x+T4I9cpON3970Vyne4Mg//As=
github.com/codefresh-io/go-sdk v0.33.0/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
github.com/codefresh-io/go-sdk v0.34.0 h1:JvY71ZTu23F+mHrG+MiqLyUqNlvUAiVUzXjJHUFoP+I=
github.com/codefresh-io/go-sdk v0.34.0/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
github.com/colinmarc/hdfs v1.1.4-0.20180802165501-48eb8d6c34a9/go.mod h1:0DumPviB681UcSuJErAbDIOx6SIaJWj463TymfZG02I=
github.com/colinmarc/hdfs v1.1.4-0.20180805212432-9746310a4d31/go.mod h1:vSBumefK4HA5uiRSwNP+3ofgrEoScpCS2MMWcWXEuQ4=
github.com/container-storage-interface/spec v1.3.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=
Expand Down
2 changes: 1 addition & 1 deletion manifests/runtime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
namespace: "{{ namespace }}"
spec:
defVersion: 1.0.0
version: 0.0.85
version: 0.0.86
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
components:
- name: events
Expand Down

0 comments on commit f12ceb2

Please sign in to comment.