Skip to content

Commit 9ad6272

Browse files
CR-11767 uninstalling isc when uninstalling runtime (#424)
* isc uninstall * bump * get isc repo from`me` query * usersV2 * get current * bump go-sdk * bump * bump
1 parent 5a2275c commit 9ad6272

File tree

9 files changed

+69
-7
lines changed

9 files changed

+69
-7
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.381
1+
VERSION=v0.0.382
22

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

cmd/commands/common.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,3 +637,12 @@ func setIscRepo(ctx context.Context, suggestedSharedConfigRepo string) (string,
637637

638638
return setIscRepoResponse, nil
639639
}
640+
641+
func getIscRepo(ctx context.Context) (string, error) {
642+
user, err := cfConfig.NewClient().V2().UsersV2().GetCurrent(ctx)
643+
if err != nil {
644+
return "", fmt.Errorf("failed to get shared config repo. Error: %w", err)
645+
}
646+
647+
return *user.ActiveAccount.SharedConfigRepo, nil
648+
}

cmd/commands/runtime.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ type (
113113
RuntimeName string
114114
Timeout time.Duration
115115
CloneOpts *git.CloneOptions
116+
IscCloneOpts *git.CloneOptions
116117
KubeFactory kube.Factory
117118
SkipChecks bool
118119
Force bool
@@ -455,6 +456,12 @@ func runtimeUninstallCommandPreRunHandler(cmd *cobra.Command, args []string, opt
455456
return err
456457
}
457458

459+
opts.IscCloneOpts.Repo, err = getIscRepo(cmd.Context())
460+
handleCliStep(reporter.UninstallStepPreCheckGetIscRepo, "Getting internal shared config repo", err, true, false)
461+
if err != nil {
462+
return err
463+
}
464+
458465
return nil
459466
}
460467

@@ -1509,6 +1516,11 @@ func NewRuntimeUninstallCommand() *cobra.Command {
15091516

15101517
createAnalyticsReporter(ctx, reporter.UninstallFlow, opts.DisableTelemetry)
15111518

1519+
opts.IscCloneOpts = &git.CloneOptions{
1520+
FS: fs.Create(memfs.New()),
1521+
CreateIfNotExist: false,
1522+
}
1523+
15121524
err := runtimeUninstallCommandPreRunHandler(cmd, args, &opts)
15131525
handleCliStep(reporter.UninstallPhasePreCheckFinish, "Finished pre run checks", err, true, false)
15141526
if err != nil {
@@ -1532,7 +1544,12 @@ func NewRuntimeUninstallCommand() *cobra.Command {
15321544
}
15331545

15341546
opts.Timeout = store.Get().WaitTimeout
1547+
1548+
inferProviderFromRepo(opts.IscCloneOpts)
1549+
opts.IscCloneOpts.Auth = opts.CloneOpts.Auth
1550+
opts.IscCloneOpts.Progress = opts.CloneOpts.Progress
15351551
opts.CloneOpts.Parse()
1552+
opts.IscCloneOpts.Parse()
15361553
return nil
15371554
},
15381555
RunE: func(cmd *cobra.Command, _ []string) error {
@@ -1607,6 +1624,12 @@ func RunRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err
16071624
return err
16081625
}
16091626

1627+
err = removeRuntimeIsc(ctx, opts)
1628+
handleCliStep(reporter.UninstallStepRemoveRuntimeIsc, "Removing runtime ISC", err, false, true)
1629+
if err != nil {
1630+
return fmt.Errorf("failed to remove runtime isc: %w", err)
1631+
}
1632+
16101633
err = deleteRuntimeFromPlatform(ctx, opts)
16111634
handleCliStep(reporter.UninstallStepDeleteRuntimeFromPlatform, "Deleting runtime from platform", err, false, true)
16121635
if err != nil {
@@ -1732,6 +1755,32 @@ func getApplicationChecklistState(name string, a *argocdv1alpha1.Application, ru
17321755
return state, []string{name, status}
17331756
}
17341757

1758+
func removeRuntimeIsc(ctx context.Context, opts *RuntimeUninstallOptions) error {
1759+
if opts.IscCloneOpts.Repo == "" {
1760+
return nil
1761+
}
1762+
1763+
log.G(ctx).Info("removing runtime isc")
1764+
1765+
r, fs, err := opts.IscCloneOpts.GetRepo(ctx)
1766+
if err != nil {
1767+
return fmt.Errorf("failed to clone isc repo. error: %w", err)
1768+
}
1769+
1770+
err = billyUtils.RemoveAll(fs, fs.Join(store.Get().IscRuntimesDir, opts.RuntimeName))
1771+
if err != nil {
1772+
return fmt.Errorf("failed to remove runtime dir '%s' from shared config repo. error: %w", opts.RuntimeName, err)
1773+
}
1774+
1775+
pushMsg := fmt.Sprintf("Removing runtime dir '%s'", opts.RuntimeName)
1776+
err = apu.PushWithMessage(ctx, r, pushMsg)
1777+
if err != nil {
1778+
return fmt.Errorf("failed to push to git while removing runtime '%s' dir: %w", opts.RuntimeName, err)
1779+
}
1780+
1781+
return nil
1782+
}
1783+
17351784
func deleteRuntimeFromPlatform(ctx context.Context, opts *RuntimeUninstallOptions) error {
17361785
log.G(ctx).Infof("Deleting runtime \"%s\" from the platform", opts.RuntimeName)
17371786
_, err := cfConfig.NewClient().V2().Runtime().Delete(ctx, opts.RuntimeName)

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cf version
2323

2424
```bash
2525
# download and extract the binary
26-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.381/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.382/cf-linux-amd64.tar.gz | tar zx
2727

2828
# move the binary to your $PATH
2929
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -36,7 +36,7 @@ cf version
3636

3737
```bash
3838
# download and extract the binary
39-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.381/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.382/cf-darwin-amd64.tar.gz | tar zx
4040

4141
# move the binary to your $PATH
4242
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 v0.17.1-0.20220327045437-70eaafe9afec
1111
github.com/argoproj/argo-workflows/v3 v3.3.1
1212
github.com/briandowns/spinner v1.18.1
13-
github.com/codefresh-io/go-sdk v0.43.10
13+
github.com/codefresh-io/go-sdk v0.43.11
1414
github.com/fatih/color v1.13.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
@@ -254,8 +254,8 @@ github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h
254254
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
255255
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
256256
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
257-
github.com/codefresh-io/go-sdk v0.43.10 h1:SJbc1kOrgvesllkdMZsMFYWOmrFMIyi0d10jslIOIus=
258-
github.com/codefresh-io/go-sdk v0.43.10/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
257+
github.com/codefresh-io/go-sdk v0.43.11 h1:2TMUHE68ZTJS2qWOC7a8+1pdOfH8+b+2g749deMiKX0=
258+
github.com/codefresh-io/go-sdk v0.43.11/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
259259
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
260260
github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE=
261261
github.com/container-storage-interface/spec v1.5.0/go.mod h1:8K96oQNkJ7pFcC2R9Z1ynGGBB1I93kcS6PGg3SsOk8s=

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

pkg/reporter/reporter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ const (
102102
UninstallStepPreCheckRuntimeNameValidation CliStep = "uninstall.pre-check.step.runtime-name-validation"
103103
UninstallStepPreCheckEnsureRuntimeRepo CliStep = "uninstall.pre-check.step.ensure-runtime-repo"
104104
UninstallStepPreCheckEnsureGitToken CliStep = "uninstall.pre-check.step.ensure-git-token"
105+
UninstallStepPreCheckGetIscRepo CliStep = "uninstall.pre-check.step.get-isc-repo"
105106
UninstallPhasePreCheckFinish CliStep = "uninstall.pre-check.phase.finish"
106107
UninstallPhaseStart CliStep = "uninstall.run.phase.start"
107108
UninstallStepCheckRuntimeExists CliStep = "uninstall.run.step.check-runtime-exists"
108109
UninstallStepUninstallRepo CliStep = "uninstall.run.step.uninstall-repo"
109110
UninstallStepRemoveGitIntegrations CliStep = "uninstall.run.step.remove-git-integrations"
111+
UninstallStepRemoveRuntimeIsc CliStep = "uninstall.run.step.remove-runtime-isc"
110112
UninstallStepDeleteRuntimeFromPlatform CliStep = "uninstall.run.step.delete-runtime-from-platform"
111113
UninstallPhaseFinish CliStep = "uninstall.run.phase.finish"
112114

pkg/store/store.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ type Store struct {
144144
InstallationFlow string
145145
GsCreateFlow string
146146
InCluster string
147+
IscRuntimesDir string
147148
}
148149

149150
// Get returns the global store
@@ -243,6 +244,7 @@ func init() {
243244
s.InstallationFlow = "install-runtime"
244245
s.GsCreateFlow = "git-source-create"
245246
s.InCluster = "https://kubernetes.default.svc"
247+
s.IscRuntimesDir = "runtimes"
246248

247249
initVersion()
248250
}

0 commit comments

Comments
 (0)