diff --git a/pkg/deploy/kapp.go b/pkg/deploy/kapp.go index 5618bab79b..49d599521c 100644 --- a/pkg/deploy/kapp.go +++ b/pkg/deploy/kapp.go @@ -63,7 +63,7 @@ func (a *Kapp) Deploy(tplOutput string, startedApplyingFunc func(), metadataFile := filepath.Join(tmpMetadataDir.Path(), "app-metadata.yml") - args, err := a.addDeployArgs([]string{"deploy", "--app-metadata-file-output", metadataFile, "--prev-app", a.oldManagedName(), "-f", "-", "--app-namespace", a.appNamespace}) + args, err := a.addDeployArgs([]string{"deploy", "--app-metadata-file-output", metadataFile, "--prev-app", a.oldManagedName(), "-f", "-"}) if err != nil { return exec.NewCmdRunResultWithErr(err) } @@ -90,7 +90,7 @@ func (a *Kapp) Deploy(tplOutput string, startedApplyingFunc func(), // Delete takes the app name, it shells out, running kapp delete ... func (a *Kapp) Delete(startedApplyingFunc func(), changedFunc func(exec.CmdRunResult)) exec.CmdRunResult { - args, err := a.addDeleteArgs([]string{"delete", "--prev-app", a.oldManagedName(), "--app-namespace", a.appNamespace}) + args, err := a.addDeleteArgs([]string{"delete", "--prev-app", a.oldManagedName()}) if err != nil { return exec.NewCmdRunResultWithErr(err) } @@ -120,7 +120,6 @@ func (a *Kapp) Inspect() exec.CmdRunResult { // TODO is there a better way to deal with this? "--filter", `{"not":{"resource":{"kinds":["PodMetrics"]}}}`, "--tty", - "--app-namespace", a.appNamespace, }) if err != nil { return exec.NewCmdRunResultWithErr(err) @@ -260,6 +259,10 @@ func (a *Kapp) addGenericArgs(args []string, appName string) ([]string, []string args = append(args, []string{"--namespace", a.clusterAccess.Namespace}...) } + if len(a.clusterAccess.DeployNamespace) > 0 { + args = append(args, []string{"--app-namespace", a.clusterAccess.DeployNamespace}...) + } + switch { case a.clusterAccess.Kubeconfig != nil: env = append(env, "KAPP_KUBECONFIG_YAML="+a.clusterAccess.Kubeconfig.AsYAML()) diff --git a/pkg/kubeconfig/kubeconfig.go b/pkg/kubeconfig/kubeconfig.go index 7fbf5e6ea1..edd511cd90 100644 --- a/pkg/kubeconfig/kubeconfig.go +++ b/pkg/kubeconfig/kubeconfig.go @@ -32,6 +32,8 @@ type AccessInfo struct { Name string Namespace string + DeployNamespace string + Kubeconfig *Restricted DangerousUsePodServiceAccount bool } @@ -68,8 +70,10 @@ func (k Kubeconfig) ClusterAccess(saName string, clusterOpts *v1alpha1.AppCluste return AccessInfo{}, fmt.Errorf("Expected service account or cluster specified") } - // If preferredNamespace is "", then kubeconfig preferred namespace will be used - clusterAccessInfo.Namespace = preferredNamespace + if clusterAccessInfo.Namespace == "" { + // If preferredNamespace is "", then kubeconfig preferred namespace will be used + clusterAccessInfo.Namespace = preferredNamespace + } return clusterAccessInfo, nil } diff --git a/pkg/kubeconfig/kubeconfig_secrets.go b/pkg/kubeconfig/kubeconfig_secrets.go index d0fb2c1bf0..d079199b5e 100644 --- a/pkg/kubeconfig/kubeconfig_secrets.go +++ b/pkg/kubeconfig/kubeconfig_secrets.go @@ -49,8 +49,11 @@ func (s *Secrets) Find(accessLocation AccessLocation, Name: accessLocation.Name, // Override destination namespace; if it's empty // assume kubeconfig contains preferred namespace - Namespace: clusterOpts.Namespace, - Kubeconfig: kubeconfigRestricted, + Namespace: clusterOpts.Namespace, + // Use provided namespace as app namespace; if it's empty + // assume kubeconfig contains preferred namespace + DeployNamespace: clusterOpts.Namespace, + Kubeconfig: kubeconfigRestricted, } return pgoForCluster, nil diff --git a/pkg/kubeconfig/service_accounts.go b/pkg/kubeconfig/service_accounts.go index 7b089e877a..fde14ca9ad 100644 --- a/pkg/kubeconfig/service_accounts.go +++ b/pkg/kubeconfig/service_accounts.go @@ -51,9 +51,10 @@ func (s *ServiceAccounts) Find(accessLocation AccessLocation, saName string) (Ac } pgoForSA := AccessInfo{ - Name: accessLocation.Name, - Namespace: "", // Assume kubeconfig contains preferred namespace from SA - Kubeconfig: kubeconfigRestricted, + Name: accessLocation.Name, + Namespace: "", // Assume kubeconfig contains preferred namespace from SA + DeployNamespace: accessLocation.Namespace, // App namespace is same as SA namespace + Kubeconfig: kubeconfigRestricted, } return pgoForSA, nil