Skip to content

Commit

Permalink
fix(container): add default container annotation to generated manifests
Browse files Browse the repository at this point in the history
This is useful when pod has multiple containers (e.g. injected as sidecars).
With this annotation, the right container is picked when exec
is run without specifying container name
  • Loading branch information
shumailxyz committed Jul 18, 2023
1 parent ac70427 commit 7ca6ca5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions core/src/plugins/kubernetes/container/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 8 additions & 2 deletions core/test/integ/src/plugins/kubernetes/container/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7ca6ca5

Please sign in to comment.