Skip to content

Commit 9c96245

Browse files
Decouple runtime name and namespace (#679)
* fix * fix * fixes according to code review * fixes * bump
1 parent 0507dd1 commit 9c96245

File tree

9 files changed

+116
-63
lines changed

9 files changed

+116
-63
lines changed

Makefile

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

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

cmd/commands/git-source.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type (
5757
GsCloneOpts *git.CloneOptions
5858
GsName string
5959
RuntimeName string
60+
RuntimeNamespace string
6061
CreateDemoResources bool
6162
Exclude string
6263
Include string
@@ -186,11 +187,18 @@ func NewGitSourceCreateCommand() *cobra.Command {
186187
RunE: func(cmd *cobra.Command, args []string) error {
187188
ctx := cmd.Context()
188189

190+
runtimeNamespace := args[0]
191+
namespace := cmd.Flag("namespace").Value.String()
192+
if namespace != "" {
193+
runtimeNamespace = namespace
194+
}
195+
189196
return RunGitSourceCreate(ctx, &GitSourceCreateOptions{
190197
GsCloneOpts: gsCloneOpts,
191198
GitProvider: gitProvider,
192199
GsName: args[1],
193200
RuntimeName: args[0],
201+
RuntimeNamespace: runtimeNamespace,
194202
CreateDemoResources: false,
195203
Include: include,
196204
Exclude: exclude,
@@ -223,7 +231,7 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
223231
AppName: opts.GsName,
224232
AppSpecifier: appSpecifier,
225233
DestServer: store.Get().InCluster,
226-
DestNamespace: &opts.RuntimeName,
234+
DestNamespace: &opts.RuntimeNamespace,
227235
IsInternal: &isInternal,
228236
Include: &opts.Include,
229237
Exclude: &opts.Exclude,
@@ -1424,7 +1432,7 @@ func legacyGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) er
14241432

14251433
appDef.IsInternal = util.StringIndexOf(store.Get().CFInternalGitSources, appDef.Name) > -1
14261434

1427-
if err := appDef.CreateApp(ctx, nil, opts.InsCloneOpts, opts.RuntimeName, store.Get().CFGitSourceType); err != nil {
1435+
if err := appDef.CreateApp(ctx, nil, opts.InsCloneOpts, opts.RuntimeName, opts.RuntimeNamespace, store.Get().CFGitSourceType); err != nil {
14281436
return fmt.Errorf("failed to create git-source application. Err: %w", err)
14291437
}
14301438

cmd/commands/runtime.go

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import (
5656
type (
5757
RuntimeUninstallOptions struct {
5858
RuntimeName string
59+
RuntimeNamespace string
5960
Timeout time.Duration
6061
CloneOpts *apgit.CloneOptions
6162
KubeFactory kube.Factory
@@ -71,6 +72,7 @@ type (
7172

7273
RuntimeUpgradeOptions struct {
7374
RuntimeName string
75+
RuntimeNamespace string
7476
CloneOpts *apgit.CloneOptions
7577
CommonConfig *runtime.CommonConfig
7678
SuggestedSharedConfigRepo string
@@ -178,7 +180,7 @@ func runtimeUninstallCommandPreRunHandler(cmd *cobra.Command, args []string, opt
178180
return err
179181
}
180182

181-
if !opts.Managed {
183+
if !opts.Managed && !opts.SkipChecks {
182184
err = ensureRepo(cmd, opts.RuntimeName, opts.CloneOpts, true)
183185
}
184186
handleCliStep(reporter.UninstallStepPreCheckEnsureRuntimeRepo, "Getting runtime repo", err, true, false)
@@ -216,6 +218,8 @@ func runtimeUpgradeCommandPreRunHandler(cmd *cobra.Command, args []string, opts
216218
return err
217219
}
218220

221+
opts.RuntimeNamespace = *rt.Metadata.Namespace
222+
219223
if rt.Managed {
220224
return fmt.Errorf("manual upgrades are not allowed for hosted runtimes and are managed by Codefresh operational team")
221225
}
@@ -454,6 +458,7 @@ func NewRuntimeUninstallCommand() *cobra.Command {
454458
finalParameters = map[string]string{
455459
"Codefresh context": cfConfig.CurrentContext,
456460
"Runtime name": opts.RuntimeName,
461+
"Runtime namespace": opts.RuntimeNamespace,
457462
}
458463

459464
if !opts.Managed {
@@ -541,7 +546,7 @@ func runRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err
541546

542547
if !opts.Managed {
543548
err = apcmd.RunRepoUninstall(ctx, &apcmd.RepoUninstallOptions{
544-
Namespace: opts.RuntimeName,
549+
Namespace: opts.RuntimeNamespace,
545550
KubeContextName: opts.kubeContext,
546551
Timeout: opts.Timeout,
547552
CloneOptions: opts.CloneOpts,
@@ -577,7 +582,7 @@ func runRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err
577582
}
578583

579584
if !opts.Managed {
580-
err = runPostUninstallCleanup(ctx, opts.KubeFactory, opts.RuntimeName)
585+
err = runPostUninstallCleanup(ctx, opts.KubeFactory, opts.RuntimeNamespace)
581586
if err != nil {
582587
errorMsg := fmt.Sprintf("failed to do post uninstall cleanup: %v", err)
583588
if !opts.Force {
@@ -875,7 +880,7 @@ func runRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
875880
log.G(ctx).Info("Downloading runtime definition")
876881

877882
runtimeDef := getRuntimeDef(opts.runtimeDef, opts.versionStr)
878-
newRt, err := runtime.Download(runtimeDef, opts.RuntimeName, opts.featuresToInstall)
883+
newRt, err := runtime.Download(runtimeDef, opts.RuntimeName, opts.RuntimeNamespace, opts.featuresToInstall)
879884
handleCliStep(reporter.UpgradeStepDownloadRuntimeDefinition, "Downloading runtime definition", err, true, false)
880885
if err != nil {
881886
return fmt.Errorf("failed to download runtime definition: %w", err)
@@ -930,7 +935,7 @@ func runRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
930935
for _, component := range newComponents {
931936
log.G(ctx).Infof("Installing new component \"%s\"", component.Name)
932937
component.IsInternal = true
933-
err = component.CreateApp(ctx, nil, opts.CloneOpts, opts.RuntimeName, store.Get().CFComponentType)
938+
err = component.CreateApp(ctx, nil, opts.CloneOpts, opts.RuntimeName, opts.RuntimeNamespace, store.Get().CFComponentType)
934939
if err != nil {
935940
err = fmt.Errorf("failed to create \"%s\" application: %w", component.Name, err)
936941
break
@@ -1156,3 +1161,22 @@ func createAnalyticsReporter(ctx context.Context, flow reporter.FlowType, disabl
11561161

11571162
reporter.Init(user, flow)
11581163
}
1164+
1165+
func getRuntimeNamespace(cmd *cobra.Command, runtimeName string, runtimeVersion *semver.Version) string {
1166+
namespace := runtimeName
1167+
differentNamespaceSupportVer := semver.MustParse("0.1.26")
1168+
hasdifferentNamespaceSupport := runtimeVersion.GreaterThan(differentNamespaceSupportVer)
1169+
1170+
if !hasdifferentNamespaceSupport {
1171+
log.G().Infof("To specify a different namespace please use runtime version >= %s", differentNamespaceSupportVer.String())
1172+
_ = cmd.Flag("namespace").Value.Set("")
1173+
return namespace
1174+
}
1175+
1176+
namespaceVal := cmd.Flag("namespace").Value.String()
1177+
if namespaceVal != "" {
1178+
namespace = namespaceVal
1179+
}
1180+
1181+
return namespace
1182+
}

0 commit comments

Comments
 (0)