From 62dadfcc2ccdc6b2f943f6295483334f2e5a4823 Mon Sep 17 00:00:00 2001 From: Thorarinn Sigurdsson Date: Mon, 1 Nov 2021 10:54:38 -0700 Subject: [PATCH] fix(k8s): use module ns in getServiceResource When provided, we now use the custom namespace defined in `module.spec.namespace` for `helm` and `kubernetes` modules when getting the module's `serviceResource`. --- core/src/plugins/kubernetes/util.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/src/plugins/kubernetes/util.ts b/core/src/plugins/kubernetes/util.ts index 4ff14c5f59..54db9ef3a0 100644 --- a/core/src/plugins/kubernetes/util.ts +++ b/core/src/plugins/kubernetes/util.ts @@ -20,7 +20,7 @@ import { gardenAnnotationKey, base64, deline, stableStringify } from "../../util import { inClusterRegistryHostname, MAX_CONFIGMAP_DATA_SIZE, systemDockerAuthSecretName } from "./constants" import { ContainerEnvVars } from "../container/config" import { ConfigurationError, DeploymentError, PluginError } from "../../exceptions" -import { ServiceResourceSpec, KubernetesProvider } from "./config" +import { ServiceResourceSpec, KubernetesProvider, KubernetesPluginContext } from "./config" import { LogEntry } from "../../logger/log-entry" import { PluginContext } from "../../plugin-context" import { HelmModule } from "./helm/config" @@ -31,7 +31,7 @@ import { ProviderMap } from "../../config/provider" import { PodRunner } from "./run" import { isSubset } from "../../util/is-subset" import { checkPodStatus } from "./status/pod" -import { getAppNamespace } from "./namespace" +import { getModuleNamespace } from "./namespace" export const skopeoImage = "gardendev/skopeo:1.41.0-2" @@ -562,7 +562,13 @@ export async function getServiceResource({ if (resourceSpec.podSelector && !isEmpty(resourceSpec.podSelector)) { const api = await KubeApi.factory(log, ctx, provider) - const namespace = await getAppNamespace(ctx, log, provider) + const k8sCtx = ctx as KubernetesPluginContext + const namespace = await getModuleNamespace({ + ctx: k8sCtx, + log, + module, + provider: k8sCtx.provider, + }) const pods = await getReadyPods(api, namespace, resourceSpec.podSelector) const pod = sample(pods)