Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

fix admission controller's podsInitContainerPatch #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions admission-controller/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ const (
podsSidecarPatch string = `[
{"op":"add", "path":"/spec/containers/-","value":{"image":"%v","name":"webhook-added-sidecar","volumeMounts":[{"name":"vol","mountPath":"/tmp"}],"resources":{}}}
]`
podsInitContainerPatch0 string = `[
{"op":"add","path":"/spec/initContainers/0","value":{"image":"%v","name":"secrets-init-container","imagePullPolicy": "Always","volumeMounts":[{"name":"secret-vol","mountPath":"/tmp"}],"env":[{"name": "SECRET_ARN","valueFrom": {"fieldRef": {"fieldPath": "metadata.annotations['secrets.k8s.aws/secret-arn']"}}}`
podsInitContainerPatch = `[
{"op":"add","path":"/spec/initContainers","value":[{"image":"%v","name":"secrets-init-container","imagePullPolicy": "Always","volumeMounts":[{"name":"secret-vol","mountPath":"/tmp"}],"env":[{"name": "SECRET_ARN","valueFrom": {"fieldRef": {"fieldPath": "metadata.annotations['secrets.k8s.aws/secret-arn']"}}}`
)

var podsInitContainerPatch string = `[
{"op":"add","path":"/spec/initContainers/0","value":{"image":"%v","name":"secrets-init-container","imagePullPolicy": "Always","volumeMounts":[{"name":"secret-vol","mountPath":"/tmp"}],"env":[{"name": "SECRET_ARN","valueFrom": {"fieldRef": {"fieldPath": "metadata.annotations['secrets.k8s.aws/secret-arn']"}}}`
var podsInitPatch = ``

func admitPods(ar v1.AdmissionReview) *v1.AdmissionResponse {
klog.V(2).Info("admitting pods")
Expand Down Expand Up @@ -87,12 +90,13 @@ func mutatePods(ar v1.AdmissionReview) *v1.AdmissionResponse {
}

if len(pod.Spec.InitContainers) == 0 {
podsInitContainerPatch = `[
{"op":"add","path":"/spec/initContainers","value":[{"image":"%v","name":"secrets-init-container","imagePullPolicy": "Always","volumeMounts":[{"name":"secret-vol","mountPath":"/tmp"}],"env":[{"name": "SECRET_ARN","valueFrom": {"fieldRef": {"fieldPath": "metadata.annotations['secrets.k8s.aws/secret-arn']"}}}`
}
podsInitPatch = podsInitContainerPatch
} else {
podsInitPatch = podsInitContainerPatch0
}
return !hasContainer(pod.Spec.InitContainers, "secrets-init-container")
}
return applyPodPatch(ar, shouldPatchPod, fmt.Sprintf(podsInitContainerPatch, sidecarImage))
return applyPodPatch(ar, shouldPatchPod, fmt.Sprintf(podsInitPatch, sidecarImage))
}

func mutatePodsSidecar(ar v1.AdmissionReview) *v1.AdmissionResponse {
Expand Down