Skip to content

Commit 7afa8df

Browse files
authored
compare install repo host to isc host (#500)
1 parent 05b9d87 commit 7afa8df

File tree

8 files changed

+57
-9
lines changed

8 files changed

+57
-9
lines changed

Makefile

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

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

cmd/commands/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ func newClusterRemoveCommand() *cobra.Command {
398398

399399
return nil
400400
},
401-
RunE: func(cmd *cobra.Command, args []string) error {
401+
RunE: func(cmd *cobra.Command, _ []string) error {
402402
// this is a temp solution for too short timeout when removing a cluster
403403
// (on app-proxy it is waiting for the isc to finalize which can take a while)
404404
// this should be removed after implementing a scalable solution (CR-13259)

cmd/commands/common.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ func ensureGitPAT(ctx context.Context, opts *RuntimeInstallOptions) error {
311311
opts.GitIntegrationRegistrationOpts.Token = opts.InsCloneOpts.Auth.Password
312312
currentUser, err := cfConfig.NewClient().Users().GetCurrent(ctx)
313313
if err != nil {
314-
return fmt.Errorf("failed to retrieve username from platform: %w", err)
314+
return fmt.Errorf("failed to get current user from platform: %w", err)
315315
}
316316

317317
log.G(ctx).Infof("Personal git token was not provided. Using runtime git token to register user: \"%s\". You may replace your personal git token at any time from the UI in the user settings", currentUser.Name)
@@ -638,7 +638,20 @@ func isValidationError(err error) bool {
638638
return err != nil && err != promptui.ErrInterrupt
639639
}
640640

641-
func setIscRepo(ctx context.Context, suggestedSharedConfigRepo string) (string, error) {
641+
func getIscRepo(ctx context.Context) (string, error) {
642+
currentUser, err := cfConfig.NewClient().V2().UsersV2().GetCurrent(ctx)
643+
if err != nil {
644+
return "", fmt.Errorf("failed to get current user from platform: %w", err)
645+
}
646+
647+
if currentUser.ActiveAccount.SharedConfigRepo == nil {
648+
return "", nil
649+
}
650+
651+
return *currentUser.ActiveAccount.SharedConfigRepo, nil
652+
}
653+
654+
func suggestIscRepo(ctx context.Context, suggestedSharedConfigRepo string) (string, error) {
642655
setIscRepoResponse, err := cfConfig.NewClient().V2().Runtime().SetSharedConfigRepo(ctx, suggestedSharedConfigRepo)
643656
if err != nil {
644657
return "", fmt.Errorf("failed to set shared config repo. Error: %w", err)

cmd/commands/runtime.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func runtimeUpgradeCommandPreRunHandler(cmd *cobra.Command, args []string, opts
224224
}
225225

226226
if opts.SuggestedSharedConfigRepo != "" {
227-
sharedConfigRepo, err := setIscRepo(ctx, opts.SuggestedSharedConfigRepo)
227+
sharedConfigRepo, err := suggestIscRepo(ctx, opts.SuggestedSharedConfigRepo)
228228
if err != nil {
229229
return fmt.Errorf("failed to ensure shared config repo for account: %w", err)
230230
}

cmd/commands/runtime_install.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func runtimeInstallCommandPreRunHandler(cmd *cobra.Command, opts *RuntimeInstall
299299
}
300300

301301
if opts.SuggestedSharedConfigRepo != "" {
302-
sharedConfigRepo, err := setIscRepo(ctx, opts.SuggestedSharedConfigRepo)
302+
sharedConfigRepo, err := suggestIscRepo(ctx, opts.SuggestedSharedConfigRepo)
303303
if err != nil {
304304
return fmt.Errorf("failed to ensure shared config repo: %w", err)
305305
}
@@ -1059,10 +1059,17 @@ func installComponents(ctx context.Context, opts *RuntimeInstallOptions, rt *run
10591059
}
10601060

10611061
func preInstallationChecks(ctx context.Context, opts *RuntimeInstallOptions) error {
1062+
var err error
10621063
log.G(ctx).Debug("running pre-installation checks...")
10631064

10641065
handleCliStep(reporter.InstallPhaseRunPreCheckStart, "Running pre run installation checks", nil, true, false)
10651066

1067+
err = checkIscProvider(ctx, opts.InsCloneOpts)
1068+
handleCliStep(reporter.InstallStepRunPreCheckGitProvider, "Checking Account Git Provider", err, true, true)
1069+
if err != nil {
1070+
return err
1071+
}
1072+
10661073
rt, err := runtime.Download(opts.Version, opts.RuntimeName)
10671074
handleCliStep(reporter.InstallStepRunPreCheckDownloadRuntimeDefinition, "Downloading runtime definition", err, true, true)
10681075
if err != nil {
@@ -1102,6 +1109,33 @@ func preInstallationChecks(ctx context.Context, opts *RuntimeInstallOptions) err
11021109
return nil
11031110
}
11041111

1112+
func checkIscProvider(ctx context.Context, opts *apgit.CloneOptions) error {
1113+
iscRepo, err := getIscRepo(ctx)
1114+
if err != nil {
1115+
return fmt.Errorf("failed to check account git provider: %w", err)
1116+
}
1117+
1118+
if iscRepo == "" {
1119+
return nil
1120+
}
1121+
1122+
iscUrl, err := url.Parse(iscRepo)
1123+
if err != nil {
1124+
return fmt.Errorf("failed to check account git provider: %w", err)
1125+
}
1126+
1127+
insUrl, err := url.Parse(opts.URL())
1128+
if err != nil {
1129+
return fmt.Errorf("failed to check account git provider: %w", err)
1130+
}
1131+
1132+
if iscUrl.Host != insUrl.Host {
1133+
return fmt.Errorf("cannot install runtime in \"%s\" when Account git provider is in \"%s\"", insUrl.Host, iscUrl.Host)
1134+
}
1135+
1136+
return nil
1137+
}
1138+
11051139
func checkRuntimeCollisions(ctx context.Context, kube kube.Factory, runtime string) error {
11061140
log.G(ctx).Debug("checking for argocd collisions in cluster")
11071141

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.443/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.444/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.443/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.444/cf-darwin-amd64.tar.gz | tar zx
4040

4141
# move the binary to your $PATH
4242
mv ./cf-darwin-amd64 /usr/local/bin/cf

manifests/runtime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: "{{ namespace }}"
66
spec:
77
defVersion: 1.0.1
8-
version: 0.0.443
8+
version: 0.0.444
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

pkg/reporter/reporter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const (
7272
InstallStepPreCheckShouldInstallDemoResources CliStep = "install.pre-check.step.should-install-demo-resources"
7373
InstallPhasePreCheckFinish CliStep = "install.pre-check.phase.finish"
7474
InstallPhaseRunPreCheckStart CliStep = "install.run.pre-check.phase.start"
75+
InstallStepRunPreCheckGitProvider CliStep = "install.run.pre-check.step.check-git-provider"
7576
InstallStepRunPreCheckDownloadRuntimeDefinition CliStep = "install.run.pre-check.step.download-runtime-definition"
7677
InstallStepRunPreCheckEnsureCliVersion CliStep = "install.run.pre-check.step.ensure-cli-version"
7778
InstallStepRunPreCheckRuntimeCollision CliStep = "install.run.pre-check.step.runtime-collision"

0 commit comments

Comments
 (0)