From 244892a76607a5e38772dc53c5e1ceda3984e6c3 Mon Sep 17 00:00:00 2001 From: Noam Gal Date: Mon, 19 Dec 2022 11:53:00 +0200 Subject: [PATCH] CR-13084-hide-cluster-resources-upgrade (#658) * try to patch cluster-resource appset on upgrade * bumped version to 0.1.20 --- Makefile | 2 +- cmd/commands/common.go | 16 ++++++++++++++++ cmd/commands/runtime.go | 5 +++++ cmd/commands/runtime_install.go | 16 +++------------- docs/releases/release_notes.md | 4 ++-- 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 33f6f2e7..951e1dfb 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=v0.1.19 +VERSION=v0.1.20 OUT_DIR=dist YEAR?=$(shell date +"%Y") diff --git a/cmd/commands/common.go b/cmd/commands/common.go index 707abc15..3ad175f4 100644 --- a/cmd/commands/common.go +++ b/cmd/commands/common.go @@ -34,7 +34,10 @@ import ( "github.com/codefresh-io/cli-v2/pkg/runtime" "github.com/codefresh-io/cli-v2/pkg/store" "github.com/codefresh-io/cli-v2/pkg/util" + apu "github.com/codefresh-io/cli-v2/pkg/util/aputil" + "github.com/argoproj-labs/argocd-autopilot/pkg/fs" + "github.com/argoproj-labs/argocd-autopilot/pkg/git" apgit "github.com/argoproj-labs/argocd-autopilot/pkg/git" aputil "github.com/argoproj-labs/argocd-autopilot/pkg/util" platmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model" @@ -790,3 +793,16 @@ func getRuntime(ctx context.Context, runtimeName string) (*platmodel.Runtime, er return rt, nil } + +func patchRuntimeRepo(ctx context.Context, cloneOpts *git.CloneOptions, msg string, f func(fs fs.FS) error) error { + r, fs, err := cloneOpts.GetRepo(ctx) + if err != nil { + return err + } + + if err = f(fs); err != nil { + return err + } + + return apu.PushWithMessage(ctx, r, msg) +} diff --git a/cmd/commands/runtime.go b/cmd/commands/runtime.go index 74b868dc..526a8e05 100644 --- a/cmd/commands/runtime.go +++ b/cmd/commands/runtime.go @@ -909,6 +909,11 @@ func runRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error { return fmt.Errorf("failed to upgrade runtime: %w", err) } + err = patchClusterResourcesAppSet(fs) + if err != nil { + log.G(ctx).Warnf("failed to patch cluster-resources ApplicationSet: %w", err) + } + log.G(ctx).Info("Pushing new runtime definition") err = apu.PushWithMessage(ctx, r, fmt.Sprintf("Upgraded to %s", newRt.Spec.Version)) handleCliStep(reporter.UpgradeStepPushRuntimeDefinition, "Pushing new runtime definition", err, false, false) diff --git a/cmd/commands/runtime_install.go b/cmd/commands/runtime_install.go index d2646a3b..9626be70 100644 --- a/cmd/commands/runtime_install.go +++ b/cmd/commands/runtime_install.go @@ -47,7 +47,6 @@ import ( apcmd "github.com/argoproj-labs/argocd-autopilot/cmd/commands" "github.com/argoproj-labs/argocd-autopilot/pkg/application" "github.com/argoproj-labs/argocd-autopilot/pkg/fs" - "github.com/argoproj-labs/argocd-autopilot/pkg/git" apgit "github.com/argoproj-labs/argocd-autopilot/pkg/git" "github.com/argoproj-labs/argocd-autopilot/pkg/kube" apstore "github.com/argoproj-labs/argocd-autopilot/pkg/store" @@ -694,7 +693,7 @@ func runRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error { return util.DecorateErrorWithDocsLink(fmt.Errorf("failed to bootstrap repository: %w", err)) } - err = patchClusterResourcesAppSet(ctx, opts.InsCloneOpts) + err = patchRuntimeRepo(ctx, opts.InsCloneOpts, "patch cluster-resources ApplicationSet", patchClusterResourcesAppSet) if err != nil { return util.DecorateErrorWithDocsLink(fmt.Errorf("failed to patch cluster-resources ApplicationSet: %w", err)) } @@ -2153,12 +2152,7 @@ func getRuntimeDef(runtimeDef, version string) string { return strings.Replace(runtimeDef, "stable", version, 1) } -func patchClusterResourcesAppSet(ctx context.Context, cloneOpts *git.CloneOptions) error { - r, fs, err := cloneOpts.GetRepo(ctx) - if err != nil { - return err - } - +func patchClusterResourcesAppSet(fs fs.FS) error { appSet := &argocdv1alpha1.ApplicationSet{} name := store.Get().ClusterResourcesPath if err := fs.ReadYamls(name, appSet); err != nil { @@ -2170,9 +2164,5 @@ func patchClusterResourcesAppSet(ctx context.Context, cloneOpts *git.CloneOption } appSet.ObjectMeta.Labels[store.Get().LabelKeyCFInternal] = "true" - if err = fs.WriteYamls(name, appSet); err != nil { - return err - } - - return apu.PushWithMessage(ctx, r, "patch cluster-resources ApplicationSet") + return fs.WriteYamls(name, appSet) } diff --git a/docs/releases/release_notes.md b/docs/releases/release_notes.md index f26d161a..b31db778 100644 --- a/docs/releases/release_notes.md +++ b/docs/releases/release_notes.md @@ -23,7 +23,7 @@ cf version ```bash # download and extract the binary -curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.19/cf-linux-amd64.tar.gz | tar zx +curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.20/cf-linux-amd64.tar.gz | tar zx # move the binary to your $PATH mv ./cf-linux-amd64 /usr/local/bin/cf @@ -36,7 +36,7 @@ cf version ```bash # download and extract the binary -curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.19/cf-darwin-amd64.tar.gz | tar zx +curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.20/cf-darwin-amd64.tar.gz | tar zx # move the binary to your $PATH mv ./cf-darwin-amd64 /usr/local/bin/cf