Skip to content

Commit

Permalink
Check initContainers if they have env vars from a configmap or a secret
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandar Milanov committed Dec 9, 2024
1 parent ab12334 commit 751571f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/kor/configmaps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ func createTestConfigmaps(t *testing.T) *fake.Clientset {
},
}

pod5 := CreateTestPod(testNamespace, "pod-5", "", nil, AppLabels)
pod5.Spec.InitContainers = []corev1.Container{
{
EnvFrom: []corev1.EnvFromSource{
{
ConfigMapRef: &corev1.ConfigMapEnvSource{LocalObjectReference: corev1.LocalObjectReference{Name: configmap6.ObjectMeta.Name}},
},
},
},
}

_, err = clientset.CoreV1().Pods(testNamespace).Create(context.TODO(), pod1, metav1.CreateOptions{})
if err != nil {
t.Fatalf("Error creating fake pod: %v", err)
Expand All @@ -129,6 +140,11 @@ func createTestConfigmaps(t *testing.T) *fake.Clientset {
t.Fatalf("Error creating fake pod: %v", err)
}

_, err = clientset.CoreV1().Pods(testNamespace).Create(context.TODO(), pod5, metav1.CreateOptions{})
if err != nil {
t.Fatalf("Error creating fake pod: %v", err)
}

return clientset
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/kor/secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ func createTestSecrets(t *testing.T) *fake.Clientset {
{Name: secret2.ObjectMeta.Name},
}

pod7 := CreateTestPod(testNamespace, "pod-7", "", nil, AppLabels)
pod7.Spec.InitContainers = []corev1.Container{
{
EnvFrom: []corev1.EnvFromSource{
{SecretRef: &corev1.SecretEnvSource{LocalObjectReference: corev1.LocalObjectReference{Name: secret6.ObjectMeta.Name}}},
},
},
}

_, err = clientset.CoreV1().Pods(testNamespace).Create(context.TODO(), pod1, v1.CreateOptions{})
if err != nil {
t.Fatalf("Error creating fake pod: %v", err)
Expand Down Expand Up @@ -121,6 +130,11 @@ func createTestSecrets(t *testing.T) *fake.Clientset {
t.Fatalf("Error creating fake pod: %v", err)
}

_, err = clientset.CoreV1().Pods(testNamespace).Create(context.TODO(), pod7, v1.CreateOptions{})
if err != nil {
t.Fatalf("Error creating fake pod: %v", err)
}

_, err = clientset.CoreV1().Secrets(testNamespace).Create(context.TODO(), secret1, v1.CreateOptions{})
if err != nil {
t.Fatalf("Error creating fake %s: %v", "Secret", err)
Expand Down

0 comments on commit 751571f

Please sign in to comment.