env: fix pod envFrom processing
This commit is contained in:
committed by
Paulo Pires
parent
31768c5b5c
commit
fbae26fc11
@@ -189,6 +189,128 @@ func TestPodLifecycle(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestCreatePodWithOptionalInexistantSecrets tries to create a pod referencing optional, inexistant secrets.
|
||||
// It then verifies that the pod is created successfully.
|
||||
func TestCreatePodWithOptionalInexistantSecrets(t *testing.T) {
|
||||
// Create a pod with a single container referencing optional, inexistant secrets.
|
||||
pod, err := f.CreatePod(f.CreatePodObjectWithOptionalSecretKey())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Delete the pod after the test finishes.
|
||||
defer func() {
|
||||
if err := f.DeletePod(pod.Namespace, pod.Name); err != nil && !apierrors.IsNotFound(err) {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Wait for the pod to be reported as running and ready.
|
||||
if err := f.WaitUntilPodReady(pod.Namespace, pod.Name); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Check that the pod is known to the provider.
|
||||
stats, err := f.GetStatsSummary()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := findPodInPodStats(stats, pod); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestCreatePodWithMandatoryInexistantSecrets tries to create a pod referencing inexistant secrets.
|
||||
// It then verifies that the pod is not created.
|
||||
func TestCreatePodWithMandatoryInexistantSecrets(t *testing.T) {
|
||||
// Create a pod with a single container referencing inexistant secrets.
|
||||
pod, err := f.CreatePod(f.CreatePodObjectWithMandatorySecretKey())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Delete the pod after the test finishes.
|
||||
defer func() {
|
||||
if err := f.DeletePodImmediately(pod.Namespace, pod.Name); err != nil && !apierrors.IsNotFound(err) {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Wait for a small period so we can later assert the pod is not running.
|
||||
// TODO (@pires) Wait for event to be reported.
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
// Check that the pod is NOT known to the provider.
|
||||
stats, err := f.GetStatsSummary()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := findPodInPodStats(stats, pod); err == nil {
|
||||
t.Fatalf("Expecting to NOT find pod \"%s/%s\" having mandatory, inexistant secrets.", pod.Namespace, pod.Name)
|
||||
}
|
||||
}
|
||||
|
||||
// TestCreatePodWithOptionalInexistantConfigMap tries to create a pod referencing optional, inexistant config map.
|
||||
// It then verifies that the pod is created successfully.
|
||||
func TestCreatePodWithOptionalInexistantConfigMap(t *testing.T) {
|
||||
// Create a pod with a single container referencing optional, inexistant config map.
|
||||
pod, err := f.CreatePod(f.CreatePodObjectWithOptionalConfigMapKey())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Delete the pod after the test finishes.
|
||||
defer func() {
|
||||
if err := f.DeletePod(pod.Namespace, pod.Name); err != nil && !apierrors.IsNotFound(err) {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Wait for the pod to be reported as running and ready.
|
||||
if err := f.WaitUntilPodReady(pod.Namespace, pod.Name); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Check that the pod is known to the provider.
|
||||
stats, err := f.GetStatsSummary()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := findPodInPodStats(stats, pod); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestCreatePodWithMandatoryInexistantConfigMap tries to create a pod referencing inexistant secrets.
|
||||
// It then verifies that the pod is not created.
|
||||
func TestCreatePodWithMandatoryInexistantConfigMap(t *testing.T) {
|
||||
// Create a pod with a single container referencing inexistant config map.
|
||||
pod, err := f.CreatePod(f.CreatePodObjectWithMandatoryConfigMapKey())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Delete the pod after the test finishes.
|
||||
defer func() {
|
||||
if err := f.DeletePodImmediately(pod.Namespace, pod.Name); err != nil && !apierrors.IsNotFound(err) {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Wait for a small period so we can later assert the pod is not running.
|
||||
// TODO (@pires) Wait for event to be reported.
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
// Check that the pod is NOT known to the provider.
|
||||
stats, err := f.GetStatsSummary()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := findPodInPodStats(stats, pod); err == nil {
|
||||
t.Fatalf("Expecting to NOT find pod \"%s/%s\" having mandatory, inexistant config map.", pod.Namespace, pod.Name)
|
||||
}
|
||||
}
|
||||
|
||||
// findPodInPodStats returns the index of the specified pod in the .pods field of the specified Summary object.
|
||||
// It returns an error if the specified pod is not found.
|
||||
func findPodInPodStats(summary *v1alpha1.Summary, pod *v1.Pod) (int, error) {
|
||||
|
||||
81
test/e2e/framework/env.go
Normal file
81
test/e2e/framework/env.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user