|
15 | 15 | package argocompiler
|
16 | 16 |
|
17 | 17 | import (
|
| 18 | + "os" |
18 | 19 | "testing"
|
19 | 20 |
|
20 | 21 | wfapi "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
|
21 | 22 | "github.com/kubeflow/pipelines/kubernetes_platform/go/kubernetesplatform"
|
22 | 23 | "github.com/stretchr/testify/assert"
|
23 | 24 | )
|
24 | 25 |
|
| 26 | +func TestAddContainerExecutorTemplate(t *testing.T) { |
| 27 | + tests := []struct { |
| 28 | + name string |
| 29 | + configMapName string |
| 30 | + configMapKey string |
| 31 | + mountPath string |
| 32 | + expectedVolumeName string |
| 33 | + expectedConfigMapName string |
| 34 | + expectedMountPath string |
| 35 | + }{ |
| 36 | + { |
| 37 | + name: "Test with valid settings", |
| 38 | + configMapName: "kube-root-ca.crt", |
| 39 | + configMapKey: "ca.crt", |
| 40 | + mountPath: "/etc/ssl/custom", |
| 41 | + expectedVolumeName: "ca-bundle", |
| 42 | + expectedConfigMapName: "kube-root-ca.crt", |
| 43 | + expectedMountPath: "/etc/ssl/custom/ca.crt", |
| 44 | + }, |
| 45 | + } |
| 46 | + |
| 47 | + for _, tt := range tests { |
| 48 | + t.Run(tt.name, func(t *testing.T) { |
| 49 | + os.Setenv("EXECUTOR_CABUNDLE_CONFIGMAP_NAME", tt.configMapName) |
| 50 | + os.Setenv("EXECUTOR_CABUNDLE_CONFIGMAP_KEY", tt.configMapKey) |
| 51 | + os.Setenv("EXECUTOR_CABUNDLE_MOUNTPATH", tt.mountPath) |
| 52 | + |
| 53 | + c := &workflowCompiler{ |
| 54 | + templates: make(map[string]*wfapi.Template), |
| 55 | + wf: &wfapi.Workflow{ |
| 56 | + Spec: wfapi.WorkflowSpec{ |
| 57 | + Templates: []wfapi.Template{}, |
| 58 | + }, |
| 59 | + }, |
| 60 | + } |
| 61 | + |
| 62 | + c.addContainerExecutorTemplate("test-ref") |
| 63 | + assert.NotEmpty(t, "system-container-impl", "Template name should not be empty") |
| 64 | + |
| 65 | + executorTemplate, exists := c.templates["system-container-impl"] |
| 66 | + assert.True(t, exists, "Template should exist with the returned name") |
| 67 | + assert.NotNil(t, executorTemplate, "Executor template should not be nil") |
| 68 | + |
| 69 | + foundVolume := false |
| 70 | + for _, volume := range executorTemplate.Volumes { |
| 71 | + if volume.Name == tt.expectedVolumeName { |
| 72 | + foundVolume = true |
| 73 | + assert.Equal(t, tt.expectedConfigMapName, volume.VolumeSource.ConfigMap.Name, "ConfigMap name should match") |
| 74 | + break |
| 75 | + } |
| 76 | + } |
| 77 | + assert.True(t, foundVolume, "CA bundle volume should be included in the template") |
| 78 | + |
| 79 | + foundVolumeMount := false |
| 80 | + if executorTemplate.Container != nil { |
| 81 | + for _, mount := range executorTemplate.Container.VolumeMounts { |
| 82 | + if mount.Name == tt.expectedVolumeName && mount.MountPath == tt.expectedMountPath { |
| 83 | + foundVolumeMount = true |
| 84 | + break |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + assert.True(t, foundVolumeMount, "CA bundle volume mount should be included in the container") |
| 89 | + }) |
| 90 | + } |
| 91 | + defer func() { |
| 92 | + os.Unsetenv("EXECUTOR_CABUNDLE_CONFIGMAP_NAME") |
| 93 | + os.Unsetenv("EXECUTOR_CABUNDLE_CONFIGMAP_KEY") |
| 94 | + os.Unsetenv("EXECUTOR_CABUNDLE_MOUNTPATH") |
| 95 | + }() |
| 96 | + |
| 97 | +} |
| 98 | + |
25 | 99 | func Test_extendPodMetadata(t *testing.T) {
|
26 | 100 | tests := []struct {
|
27 | 101 | name string
|
|
0 commit comments