Check for config map key ref for unused config map test
parent
cb603bc39a
commit
a3ccd62f2d
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2019 DigitalOcean
|
||||
Copyright 2020 DigitalOcean
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -155,6 +155,11 @@ func checkEnvVars(containers []corev1.Container, namespace string) []kube.Identi
|
|||
refs = append(refs, kube.Identifier{Name: env.ConfigMapRef.LocalObjectReference.Name, Namespace: namespace})
|
||||
}
|
||||
}
|
||||
for _, env := range container.Env {
|
||||
if env.ValueFrom != nil && env.ValueFrom.ConfigMapKeyRef != nil {
|
||||
refs = append(refs, kube.Identifier{Name: env.ValueFrom.ConfigMapKeyRef.LocalObjectReference.Name, Namespace: namespace})
|
||||
}
|
||||
}
|
||||
}
|
||||
return refs
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2019 DigitalOcean
|
||||
Copyright 2020 DigitalOcean
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -65,6 +65,11 @@ func TestUnusedConfigMapWarning(t *testing.T) {
|
|||
objs: configMapEnvSource(),
|
||||
expected: nil,
|
||||
},
|
||||
{
|
||||
name: "environment variable value from references config map",
|
||||
objs: configMapEnvVarValueFromSource(),
|
||||
expected: nil,
|
||||
},
|
||||
{
|
||||
name: "projected volume references config map",
|
||||
objs: projectedVolume(),
|
||||
|
@ -198,3 +203,26 @@ func configMapEnvSource() *kube.Objects {
|
|||
}
|
||||
return objs
|
||||
}
|
||||
|
||||
func configMapEnvVarValueFromSource() *kube.Objects {
|
||||
objs := initConfigMap()
|
||||
objs.Pods.Items[0].Spec = corev1.PodSpec{
|
||||
Containers: []corev1.Container{
|
||||
{
|
||||
Name: "test-container",
|
||||
Image: "docker.io/nginx",
|
||||
Env: []corev1.EnvVar{
|
||||
{
|
||||
Name: "special_env_var",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: "cm_foo"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return objs
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue