From 5de120e294910842d8736ab2d56c3f4649567330 Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Sun, 5 Mar 2023 21:10:45 +0200 Subject: [PATCH 1/6] export rollout status in the end --- VERSION | 2 +- cmd/rollout/rollout.go | 5 +++++ pkg/builder/builder.go | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 3eefcb9..7dea76e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0 +1.0.1 diff --git a/cmd/rollout/rollout.go b/cmd/rollout/rollout.go index 538f383..3071c47 100644 --- a/cmd/rollout/rollout.go +++ b/cmd/rollout/rollout.go @@ -38,6 +38,10 @@ var Cmd = &cobra.Command{ b.ExportExternalUrl(context.PluginArgoCredentials.Host, name) b.Rollout(rolloutArgs, name, context.PluginArgoCredentials.Token, context.PluginArgoCredentials.Host, context.PluginCodefreshCredentials.Integration, rolloutArgs.SkipWaitRollout) + if rolloutArgs.ExportRolloutStatus { + b.ExportRolloutStatus(rolloutArgs) + } + resultCommands := strings.Join(b.GetLines()[:], "\n") resultExportCommands := strings.Join(b.GetExportLines()[:], "\n") @@ -97,6 +101,7 @@ func init() { f.StringVar(&rolloutArgs.WaitAdditionalFlags, "wait-additional-flags", "", "Specify additional flags for wait command, like --timeout , so on") f.BoolVar(&rolloutArgs.Debug, "debug", false, "Debug argocd command ( print commands to output )") f.BoolVar(&rolloutArgs.SkipWaitRollout, "skip", false, "Skip wait rollout") + f.BoolVar(&rolloutArgs.ExportRolloutStatus, "export-rollout-status", false, "Export rollout status") _ = cobra.MarkFlagRequired(f, "k8s-context") _ = cobra.MarkFlagRequired(f, "rollout-name") diff --git a/pkg/builder/builder.go b/pkg/builder/builder.go index e9dd9b8..96d7828 100644 --- a/pkg/builder/builder.go +++ b/pkg/builder/builder.go @@ -26,6 +26,7 @@ type RolloutArgs struct { WaitAdditionalFlags string Debug bool SkipWaitRollout bool + ExportRolloutStatus bool } type Builder interface { @@ -34,6 +35,7 @@ type Builder interface { ExportExternalUrl(host string, name string) ExportCustomExternalUrl(url string) Rollout(args *RolloutArgs, name string, authToken string, host string, context string, skip bool) + ExportRolloutStatus(args *RolloutArgs) GetLines() []string GetExportLines() []string @@ -148,6 +150,10 @@ func (b *builder) ExportCustomExternalUrl(url string) { b.exportLines = append(b.exportLines, command) } +func (b *builder) ExportRolloutStatus(args *RolloutArgs) { + b.exportLines = append(b.lines, fmt.Sprintf("kubectl argo rollouts status \"%s\" -n \"%s\" | { read status; echo runArgoCd_CF_OUTPUT_URL=$status; }", args.RolloutName, args.RolloutNamespace)) +} + func getHostDomain(host string) (*string, error) { u, err := url.Parse(host) if err != nil { From 10224e99c88c9cc1bf9e3b0f50a25f72b2548993 Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Sun, 5 Mar 2023 21:51:46 +0200 Subject: [PATCH 2/6] export env --- pkg/builder/builder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/builder/builder.go b/pkg/builder/builder.go index 96d7828..3e3af55 100644 --- a/pkg/builder/builder.go +++ b/pkg/builder/builder.go @@ -151,7 +151,7 @@ func (b *builder) ExportCustomExternalUrl(url string) { } func (b *builder) ExportRolloutStatus(args *RolloutArgs) { - b.exportLines = append(b.lines, fmt.Sprintf("kubectl argo rollouts status \"%s\" -n \"%s\" | { read status; echo runArgoCd_CF_OUTPUT_URL=$status; }", args.RolloutName, args.RolloutNamespace)) + b.exportLines = append(b.lines, fmt.Sprintf("kubectl argo rollouts status \"%s\" -n \"%s\" | { read status; echo rollout_status=$status; }", args.RolloutName, args.RolloutNamespace)) } func getHostDomain(host string) (*string, error) { From a893f4c47838221f46436eb22a78cb5217e082e9 Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Sun, 5 Mar 2023 22:21:13 +0200 Subject: [PATCH 3/6] do export --- pkg/builder/builder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/builder/builder.go b/pkg/builder/builder.go index 3e3af55..63b1bea 100644 --- a/pkg/builder/builder.go +++ b/pkg/builder/builder.go @@ -151,7 +151,7 @@ func (b *builder) ExportCustomExternalUrl(url string) { } func (b *builder) ExportRolloutStatus(args *RolloutArgs) { - b.exportLines = append(b.lines, fmt.Sprintf("kubectl argo rollouts status \"%s\" -n \"%s\" | { read status; echo rollout_status=$status; }", args.RolloutName, args.RolloutNamespace)) + b.exportLines = append(b.lines, fmt.Sprintf("kubectl argo rollouts status \"%s\" -n \"%s\" | { read status; cf_export rollout_status=$status; }", args.RolloutName, args.RolloutNamespace)) } func getHostDomain(host string) (*string, error) { From 81dca6f1d923da635c87de35891631bfade4f03b Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Sun, 5 Mar 2023 22:27:13 +0200 Subject: [PATCH 4/6] do export --- pkg/builder/builder.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/builder/builder.go b/pkg/builder/builder.go index 63b1bea..6ae001d 100644 --- a/pkg/builder/builder.go +++ b/pkg/builder/builder.go @@ -151,7 +151,8 @@ func (b *builder) ExportCustomExternalUrl(url string) { } func (b *builder) ExportRolloutStatus(args *RolloutArgs) { - b.exportLines = append(b.lines, fmt.Sprintf("kubectl argo rollouts status \"%s\" -n \"%s\" | { read status; cf_export rollout_status=$status; }", args.RolloutName, args.RolloutNamespace)) + b.lines = append(b.lines, fmt.Sprintf("kubectl argo rollouts status \"%s\" -n \"%s\" | { read status; cf_export rollout_status=$status; }", args.RolloutName, args.RolloutNamespace)) + b.exportLines = append(b.exportLines, fmt.Sprintf("kubectl argo rollouts status \"%s\" -n \"%s\" | { read status; cf_export rollout_status=$status; }", args.RolloutName, args.RolloutNamespace)) } func getHostDomain(host string) (*string, error) { From b681819b6db7b1c4c0fd6b563b132d169e160c9b Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Sun, 5 Mar 2023 22:40:54 +0200 Subject: [PATCH 5/6] do export --- pkg/builder/builder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/builder/builder.go b/pkg/builder/builder.go index 6ae001d..8e66c83 100644 --- a/pkg/builder/builder.go +++ b/pkg/builder/builder.go @@ -151,7 +151,7 @@ func (b *builder) ExportCustomExternalUrl(url string) { } func (b *builder) ExportRolloutStatus(args *RolloutArgs) { - b.lines = append(b.lines, fmt.Sprintf("kubectl argo rollouts status \"%s\" -n \"%s\" | { read status; cf_export rollout_status=$status; }", args.RolloutName, args.RolloutNamespace)) + b.lines = append(b.lines, fmt.Sprintf("kubectl config use-context \"%s\"", args.KubernetesContext)) b.exportLines = append(b.exportLines, fmt.Sprintf("kubectl argo rollouts status \"%s\" -n \"%s\" | { read status; cf_export rollout_status=$status; }", args.RolloutName, args.RolloutNamespace)) } From d8cea02c872b441187f2ea1c380774658c12e1b7 Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Sun, 5 Mar 2023 22:50:10 +0200 Subject: [PATCH 6/6] do export --- pkg/builder/builder.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/builder/builder.go b/pkg/builder/builder.go index 8e66c83..2e76aca 100644 --- a/pkg/builder/builder.go +++ b/pkg/builder/builder.go @@ -151,8 +151,7 @@ func (b *builder) ExportCustomExternalUrl(url string) { } func (b *builder) ExportRolloutStatus(args *RolloutArgs) { - b.lines = append(b.lines, fmt.Sprintf("kubectl config use-context \"%s\"", args.KubernetesContext)) - b.exportLines = append(b.exportLines, fmt.Sprintf("kubectl argo rollouts status \"%s\" -n \"%s\" | { read status; cf_export rollout_status=$status; }", args.RolloutName, args.RolloutNamespace)) + b.lines = append(b.lines, fmt.Sprintf("kubectl argo rollouts status \"%s\" -n \"%s\" | { read status; echo rollout_status=$status >> /meta/env_vars_to_export; }", args.RolloutName, args.RolloutNamespace)) } func getHostDomain(host string) (*string, error) {