Skip to content

Commit

Permalink
Fix migrate command (#725)
Browse files Browse the repository at this point in the history
## What
<!-- What is changing in this PR? -->

## Why
<!-- Why are these changes being made? -->

## Notes
<!-- Add any additional notes here -->
  • Loading branch information
danielm-codefresh authored Dec 7, 2023
1 parent fcd73ea commit d9aa8b6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 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.54
VERSION=v0.1.55

OUT_DIR=dist
YEAR?=$(shell date +"%Y")
Expand Down
25 changes: 21 additions & 4 deletions cmd/commands/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net/url"
"strings"

aputil "github.com/argoproj-labs/argocd-autopilot/pkg/util"
argocdv1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/codefresh-io/cli-v2/pkg/log"
"github.com/codefresh-io/cli-v2/pkg/store"
Expand Down Expand Up @@ -134,14 +135,18 @@ func runHelmMigrate(ctx context.Context, opts *MigrateOptions) error {
}

log.G(ctx).Infof("Cloned installation repo %q", *runtime.Repo)
destFs := apfs.Create(memfs.New())
if isSharedConfigInInstallationRepo(user.ActiveAccount.SharedConfigRepo, runtime.Repo) {
destFs = opts.cloneOpts.FS
}
destCloneOpts := &apgit.CloneOptions{
Provider: user.ActiveAccount.GitProvider.String(),
Repo: *user.ActiveAccount.SharedConfigRepo,
Auth: opts.cloneOpts.Auth,
FS: apfs.Create(memfs.New()),
FS: destFs,
}
destCloneOpts.Parse()
destRepo, destFs, err := destCloneOpts.GetRepo(ctx)
_, destFs, err = destCloneOpts.GetRepo(ctx)
if err != nil {
return fmt.Errorf("failed getting shared config repo: %w", err)
}
Expand Down Expand Up @@ -171,15 +176,20 @@ func runHelmMigrate(ctx context.Context, opts *MigrateOptions) error {
return fmt.Errorf("failed pushing changes to installation repo: %w", err)
}

log.G(ctx).Infof("Pushed changes to installation repo %q, sha: %s", *user.ActiveAccount.SharedConfigRepo, sha)
log.G(ctx).Infof("Pushed changes to installation repo %q, sha: %s", *runtime.Repo, sha)

destRepo, _, err := destCloneOpts.GetRepo(ctx)
if err != nil {
return fmt.Errorf("failed getting shared config repo: %w", err)
}
sha, err = destRepo.Persist(ctx, &apgit.PushOptions{
CommitMsg: "moved resources from installation repo",
})
if err != nil {
return fmt.Errorf("failed pushing changes to internal-shared-config repo: %w", err)
}

log.G(ctx).Infof("Pushed changes to shared-config-repo %q, sha: %s", *runtime.Repo, sha)
log.G(ctx).Infof("Pushed changes to shared-config-repo %q, sha: %s", *user.ActiveAccount.SharedConfigRepo, sha)
log.G(ctx).Infof("Done migrating resources from %q to %q", *runtime.Repo, *user.ActiveAccount.SharedConfigRepo)

err = removeFromCluster(ctx, opts.helmReleaseName, *runtime.Metadata.Namespace, opts.kubeContext, srcCloneOpts, opts.kubeFactory)
Expand Down Expand Up @@ -631,3 +641,10 @@ func filterStatus(manifest []byte) []byte {

return []byte(strings.Join(res, "\n"))
}

func isSharedConfigInInstallationRepo(iscRepo, installationRepo *string) bool {
iscRepoHost, _, _, _, _, _, _ := aputil.ParseGitUrl(*iscRepo)
installationRepoHost, _, _, _, _, _, _ := aputil.ParseGitUrl(*installationRepo)

return iscRepoHost == installationRepoHost
}
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.51/cf-linux-amd64.tar.gz | tar zx
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.55/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.51/cf-darwin-amd64.tar.gz | tar zx
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.55/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 d9aa8b6

Please sign in to comment.