Skip to content

Commit f48d149

Browse files
authored
Cr 9843 add rollouts (#353)
* updated go-sdk to 0.42.0 * updated autopilot to 0.3.5 * updated app-proxy to 1.1075.0 * use platform for `cluster list` * updated version to 0.0.321
1 parent d53d8e2 commit f48d149

File tree

9 files changed

+224
-78
lines changed

9 files changed

+224
-78
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Changelog:
22

3-
* Protect against invalid kube context
3+
* Added `cluster create-argo-rollouts` command

Makefile

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

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

cmd/commands/cluster.go

Lines changed: 117 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ import (
1818
"context"
1919
"fmt"
2020
"os"
21+
"sort"
2122
"strings"
2223

2324
"github.com/codefresh-io/cli-v2/pkg/log"
2425
"github.com/codefresh-io/cli-v2/pkg/store"
2526
"github.com/codefresh-io/cli-v2/pkg/util"
26-
cdutil "github.com/codefresh-io/cli-v2/pkg/util/cd"
2727
kustutil "github.com/codefresh-io/cli-v2/pkg/util/kust"
2828

2929
"github.com/Masterminds/semver/v3"
@@ -43,8 +43,14 @@ type (
4343
}
4444

4545
ClusterRemoveOptions struct {
46+
runtimeName string
4647
server string
48+
}
49+
50+
ClusterCreateArgoRolloutsOptions struct {
4751
runtimeName string
52+
server string
53+
namespace string
4854
}
4955
)
5056

@@ -63,21 +69,19 @@ func NewClusterCommand() *cobra.Command {
6369
},
6470
}
6571

66-
cmd.AddCommand(NewClusterAddCommand())
67-
cmd.AddCommand(NewClusterRemoveCommand())
68-
cmd.AddCommand(NewClusterListCommand())
72+
cmd.AddCommand(newClusterAddCommand())
73+
cmd.AddCommand(newClusterRemoveCommand())
74+
cmd.AddCommand(newClusterListCommand())
75+
cmd.AddCommand(newClusterCreateArgoRolloutsCommand())
6976

7077
return cmd
7178
}
7279

