diff --git a/Jenkinsfile b/Jenkinsfile index b19042b..ee0c370 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -124,13 +124,24 @@ void runTests() { sh "make test" } -void runE2eTests() { +void runMinikubeSetup() { sh ''' make e2e-setup-minikube + ''' +} + +void runE2eTests() { + sh ''' make e2e-test ''' } +void runMinikubeCleanup() { + sh ''' + make e2e-cleanup-minikube + ''' +} + pipeline { agent { label { @@ -167,11 +178,23 @@ pipeline { } } - stage('Run-e2e-tests') { + stage('Run-Minikube-Setup') { + steps { + runMinikubeSetup() + } + } + + stage('Run-e2e-Tests') { steps { runE2eTests() } } + + stage('Cleanup Environment') { + steps { + runMinikubeCleanup() + } + } } diff --git a/Makefile b/Makefile index 72098b4..368f602 100644 --- a/Makefile +++ b/Makefile @@ -125,14 +125,34 @@ test: manifests generate fmt vet envtest ## Run tests. # Utilize minikube or modify the e2e tests to load the image locally, enabling compatibility with other vendors. .PHONY: e2e-test # Run the e2e tests against a minikube k8s instance that is spun up. e2e-test: - go test -v -count=1 ./test/e2e - minikube delete || true + @echo "=====Setting hugepages value to 1280 for hugepages-e2e test" + sudo sysctl -w vm.nr_hugepages=1280 + + @echo "=====Restart minikube cluster to apply hugepages value" + minikube stop + minikube start + + @echo "=====Running e2e test including hugepages test" + go test -v -count=1 ./test/e2e -verifyHugePages + @echo "=====Resetting hugepages value to 0" + sudo sysctl -w vm.nr_hugepages=0 + + @echo "=====Restart minikube cluster" + minikube stop + minikube start + +.PHONY: e2e-setup-minikube e2e-setup-minikube: kustomize controller-gen build docker-build minikube delete || true minikube start --driver=docker --kubernetes-version=$(E2E_KUBERNETES_VERSION) --memory=8192 --cpus=2 minikube addons enable ingress minikube image load $(IMG) + +.PHONY: e2e-cleanup-minikube +e2e-cleanup-minikube: + @echo "=====Delete minikube cluster" + minikube delete GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint GOLANGCI_LINT_VERSION ?= v1.54.2 diff --git a/test/e2e/2_marklogic_cluster_test.go b/test/e2e/2_marklogic_cluster_test.go index 1bd4090..e8a1c0e 100644 --- a/test/e2e/2_marklogic_cluster_test.go +++ b/test/e2e/2_marklogic_cluster_test.go @@ -2,10 +2,15 @@ package e2e import ( "context" + "flag" + "fmt" + "strings" "testing" "time" databasev1alpha1 "github.com/marklogic/marklogic-kubernetes-operator/api/v1alpha1" + coreV1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/marklogic/marklogic-kubernetes-operator/test/utils" @@ -16,7 +21,7 @@ import ( "sigs.k8s.io/e2e-framework/pkg/features" ) -var replicas = int32(1) +var verifyHugePages = flag.Bool("verifyHugePages", false, "Test hugePages configuration") const ( groupName = "node" @@ -24,6 +29,9 @@ const ( ) var ( + replicas = int32(1) + adminUsername = "admin" + adminPassword = "Admin@8001" marklogiccluster = &databasev1alpha1.MarklogicCluster{ TypeMeta: metav1.TypeMeta{ APIVersion: "marklogic.com/v1alpha1", @@ -35,6 +43,10 @@ var ( }, Spec: databasev1alpha1.MarklogicClusterSpec{ Image: marklogicImage, + Auth: &databasev1alpha1.AdminAuth{ + AdminUsername: &adminUsername, + AdminPassword: &adminPassword, + }, MarkLogicGroups: []*databasev1alpha1.MarklogicGroups{ { Name: groupName, @@ -93,6 +105,55 @@ func TestMarklogicCluster(t *testing.T) { }) + // Run hugepages verification tests if verifyHugePages flag is set + if *verifyHugePages { + t.Log("Running HugePages verification tests") + + // Update the MarkLogic group resources + feature.Setup(func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context { + t.Log("Updating MarkLogic group resources") + client := c.Client() + var mlcluster databasev1alpha1.MarklogicCluster + var resources = coreV1.ResourceRequirements{ + Requests: coreV1.ResourceList{ + "memory": resource.MustParse("8Gi"), + }, + Limits: coreV1.ResourceList{ + "memory": resource.MustParse("8Gi"), + "hugepages-2Mi": resource.MustParse("1Gi"), + }, + } + if err := client.Resources().Get(ctx, "marklogicclusters", mlNamespace, &mlcluster); err != nil { + t.Fatal(err) + } + + mlcluster.Spec.MarkLogicGroups[0].Resources = &resources + if err := client.Resources().Update(ctx, &mlcluster); err != nil { + t.Log("Failed to update MarkLogic group resources") + t.Fatal(err) + } + return ctx + }) + + // Assessment to verify the hugepages is configured + feature.Assess("Verify Huge pages", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context { + podName := "node-0" + containerName := "marklogic-server" + cmd := fmt.Sprintf("cat /var/opt/MarkLogic/Logs/ErrorLog.txt") + + output, err := utils.ExecCmdInPod(podName, mlNamespace, containerName, cmd) + if err != nil { + t.Fatalf("Failed to execute kubectl command in pod: %v", err) + } + expectedOutput := "Linux Huge Pages: detected 1280" + + if !strings.Contains(string(output), expectedOutput) { + t.Fatal("Huge Pages not configured for the MarLogic node") + } + return ctx + }) + } + // Using feature.Teardown to clean up feature.Teardown(func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context { return ctx diff --git a/test/e2e/3_ml_cluster_ednode_test.go b/test/e2e/3_ml_cluster_ednode_test.go index 985a9c3..d679a4f 100644 --- a/test/e2e/3_ml_cluster_ednode_test.go +++ b/test/e2e/3_ml_cluster_ednode_test.go @@ -31,8 +31,6 @@ var ( home = homedir.HomeDir() initialPodCount int incrReplica = int32(2) - adminUsername = "admin" - adminPassword = "Admin@8001" marklogicgroups = []*databasev1alpha1.MarklogicGroups{ { Name: dnodeGrpName,