Skip to content

Commit

Permalink
Add unit test to check the certificate mounting
Browse files Browse the repository at this point in the history
Signed-off-by: ddalvi <ddalvi@redhat.com>
  • Loading branch information
DharmitD committed Jun 13, 2024
1 parent d08cf0e commit 34945bb
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 2 deletions.
5 changes: 3 additions & 2 deletions backend/src/v2/compiler/argocompiler/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand All @@ -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,
}
Expand Down
82 changes: 82 additions & 0 deletions backend/src/v2/compiler/argocompiler/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,95 @@
package argocompiler

import (
"os"
"testing"

wfapi "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
"github.com/kubeflow/pipelines/kubernetes_platform/go/kubernetesplatform"
"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
Expand Down

0 comments on commit 34945bb

Please sign in to comment.