Skip to content

Commit 5247cdd

Browse files
CR-9845 cluster remove (#333)
* cluster remove and small bug fix * bump version * few fixes * small fix * lint fix
1 parent 641d085 commit 5247cdd

File tree

10 files changed

+71
-15
lines changed

10 files changed

+71
-15
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.297
1+
VERSION=v0.0.298
22

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

cmd/commands/cluster.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ type (
4141
dryRun bool
4242
kubeFactory kube.Factory
4343
}
44+
45+
ClusterRemoveOptions struct {
46+
server string
47+
runtimeName string
48+
}
4449
)
4550

4651
var minAddClusterSupportedVersion = semver.MustParse("0.0.283")
@@ -59,6 +64,7 @@ func NewClusterCommand() *cobra.Command {
5964
}
6065

6166
cmd.AddCommand(NewClusterAddCommand())
67+
cmd.AddCommand(NewClusterRemoveCommand())
6268
cmd.AddCommand(NewClusterListCommand())
6369

6470
return cmd
@@ -187,6 +193,55 @@ func createAddClusterKustomization(ingressUrl, contextName, server, csdpToken, v
187193
return k
188194
}
189195

196+
func NewClusterRemoveCommand() *cobra.Command {
197+
var (
198+
opts ClusterRemoveOptions
199+
)
200+
201+
cmd := &cobra.Command{
202+
Use: "remove RUNTIME_NAME",
203+
Short: "Removes a cluster from a given runtime",
204+
Args: cobra.MaximumNArgs(1),
205+
Example: util.Doc(`<BIN> cluster remove my-runtime --server-url my-server-url`),
206+
PreRunE: func(cmd *cobra.Command, args []string) error {
207+
var err error
208+
209+
ctx := cmd.Context()
210+
211+
opts.runtimeName, err = ensureRuntimeName(ctx, args)
212+
if err != nil {
213+
return err
214+
}
215+
216+
return nil
217+
},
218+
RunE: func(cmd *cobra.Command, args []string) error {
219+
return runClusterRemove(cmd.Context(), &opts)
220+
},
221+
}
222+
223+
cmd.Flags().StringVar(&opts.server, "server-url", "", "The cluster's server url")
224+
util.Die(cobra.MarkFlagRequired(cmd.Flags(), "server-url"))
225+
226+
return cmd
227+
}
228+
229+
func runClusterRemove(ctx context.Context, opts *ClusterRemoveOptions) error {
230+
appProxy, err := cfConfig.NewClient().AppProxy(ctx, opts.runtimeName, store.Get().InsecureIngressHost)
231+
if err != nil {
232+
return err
233+
}
234+
235+
err = appProxy.AppProxyClusters().RemoveCluster(ctx, opts.server, opts.runtimeName)
236+
if err != nil {
237+
return fmt.Errorf("failed to remove cluster: %w", err)
238+
}
239+
240+
log.G(ctx).Info("cluster was removed successfully")
241+
242+
return nil
243+
}
244+
190245
func NewClusterListCommand() *cobra.Command {
191246
var runtimeName string
192247
var kubeconfig string

cmd/commands/integrations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func RunGitIntegrationListCommand(ctx context.Context, client sdk.AppProxyAPI, f
134134
intg.Name,
135135
intg.Provider,
136136
intg.APIURL,
137-
len(intg.RegisteredUsers),
137+
len(intg.Users),
138138
intg.SharingPolicy.String(),
139139
)
140140
if err != nil {

cmd/commands/runtime.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -605,11 +605,11 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
605605

606606
componentNames := getComponents(rt, opts)
607607

608-
shouldRollback := opts.DisableRollback
608+
disableRollback := opts.DisableRollback
609609

610610
defer func() {
611611
// will rollback if err is not nil and it is safe to do so
612-
postInstallationHandler(ctx, opts, err, shouldRollback)
612+
postInstallationHandler(ctx, opts, err, &disableRollback)
613613
}()
614614

615615
token, iv, err := createRuntimeOnPlatform(ctx, &model.RuntimeInstallationArgs{
@@ -698,7 +698,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
698698

699699
// if we got to this point the runtime was installed successfully
700700
// thus we shall not perform a rollback after this point.
701-
shouldRollback = false
701+
disableRollback = true
702702

703703
if store.Get().SkipIngress {
704704
handleCliStep(reporter.InstallStepCreateDefaultGitIntegration, "-skipped-", err, false, true)
@@ -2245,8 +2245,8 @@ func inferAPIURLForGitProvider(provider apmodel.GitProviders) (string, error) {
22452245
return "", fmt.Errorf("cannot infer api-url for git provider %s, %s", provider, suggest)
22462246
}
22472247

2248-
func postInstallationHandler(ctx context.Context, opts *RuntimeInstallOptions, err error, shouldRollback bool) {
2249-
if err != nil && shouldRollback {
2248+
func postInstallationHandler(ctx context.Context, opts *RuntimeInstallOptions, err error, disableRollback *bool) {
2249+
if err != nil && !*disableRollback {
22502250
summaryArr = append(summaryArr, summaryLog{"----------Uninstalling runtime----------", Info})
22512251
log.G(ctx).Warnf("installation failed due to error : %s, performing installation rollback", err.Error())
22522252
err := RunRuntimeUninstall(ctx, &RuntimeUninstallOptions{

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.297/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.298/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.297/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.298/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.37.8
13+
github.com/codefresh-io/go-sdk v0.38.0
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
@@ -241,8 +241,8 @@ github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h
241241
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
242242
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
243243
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
244-
github.com/codefresh-io/go-sdk v0.37.8 h1:Y5hH0c2tL7UPGPB6c1+tk5A1YXweexNHWFS2iRQQBwU=
245-
github.com/codefresh-io/go-sdk v0.37.8/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
244+
github.com/codefresh-io/go-sdk v0.38.0 h1:nigzhGKPezfoVhkQrgD1c6KSFzEo0O26VAi/+B82eU8=
245+
github.com/codefresh-io/go-sdk v0.38.0/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
246246
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
247247
github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE=
248248
github.com/container-storage-interface/spec v1.5.0/go.mod h1:8K96oQNkJ7pFcC2R9Z1ynGGBB1I93kcS6PGg3SsOk8s=

manifests/app-proxy/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Kustomization
33
images:
44
- name: quay.io/codefresh/cap-app-proxy
55
newName: quay.io/codefresh/cap-app-proxy
6-
newTag: 1.951.0
6+
newTag: 1.971.0
77
resources:
88
- app-proxy.deploy.yaml
99
- app-proxy.svc.yaml

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

pkg/util/util.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"bytes"
1919
"context"
2020
"fmt"
21-
"github.com/pkg/browser"
2221
"net/url"
2322
"os"
2423
"os/signal"
@@ -28,6 +27,8 @@ import (
2827
"sync"
2928
"time"
3029

30+
"github.com/pkg/browser"
31+
3132
"github.com/briandowns/spinner"
3233
"github.com/codefresh-io/cli-v2/pkg/log"
3334
"github.com/codefresh-io/cli-v2/pkg/reporter"

0 commit comments

Comments
 (0)