Skip to content

Commit

Permalink
CR-13084-hide-cluster-resources-upgrade (#658)
Browse files Browse the repository at this point in the history
* try to patch cluster-resource appset on upgrade
* bumped version to 0.1.20
  • Loading branch information
ATGardner authored Dec 19, 2022
1 parent 7dfbc67 commit 244892a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=v0.1.19
VERSION=v0.1.20

OUT_DIR=dist
YEAR?=$(shell date +"%Y")
Expand Down
16 changes: 16 additions & 0 deletions cmd/commands/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
5 changes: 5 additions & 0 deletions cmd/commands/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 3 additions & 13 deletions cmd/commands/runtime_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions docs/releases/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 244892a

Please sign in to comment.