@@ -56,6 +56,7 @@ import (
56
56
type (
57
57
RuntimeUninstallOptions struct {
58
58
RuntimeName string
59
+ RuntimeNamespace string
59
60
Timeout time.Duration
60
61
CloneOpts * apgit.CloneOptions
61
62
KubeFactory kube.Factory
71
72
72
73
RuntimeUpgradeOptions struct {
73
74
RuntimeName string
75
+ RuntimeNamespace string
74
76
CloneOpts * apgit.CloneOptions
75
77
CommonConfig * runtime.CommonConfig
76
78
SuggestedSharedConfigRepo string
@@ -178,7 +180,7 @@ func runtimeUninstallCommandPreRunHandler(cmd *cobra.Command, args []string, opt
178
180
return err
179
181
}
180
182
181
- if ! opts .Managed {
183
+ if ! opts .Managed && ! opts . SkipChecks {
182
184
err = ensureRepo (cmd , opts .RuntimeName , opts .CloneOpts , true )
183
185
}
184
186
handleCliStep (reporter .UninstallStepPreCheckEnsureRuntimeRepo , "Getting runtime repo" , err , true , false )
@@ -216,6 +218,8 @@ func runtimeUpgradeCommandPreRunHandler(cmd *cobra.Command, args []string, opts
216
218
return err
217
219
}
218
220
221
+ opts .RuntimeNamespace = * rt .Metadata .Namespace
222
+
219
223
if rt .Managed {
220
224
return fmt .Errorf ("manual upgrades are not allowed for hosted runtimes and are managed by Codefresh operational team" )
221
225
}
@@ -454,6 +458,7 @@ func NewRuntimeUninstallCommand() *cobra.Command {
454
458
finalParameters = map [string ]string {
455
459
"Codefresh context" : cfConfig .CurrentContext ,
456
460
"Runtime name" : opts .RuntimeName ,
461
+ "Runtime namespace" : opts .RuntimeNamespace ,
457
462
}
458
463
459
464
if ! opts .Managed {
@@ -541,7 +546,7 @@ func runRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err
541
546
542
547
if ! opts .Managed {
543
548
err = apcmd .RunRepoUninstall (ctx , & apcmd.RepoUninstallOptions {
544
- Namespace : opts .RuntimeName ,
549
+ Namespace : opts .RuntimeNamespace ,
545
550
KubeContextName : opts .kubeContext ,
546
551
Timeout : opts .Timeout ,
547
552
CloneOptions : opts .CloneOpts ,
@@ -577,7 +582,7 @@ func runRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err
577
582
}
578
583
579
584
if ! opts .Managed {
580
- err = runPostUninstallCleanup (ctx , opts .KubeFactory , opts .RuntimeName )
585
+ err = runPostUninstallCleanup (ctx , opts .KubeFactory , opts .RuntimeNamespace )
581
586
if err != nil {
582
587
errorMsg := fmt .Sprintf ("failed to do post uninstall cleanup: %v" , err )
583
588
if ! opts .Force {
@@ -875,7 +880,7 @@ func runRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
875
880
log .G (ctx ).Info ("Downloading runtime definition" )
876
881
877
882
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 )
879
884
handleCliStep (reporter .UpgradeStepDownloadRuntimeDefinition , "Downloading runtime definition" , err , true , false )
880
885
if err != nil {
881
886
return fmt .Errorf ("failed to download runtime definition: %w" , err )
@@ -930,7 +935,7 @@ func runRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
930
935
for _ , component := range newComponents {
931
936
log .G (ctx ).Infof ("Installing new component \" %s\" " , component .Name )
932
937
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 )
934
939
if err != nil {
935
940
err = fmt .Errorf ("failed to create \" %s\" application: %w" , component .Name , err )
936
941
break
@@ -1156,3 +1161,22 @@ func createAnalyticsReporter(ctx context.Context, flow reporter.FlowType, disabl
1156
1161
1157
1162
reporter .Init (user , flow )
1158
1163
}
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