diff --git a/backend/src/v2/compiler/argocompiler/container.go b/backend/src/v2/compiler/argocompiler/container.go index d412c08b59b0..14ed4f706796 100644 --- a/backend/src/v2/compiler/argocompiler/container.go +++ b/backend/src/v2/compiler/argocompiler/container.go @@ -29,6 +29,7 @@ import ( const ( volumeNameKFPLauncher = "kfp-launcher" + volumeNameCABundle = "ca-bundle" DefaultLauncherImage = "gcr.io/ml-pipeline/kfp-launcher@sha256:8fe5e6e4718f20b021736022ad3741ddf2abd82aa58c86ae13e89736fdc3f08f" LauncherImageEnvVar = "V2_LAUNCHER_IMAGE" DefaultDriverImage = "gcr.io/ml-pipeline/kfp-driver@sha256:3c0665cd36aa87e4359a4c8b6271dcba5bdd817815cd0496ed12eb5dde5fd2ec" @@ -395,7 +396,7 @@ func (c *workflowCompiler) addContainerExecutorTemplate(refName string) string { Value: sslCertDir, }) volume := k8score.Volume{ - Name: volumeNameCABUndle, + Name: volumeNameCABundle, VolumeSource: k8score.VolumeSource{ ConfigMap: &k8score.ConfigMapVolumeSource{ LocalObjectReference: k8score.LocalObjectReference{ @@ -408,7 +409,7 @@ func (c *workflowCompiler) addContainerExecutorTemplate(refName string) string { executor.Volumes = append(executor.Volumes, volume) volumeMount := k8score.VolumeMount{ - Name: volumeNameCABUndle, + Name: volumeNameCABundle, MountPath: caFile, SubPath: caBundleCfgMapKey, } diff --git a/backend/src/v2/compiler/argocompiler/container_test.go b/backend/src/v2/compiler/argocompiler/container_test.go index f242d87a188d..fb31bcd37035 100644 --- a/backend/src/v2/compiler/argocompiler/container_test.go +++ b/backend/src/v2/compiler/argocompiler/container_test.go @@ -15,6 +15,7 @@ package argocompiler import ( + "os" "testing" wfapi "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" @@ -22,6 +23,87 @@ import ( "github.com/stretchr/testify/assert" ) +func TestAddContainerExecutorTemplate(t *testing.T) { + tests := []struct { + name string + configMapName string + configMapKey string + mountPath string + expectedVolumeName string + expectedConfigMapName string + expectedMountPath string + }{ + { + name: "Test with valid settings", + configMapName: "kube-root-ca.crt", + configMapKey: "ca.crt", + mountPath: "/etc/ssl/custom", + expectedVolumeName: "ca-bundle", + expectedConfigMapName: "kube-root-ca.crt", + expectedMountPath: "/etc/ssl/custom/ca.crt", + }, + // You can add more test cases here + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // Setup the environment variables for testing + os.Setenv("EXECUTOR_CABUNDLE_CONFIGMAP_NAME", tt.configMapName) + os.Setenv("EXECUTOR_CABUNDLE_CONFIGMAP_KEY", tt.configMapKey) + os.Setenv("EXECUTOR_CABUNDLE_MOUNTPATH", tt.mountPath) + + defer func() { + // Clean up environment variables + os.Unsetenv("EXECUTOR_CABUNDLE_CONFIGMAP_NAME") + os.Unsetenv("EXECUTOR_CABUNDLE_CONFIGMAP_KEY") + os.Unsetenv("EXECUTOR_CABUNDLE_MOUNTPATH") + }() + + // Creating an instance of workflowCompiler with properly initialized members + c := &workflowCompiler{ + templates: make(map[string]*wfapi.Template), + wf: &wfapi.Workflow{ + Spec: wfapi.WorkflowSpec{ + Templates: []wfapi.Template{}, + }, + }, + } + + // Call the function with a reference name + templateName := c.addContainerExecutorTemplate("test-ref") + assert.NotEmpty(t, templateName, "Template name should not be empty") + + // Fetch the template and check existence + executorTemplate, exists := c.templates[templateName] + assert.True(t, exists, "Template should exist with the returned name") + assert.NotNil(t, executorTemplate, "Executor template should not be nil") + + // Check Volumes + foundVolume := false + for _, volume := range executorTemplate.Volumes { + if volume.Name == tt.expectedVolumeName { + foundVolume = true + assert.Equal(t, tt.expectedConfigMapName, volume.VolumeSource.ConfigMap.Name, "ConfigMap name should match") + break + } + } + assert.True(t, foundVolume, "CA bundle volume should be included in the template") + + // Check VolumeMounts in the container + foundVolumeMount := false + if executorTemplate.Container != nil { + for _, mount := range executorTemplate.Container.VolumeMounts { + if mount.Name == tt.expectedVolumeName && mount.MountPath == tt.expectedMountPath { + foundVolumeMount = true + break + } + } + } + assert.True(t, foundVolumeMount, "CA bundle volume mount should be included in the container") + }) + } +} + func Test_extendPodMetadata(t *testing.T) { tests := []struct { name string