env: fix pod envFrom processing

This commit is contained in:
Tarun Pothulapati
2018-12-07 22:50:16 +05:30
committed by Paulo Pires
parent 31768c5b5c
commit fbae26fc11
4 changed files with 274 additions and 19 deletions

81
test/e2e/framework/env.go Normal file
View File

@@ -0,0 +1,81 @@
package framework
import (
corev1 "k8s.io/api/core/v1"
)
var (
bFalse = false
bTrue = true
)
// CreatePodObjectWithMandatoryConfigMapKey creates a pod object that references the "key_0" key from the "config-map-0" config map as mandatory.
func (f *Framework) CreatePodObjectWithMandatoryConfigMapKey() *corev1.Pod {
return f.CreatePodObjectWithEnv([]corev1.EnvVar{
{
Name: "CONFIG_MAP_0_KEY_0",
ValueFrom: &corev1.EnvVarSource{
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
LocalObjectReference: corev1.LocalObjectReference{Name: "config-map-0"},
Key: "key_0",
Optional: &bFalse,
},
},
},
})
}
// CreatePodObjectWithOptionalConfigMapKey creates a pod object that references the "key_0" key from the "config-map-0" config map as optional.
func (f *Framework) CreatePodObjectWithOptionalConfigMapKey() *corev1.Pod {
return f.CreatePodObjectWithEnv([]corev1.EnvVar{
{
Name: "CONFIG_MAP_0_KEY_0",
ValueFrom: &corev1.EnvVarSource{
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
LocalObjectReference: corev1.LocalObjectReference{Name: "config-map-0"},
Key: "key_0",
Optional: &bTrue,
},
},
},
})
}
// CreatePodObjectWithMandatorySecretKey creates a pod object that references the "key_0" key from the "secret-0" config map as mandatory.
func (f *Framework) CreatePodObjectWithMandatorySecretKey() *corev1.Pod {
return f.CreatePodObjectWithEnv([]corev1.EnvVar{
{
Name: "SECRET_0_KEY_0",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{Name: "secret-0"},
Key: "key_0",
Optional: &bFalse,
},
},
},
})
}
// CreatePodObjectWithOptionalSecretKey creates a pod object that references the "key_0" key from the "secret-0" config map as optional.
func (f *Framework) CreatePodObjectWithOptionalSecretKey() *corev1.Pod {
return f.CreatePodObjectWithEnv([]corev1.EnvVar{
{
Name: "SECRET_0_KEY_0",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{Name: "secret-0"},
Key: "key_0",
Optional: &bTrue,
},
},
},
})
}
// CreatePodObjectWithEnv creates a pod object whose name starts with "env-test-" and that uses the specified environment configuration for its first container.
func (f *Framework) CreatePodObjectWithEnv(env []corev1.EnvVar) *corev1.Pod {
pod := f.CreateDummyPodObjectWithPrefix("env-test-", "foo")
pod.Spec.Containers[0].Env = env
return pod
}