diff --git a/core/src/plugins/kubernetes/container/deployment.ts b/core/src/plugins/kubernetes/container/deployment.ts index 7acf5731ce..d1a3d66beb 100644 --- a/core/src/plugins/kubernetes/container/deployment.ts +++ b/core/src/plugins/kubernetes/container/deployment.ts @@ -40,6 +40,7 @@ import { } from "../types" import { k8sGetContainerDeployStatus, ContainerServiceStatus } from "./status" import { emitNonRepeatableWarning } from "../../../warnings" +import { K8_POD_DEFAULT_CONTAINER_ANNOTATION_KEY } from "../run" export const DEFAULT_CPU_REQUEST = "10m" export const DEFAULT_MEMORY_REQUEST = "90Mi" // This is the minimum in some clusters - or so they tell me @@ -492,6 +493,9 @@ function workloadConfig({ } const { annotations, daemon } = action.getSpec() + // Add default-container annotation in generated manifest + // so exec respects it in case of multiple containers in pod + annotations[K8_POD_DEFAULT_CONTAINER_ANNOTATION_KEY] = action.name return { kind: daemon ? "DaemonSet" : "Deployment", diff --git a/core/test/integ/src/plugins/kubernetes/container/deployment.ts b/core/test/integ/src/plugins/kubernetes/container/deployment.ts index 7bcb642fd3..4c248d1dce 100644 --- a/core/test/integ/src/plugins/kubernetes/container/deployment.ts +++ b/core/test/integ/src/plugins/kubernetes/container/deployment.ts @@ -51,6 +51,7 @@ import { ResolvedDeployAction } from "../../../../../../src/actions/deploy" import { ActionRouter } from "../../../../../../src/router/router" import { ActionMode } from "../../../../../../src/actions/types" import { createActionLog } from "../../../../../../src/logger/log-entry" +import { K8_POD_DEFAULT_CONTAINER_ANNOTATION_KEY } from "../../../../../../src/plugins/kubernetes/run" describe("kubernetes container deployment handlers", () => { let garden: TestGarden @@ -289,7 +290,9 @@ describe("kubernetes container deployment handlers", () => { selector: { matchLabels: { [gardenAnnotationKey("action")]: action.key() } }, template: { metadata: { - annotations: {}, + annotations: { + [K8_POD_DEFAULT_CONTAINER_ANNOTATION_KEY]: "simple-service", + }, labels: getDeploymentLabels(action), }, spec: { @@ -331,7 +334,10 @@ describe("kubernetes container deployment handlers", () => { const action = await resolveDeployAction("simple-service") const namespace = provider.config.namespace!.name! - action["_config"].spec.annotations = { "annotation.key": "someValue" } + action["_config"].spec.annotations = { + "annotation.key": "someValue", + [K8_POD_DEFAULT_CONTAINER_ANNOTATION_KEY]: "simple-service", + } const resource = await createWorkloadManifest({ ctx,