73-
func NewClusterAddCommand() *cobra.Command {
74-
var (
75-
opts ClusterAddOptions
76-
err error
77-
)
80+
func newClusterAddCommand() *cobra.Command {
81+
var opts ClusterAddOptions
7882

7983
cmd := &cobra.Command{
80-
Use: "add RUNTIME_NAME",
84+
Use: "add [RUNTIME_NAME]",
8185
Short: "Add a cluster to a given runtime",
8286
Args: cobra.MaximumNArgs(1),
8387
Example: util.Doc(`<BIN> cluster add my-runtime --context my-context`),
@@ -101,7 +105,6 @@ func NewClusterAddCommand() *cobra.Command {
101105

102106
cmd.Flags().BoolVar(&opts.dryRun, "dry-run", false, "")
103107
opts.kubeFactory = kube.AddFlags(cmd.Flags())
104-
die(err)
105108

106109
return cmd
107110
}
@@ -193,16 +196,14 @@ func createAddClusterKustomization(ingressUrl, contextName, server, csdpToken, v
193196
return k
194197
}
195198

196-
func NewClusterRemoveCommand() *cobra.Command {
197-
var (
198-
opts ClusterRemoveOptions
199-
)
199+
func newClusterRemoveCommand() *cobra.Command {
200+
var opts ClusterRemoveOptions
200201

201202
cmd := &cobra.Command{
202-
Use: "remove RUNTIME_NAME",
203+
Use: "remove [RUNTIME_NAME]",
203204
Short: "Removes a cluster from a given runtime",
204205
Args: cobra.MaximumNArgs(1),
205-
Example: util.Doc(`<BIN> cluster remove my-runtime --server-url my-server-url`),
206+
Example: util.Doc(`<BIN> cluster remove my-runtime --server-url https://<some-hash>.gr7.us-east-1.eks.amazonaws.com`),
206207
PreRunE: func(cmd *cobra.Command, args []string) error {
207208
var err error
208209

@@ -232,7 +233,7 @@ func runClusterRemove(ctx context.Context, opts *ClusterRemoveOptions) error {
232233
return err
233234
}
234235

235-
err = appProxy.AppProxyClusters().RemoveCluster(ctx, opts.server, opts.runtimeName)
236+
err = appProxy.AppProxyClusters().Delete(ctx, opts.server, opts.runtimeName)
236237
if err != nil {
237238
return fmt.Errorf("failed to remove cluster: %w", err)
238239
}
@@ -242,70 +243,94 @@ func runClusterRemove(ctx context.Context, opts *ClusterRemoveOptions) error {
242243
return nil
243244
}
244245

245-
func NewClusterListCommand() *cobra.Command {
246-
var runtimeName string
247-
var kubeconfig string
246+
func newClusterListCommand() *cobra.Command {
247+
runtimeName := ""
248248

249249
cmd := &cobra.Command{
250-
Use: "list RUNTIME_NAME",
250+
Use: "list [RUNTIME_NAME]",
251251
Short: "List all the clusters of a given runtime",
252252
Args: cobra.MaximumNArgs(1),
253253
Example: util.Doc(`<BIN> cluster list my-runtime`),
254-
PreRunE: func(cmd *cobra.Command, args []string) error {
255-
var err error
256-
257-
runtimeName, err = ensureRuntimeName(cmd.Context(), args)
258-
return err
254+
PreRun: func(_ *cobra.Command, args []string) {
255+
if len(args) == 1 {
256+
runtimeName = args[0]
257+
}
259258
},
260-
RunE: func(cmd *cobra.Command, _ []string) error {
261-
return runClusterList(cmd.Context(), runtimeName, kubeconfig)
259+
RunE: func(cmd *cobra.Command, args []string) error {
260+
return runClusterList(cmd.Context(), runtimeName)
262261
},
263262
}
264263

265-
cmd.Flags().StringVar(&kubeconfig, "kubeconfig", "", "Path to the kubeconfig file")
266-
267264
return cmd
268265
}
269266

270-
func runClusterList(ctx context.Context, runtimeName, kubeconfig string) error {
271-
runtime, err := cfConfig.NewClient().V2().Runtime().Get(ctx, runtimeName)
272-
if err != nil {
273-
return err
274-
}
275-
276-
kubeContext, err := util.KubeContextNameByServer(*runtime.Cluster, kubeconfig)
277-
if err != nil {
278-
return fmt.Errorf("failed getting context for \"%s\": %w", *runtime.Cluster, err)
279-
}
280-
281-
clusters, err := cdutil.GetClusterList(ctx, kubeContext, *runtime.Metadata.Namespace, false)
267+
func runClusterList(ctx context.Context, runtimeName string) error {
268+
clusters, err := cfConfig.NewClient().V2().Cluster().List(ctx, runtimeName)
282269
if err != nil {
283270
return err
284271
}
285272

286-
if len(clusters.Items) == 0 {
273+
if len(clusters) == 0 {
287274
log.G(ctx).Info("No clusters were found")
288275
return nil
289276
}
290277

278+
sort.SliceStable(clusters, func(i, j int) bool {
279+
c1 := clusters[i]
280+
if c1.Metadata.Name == "in-cluster" {
281+
return true
282+
}
283+
284+
c2 := clusters[j]
285+
if c2.Metadata.Name == "in-cluster" {
286+
return false
287+
}
288+
289+
return c1.Metadata.Name < c2.Metadata.Name
290+
})
291+
291292
tb := ansiterm.NewTabWriter(os.Stdout, 0, 0, 4, ' ', 0)
293+
if runtimeName == "" {
294+
_, err = fmt.Fprint(tb, "RUNTIME\t")
295+
if err != nil {
296+
return err
297+
}
298+
}
299+
292300
_, err = fmt.Fprintln(tb, "SERVER\tNAME\tVERSION\tSTATUS\tMESSAGE")
293301
if err != nil {
294302
return err
295303
}
296304

297-
for _, c := range clusters.Items {
305+
for _, c := range clusters {
298306
server := c.Server
299307
if len(c.Namespaces) > 0 {
300308
server = fmt.Sprintf("%s (%d namespaces)", c.Server, len(c.Namespaces))
301309
}
302310

311+
version := ""
312+
if c.Info.ServerVersion != nil {
313+
version = *c.Info.ServerVersion
314+
}
315+
316+
message := ""
317+
if c.Info.ConnectionState.Message != nil {
318+
message = *c.Info.ConnectionState.Message
319+
}
320+
321+
if runtimeName == "" {
322+
_, err = fmt.Fprintf(tb, "%s\t", c.Metadata.Runtime)
323+
if err != nil {
324+
return err
325+
}
326+
}
327+
303328
_, err = fmt.Fprintf(tb, "%s\t%s\t%s\t%s\t%s\n",
304329
server,
305-
c.Name,
306-
c.ServerVersion,
307-
c.ConnectionState.Status,
308-
c.ConnectionState.Message,
330+
c.Metadata.Name,
331+
version,
332+
c.Info.ConnectionState.Status,
333+
message,
309334
)
310335
if err != nil {
311336
return err
@@ -314,3 +339,46 @@ func runClusterList(ctx context.Context, runtimeName, kubeconfig string) error {
314339

315340
return tb.Flush()
316341
}
342+
343+
func newClusterCreateArgoRolloutsCommand() *cobra.Command {
344+
var opts ClusterCreateArgoRolloutsOptions
345+
346+
cmd := &cobra.Command{
347+
Use: "create-argo-rollouts [RUNTIME_NAME]",
348+
Short: "creates argo-rollouts component on the target cluster",
349+
Args: cobra.MaximumNArgs(1),
350+
Example: util.Doc(`<BIN> cluster create-argo-rollouts my-runtime --server-url https://<some-hash>.gr7.us-east-1.eks.amazonaws.com --namespace managed-ns`),
351+
PreRunE: func(cmd *cobra.Command, args []string) error {
352+
var err error
353+
354+
opts.runtimeName, err = ensureRuntimeName(cmd.Context(), args)
355+
return err
356+
},
357+
RunE: func(cmd *cobra.Command, _ []string) error {
358+
return runCreateArgoRollouts(cmd.Context(), &opts)
359+
},
360+
}
361+
362+
cmd.Flags().StringVar(&opts.server, "server-url", "", "The cluster's server url")
363+
cmd.Flags().StringVar(&opts.namespace, "namespace", "", "Path to the kubeconfig file")
364+
util.Die(cobra.MarkFlagRequired(cmd.Flags(), "server-url"))
365+
util.Die(cobra.MarkFlagRequired(cmd.Flags(), "namespace"))
366+
367+
return cmd
368+
}
369+
370+
func runCreateArgoRollouts(ctx context.Context, opts *ClusterCreateArgoRolloutsOptions) error {
371+
appProxy, err := cfConfig.NewClient().AppProxy(ctx, opts.runtimeName, store.Get().InsecureIngressHost)
372+
if err != nil {
373+
return err
374+
}
375+
376+
err = appProxy.AppProxyClusters().CreateArgoRollouts(ctx, opts.server, opts.namespace)
377+
if err != nil {
378+
return fmt.Errorf("failed to create argo-rollouts on \"%s'\": %w", opts.server, err)
379+
}
380+
381+
log.G(ctx).Infof("created argo-rollouts component on \"%s\"", opts.server)
382+
383+
return nil
384+
}

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.320/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.321/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.320/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.321/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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ go 1.18
44

55
require (
66
github.com/Masterminds/semver/v3 v3.1.1
7-
github.com/argoproj-labs/argocd-autopilot v0.3.0
7+
github.com/argoproj-labs/argocd-autopilot v0.3.5
88
github.com/argoproj/applicationset v0.4.1
9-
github.com/argoproj/argo-cd/v2 v2.3.2
9+
github.com/argoproj/argo-cd/v2 v2.3.3
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.41.1
13+
github.com/codefresh-io/go-sdk v0.42.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
@@ -32,8 +32,8 @@ require (
3232
k8s.io/api v0.23.3
3333
k8s.io/apimachinery v0.23.3
3434
k8s.io/client-go v11.0.1-0.20190816222228-6d55c1b1f1ca+incompatible
35-
sigs.k8s.io/kustomize/api v0.11.2
36-
sigs.k8s.io/kustomize/kyaml v0.13.3
35+
sigs.k8s.io/kustomize/api v0.11.4
36+
sigs.k8s.io/kustomize/kyaml v0.13.6
3737
)
3838

3939
require (
@@ -61,8 +61,8 @@ require (
6161
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
6262
github.com/alicebob/miniredis/v2 v2.14.2 // indirect
6363
github.com/antonmedv/expr v1.9.0 // indirect
64-
github.com/argoproj/gitops-engine v0.6.1 // indirect
65-
github.com/argoproj/notifications-engine v0.3.1-0.20220127183449-91deed20b998 // indirect
64+
github.com/argoproj/gitops-engine v0.6.2 // indirect
65+
github.com/argoproj/notifications-engine v0.3.1-0.20220322174744-ac18ca10234c // indirect
6666
github.com/argoproj/pkg v0.11.1-0.20211203175135-36c59d8fafe0 // indirect
6767
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
6868
github.com/beorn7/perks v1.0.1 // indirect

0 commit comments

Comments
 (0)