MCPcopy
hub / github.com/zegl/kube-score / environmentVariableKeyDuplication

Function environmentVariableKeyDuplication

score/container/container.go:305–326  ·  view source on GitHub ↗

environmentVariableKeyDuplication checks that no duplicated environment variable keys.

(ps ks.PodSpecer)

Source from the content-addressed store, hash-verified

303
304// environmentVariableKeyDuplication checks that no duplicated environment variable keys.
305func environmentVariableKeyDuplication(ps ks.PodSpecer) (score scorecard.TestScore, err error) {
306 pod := ps.GetPodTemplateSpec().Spec
307
308 allContainers := pod.InitContainers
309 allContainers = append(allContainers, pod.Containers...)
310
311 score.Grade = scorecard.GradeAllOK
312
313 for _, container := range allContainers {
314 envs := make(map[string]struct{})
315 for _, env := range container.Env {
316 if _, duplicated := envs[env.Name]; duplicated {
317 msg := fmt.Sprintf("Container environment variable key '%s' is duplicated", env.Name)
318 score.AddComment(container.Name, "Environment Variable Key Duplication", msg)
319 score.Grade = scorecard.GradeCritical
320 continue
321 }
322 envs[env.Name] = struct{}{}
323 }
324 }
325 return
326}

Callers

nothing calls this directly

Calls 2

AddCommentMethod · 0.80
GetPodTemplateSpecMethod · 0.65

Tested by

no test coverage detected