@@ -56,6 +56,7 @@ import (
5656type (
5757 RuntimeUninstallOptions struct {
5858 RuntimeName string
59+ RuntimeNamespace string
5960 Timeout time.Duration
6061 CloneOpts * apgit.CloneOptions
6162 KubeFactory kube.Factory
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