Skip to content

Commit

Permalink
fix: patchOperation
Browse files Browse the repository at this point in the history
  • Loading branch information
azrod committed Feb 14, 2024
1 parent fdf8ec1 commit fe60934
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
23 changes: 10 additions & 13 deletions cmd/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,18 @@ func mutationRequired(ignoredList []string, metadata *metav1.ObjectMeta) bool {
func addEnvironnement(containers []corev1.Container, added []corev1.EnvVar, basePath string) (patch []patchOperation) {
// for each containers in the pod spec, append the env vars
for i := range containers {
// if the container has no env vars, initialize the env vars
if containers[i].Env == nil {
containers[i].Env = make([]corev1.EnvVar, 0)
}
var path string

// for each env var in the added env vars, append the env var to the container
for _, add := range added {
// Compute the path for the env var
path := basePath + "/" + fmt.Sprintf("%d/env", i)
patch = append(patch, patchOperation{
Op: "add",
Path: path,
Value: add,
})
path = basePath + "/" + fmt.Sprintf("%d/env", i)
if containers[i].Env != nil {
path = basePath + "/" + fmt.Sprintf("%d/env/-", i)
}

patch = append(patch, patchOperation{
Op: "add",
Path: path,
Value: added,
})
}

return patch
Expand Down
6 changes: 3 additions & 3 deletions manifests/env-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
env:
- name: HTTP_PROXY
Value: http://10.1.2.3:3128
Value: "http://10.1.2.3:3128"
- name: HTTPS_PROXY
Value: http://10.1.2.3:3128
Value: "http://10.1.2.3:3128"
- name: NO_PROXY
Value: cluster.local,localhost,127.0.0.1
Value: "cluster.local,localhost,127.0.0.1"

0 comments on commit fe60934

Please sign in to comment.