From 039d2745d827e82ca90593c73562f3639aec335c Mon Sep 17 00:00:00 2001 From: kqzh <35095889+kqzh@users.noreply.github.com> Date: Mon, 23 Oct 2023 15:47:22 +0800 Subject: [PATCH] feat: add volume --- tests/e2e/e2ematcher/e2ematcher.go | 3 + .../envfuncsext/nebulacluster-ready-func.go | 11 +- tests/e2e/nebulacluster_k8s_test.go | 103 ++++++++++++++++++ tests/e2e/nebulacluster_test.go | 9 +- 4 files changed, 116 insertions(+), 10 deletions(-) diff --git a/tests/e2e/e2ematcher/e2ematcher.go b/tests/e2e/e2ematcher/e2ematcher.go index 49e32526..c7b6edbd 100644 --- a/tests/e2e/e2ematcher/e2ematcher.go +++ b/tests/e2e/e2ematcher/e2ematcher.go @@ -38,6 +38,9 @@ func structImpl(preFields []string, actual any, matchers map[string]any) (retErr if m, ok := matcher.(Matcher); ok { for actualVal.Kind() == reflect.Ptr { + if actualVal.IsNil() { + break + } actualVal = actualVal.Elem() } val := actualVal.Interface() diff --git a/tests/e2e/envfuncsext/nebulacluster-ready-func.go b/tests/e2e/envfuncsext/nebulacluster-ready-func.go index 14bbbe96..baa9c42d 100644 --- a/tests/e2e/envfuncsext/nebulacluster-ready-func.go +++ b/tests/e2e/envfuncsext/nebulacluster-ready-func.go @@ -606,8 +606,8 @@ func isComponentStatefulSetExpected(ctx context.Context, cfg *envconf.Config, co }, }, "NodeSelector": e2ematcher.DeepEqual(nodeSelector), - //"Affinity": e2ematcher.DeepEqual(&[]corev1.Affinity{}), - "Tolerations": e2ematcher.DeepEqual(component.ComponentSpec().Tolerations()), + "Affinity": e2ematcher.DeepEqual(affinityPtrOrNil(component.ComponentSpec().Affinity())), + "Tolerations": e2ematcher.DeepEqual(component.ComponentSpec().Tolerations()), }, }, }, @@ -797,3 +797,10 @@ func extractComponentConfig(r io.Reader, paramValuePattern *regexp.Regexp) (map[ } return componentConfig, nil } + +func affinityPtrOrNil(affinity *corev1.Affinity) any { + if affinity == nil { + return affinity + } + return *affinity +} diff --git a/tests/e2e/nebulacluster_k8s_test.go b/tests/e2e/nebulacluster_k8s_test.go index dab7a71e..c21fbe8d 100644 --- a/tests/e2e/nebulacluster_k8s_test.go +++ b/tests/e2e/nebulacluster_k8s_test.go @@ -21,6 +21,7 @@ const ( LabelGroupK8sTolerations = "tolerations" LabelGroupK8sInitContainers = "initContainers" LabelGroupK8sSidecarContainers = "sidecarContainers" + LabelGroupK8sVolumes = "volumes" LabelGroupK8sReadinessProbe = "readinessProbe" LabelGroupK8sLivenessProbe = "livenessProbe" ) @@ -36,6 +37,7 @@ func init() { testCasesK8s = append(testCasesK8s, testCaseK8sTolerations...) testCasesK8s = append(testCasesK8s, testCaseK8sInitContainers...) testCasesK8s = append(testCasesK8s, testCaseK8sSidecarContainers...) + testCasesK8s = append(testCasesK8s, testCaseK8sVolumes...) testCasesK8s = append(testCasesK8s, testCaseK8sReadinessProbe...) testCasesK8s = append(testCasesK8s, testCaseK8sLivenessProbe...) } @@ -801,3 +803,104 @@ var testCaseK8sLivenessProbe = []ncTestCase{ }, }, } + +var testCaseK8sVolumes = []ncTestCase{ + { + Name: "k8s volumes with default values", + Labels: map[string]string{ + LabelKeyCategory: LabelCategoryK8s, + LabelKeyGroup: LabelGroupK8sVolumes, + }, + InstallWaitNCOptions: []envfuncsext.NebulaClusterOption{ + envfuncsext.WithNebulaClusterReadyFuncs( + envfuncsext.DefaultNebulaClusterReadyFunc, + ), + }, + UpgradeCases: []ncTestUpgradeCase{ + { + Name: "update components volumes", + UpgradeNCOptions: []envfuncsext.NebulaClusterOption{ + envfuncsext.WithNebulaClusterHelmRawOptions( + helm.WithArgs( + "--set", "nebula.graphd.volumes[0].name=test-volume", + "--set", "nebula.graphd.volumes[0].emptyDir.medium=Memory", + "--set", "nebula.graphd.volumeMounts[0].name=test-volume", + "--set", "nebula.graphd.volumeMounts[0].mountPath=/test", + "--set", "nebula.storaged.volumes[0].name=test-volume", + "--set", "nebula.storaged.volumes[0].emptyDir.medium=Memory", + "--set", "nebula.storaged.volumeMounts[0].name=test-volume", + "--set", "nebula.storaged.volumeMounts[0].mountPath=/test", + "--set", "nebula.metad.volumes[0].name=test-volume", + "--set", "nebula.metad.volumes[0].emptyDir.medium=Memory", + "--set", "nebula.metad.volumeMounts[0].name=test-volume", + "--set", "nebula.metad.volumeMounts[0].mountPath=/test", + ), + ), + }, + UpgradeWaitNCOptions: []envfuncsext.NebulaClusterOption{ + envfuncsext.WithNebulaClusterReadyFuncs( + envfuncsext.NebulaClusterReadyFuncForFields(true, map[string]any{ + "Spec": map[string]any{ + "Graphd": map[string]any{ + "Volumes": e2ematcher.DeepEqual([]corev1.Volume{ + { + Name: "test-volume", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{ + Medium: corev1.StorageMediumMemory, + }, + }, + }, + }), + "VolumeMounts": e2ematcher.DeepEqual([]corev1.VolumeMount{ + { + Name: "test-volume", + MountPath: "/test", + }, + }), + }, + "Storaged": map[string]any{ + "Volumes": e2ematcher.DeepEqual([]corev1.Volume{ + { + Name: "test-volume", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{ + Medium: corev1.StorageMediumMemory, + }, + }, + }, + }), + "VolumeMounts": e2ematcher.DeepEqual([]corev1.VolumeMount{ + { + Name: "test-volume", + MountPath: "/test", + }, + }), + }, + "Metad": map[string]any{ + "Volumes": e2ematcher.DeepEqual([]corev1.Volume{ + { + Name: "test-volume", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{ + Medium: corev1.StorageMediumMemory, + }, + }, + }, + }), + "VolumeMounts": e2ematcher.DeepEqual([]corev1.VolumeMount{ + { + Name: "test-volume", + MountPath: "/test", + }, + }), + }, + }, + }), + envfuncsext.DefaultNebulaClusterReadyFunc, + ), + }, + }, + }, + }, +} diff --git a/tests/e2e/nebulacluster_test.go b/tests/e2e/nebulacluster_test.go index 5043852f..eec2667c 100644 --- a/tests/e2e/nebulacluster_test.go +++ b/tests/e2e/nebulacluster_test.go @@ -36,14 +36,6 @@ import ( "github.com/vesoft-inc/nebula-operator/tests/e2e/envfuncsext" ) -var ncGlobalTestCases []ncTestCase - -func init() { - ncGlobalTestCases = append(ncGlobalTestCases, testCasesBasic...) - ncGlobalTestCases = append(ncGlobalTestCases, testCasesCustomConfig...) - ncGlobalTestCases = append(ncGlobalTestCases, testCasesK8s...) -} - type ( ncTestCase struct { Name string @@ -69,6 +61,7 @@ func TestNebulaCluster(t *testing.T) { ncTestCases = append(ncTestCases, testCasesTools...) ncTestCases = append(ncTestCases, testCasesZone...) ncTestCases = append(ncTestCases, testCasesPV...) + ncTestCases = append(ncTestCases, testCasesK8s...) defaultNebulaClusterHelmArgs := getDefaultNebulaClusterHelmArgs()