Skip to content

Commit 4706e50

Browse files
MLE-17366: K8s Operator: E2E test to verify MarkLogic Cluster with huge pages (#43)
* e2e tests for huge pages
1 parent d4254c9 commit 4706e50

File tree

4 files changed

+109
-7
lines changed

4 files changed

+109
-7
lines changed

Jenkinsfile

+25-2
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,24 @@ void runTests() {
124124
sh "make test"
125125
}
126126

127-
void runE2eTests() {
127+
void runMinikubeSetup() {
128128
sh '''
129129
make e2e-setup-minikube
130+
'''
131+
}
132+
133+
void runE2eTests() {
134+
sh '''
130135
make e2e-test
131136
'''
132137
}
133138

139+
void runMinikubeCleanup() {
140+
sh '''
141+
make e2e-cleanup-minikube
142+
'''
143+
}
144+
134145
pipeline {
135146
agent {
136147
label {
@@ -167,11 +178,23 @@ pipeline {
167178
}
168179
}
169180

170-
stage('Run-e2e-tests') {
181+
stage('Run-Minikube-Setup') {
182+
steps {
183+
runMinikubeSetup()
184+
}
185+
}
186+
187+
stage('Run-e2e-Tests') {
171188
steps {
172189
runE2eTests()
173190
}
174191
}
192+
193+
stage('Cleanup Environment') {
194+
steps {
195+
runMinikubeCleanup()
196+
}
197+
}
175198

176199
}
177200

Makefile

+22-2
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,34 @@ test: manifests generate fmt vet envtest ## Run tests.
125125
# Utilize minikube or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
126126
.PHONY: e2e-test # Run the e2e tests against a minikube k8s instance that is spun up.
127127
e2e-test:
128-
go test -v -count=1 ./test/e2e
129-
minikube delete || true
128+
@echo "=====Setting hugepages value to 1280 for hugepages-e2e test"
129+
sudo sysctl -w vm.nr_hugepages=1280
130+
131+
@echo "=====Restart minikube cluster to apply hugepages value"
132+
minikube stop
133+
minikube start
134+
135+
@echo "=====Running e2e test including hugepages test"
136+
go test -v -count=1 ./test/e2e -verifyHugePages
130137

138+
@echo "=====Resetting hugepages value to 0"
139+
sudo sysctl -w vm.nr_hugepages=0
140+
141+
@echo "=====Restart minikube cluster"
142+
minikube stop
143+
minikube start
144+
145+
.PHONY: e2e-setup-minikube
131146
e2e-setup-minikube: kustomize controller-gen build docker-build
132147
minikube delete || true
133148
minikube start --driver=docker --kubernetes-version=$(E2E_KUBERNETES_VERSION) --memory=8192 --cpus=2
134149
minikube addons enable ingress
135150
minikube image load $(IMG)
151+
152+
.PHONY: e2e-cleanup-minikube
153+
e2e-cleanup-minikube:
154+
@echo "=====Delete minikube cluster"
155+
minikube delete
136156

137157
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
138158
GOLANGCI_LINT_VERSION ?= v1.54.2

test/e2e/2_marklogic_cluster_test.go

+62-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ package e2e
22

33
import (
44
"context"
5+
"flag"
6+
"fmt"
7+
"strings"
58
"testing"
69
"time"
710

811
databasev1alpha1 "github.com/marklogic/marklogic-kubernetes-operator/api/v1alpha1"
12+
coreV1 "k8s.io/api/core/v1"
13+
"k8s.io/apimachinery/pkg/api/resource"
914
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1015

1116
"github.com/marklogic/marklogic-kubernetes-operator/test/utils"
@@ -16,14 +21,17 @@ import (
1621
"sigs.k8s.io/e2e-framework/pkg/features"
1722
)
1823

19-
var replicas = int32(1)
24+
var verifyHugePages = flag.Bool("verifyHugePages", false, "Test hugePages configuration")
2025

2126
const (
2227
groupName = "node"
2328
mlNamespace = "default"
2429
)
2530

2631
var (
32+
replicas = int32(1)
33+
adminUsername = "admin"
34+
adminPassword = "Admin@8001"
2735
marklogiccluster = &databasev1alpha1.MarklogicCluster{
2836
TypeMeta: metav1.TypeMeta{
2937
APIVersion: "marklogic.com/v1alpha1",
@@ -35,6 +43,10 @@ var (
3543
},
3644
Spec: databasev1alpha1.MarklogicClusterSpec{
3745
Image: marklogicImage,
46+
Auth: &databasev1alpha1.AdminAuth{
47+
AdminUsername: &adminUsername,
48+
AdminPassword: &adminPassword,
49+
},
3850
MarkLogicGroups: []*databasev1alpha1.MarklogicGroups{
3951
{
4052
Name: groupName,
@@ -93,6 +105,55 @@ func TestMarklogicCluster(t *testing.T) {
93105

94106
})
95107

108+
// Run hugepages verification tests if verifyHugePages flag is set
109+
if *verifyHugePages {
110+
t.Log("Running HugePages verification tests")
111+
112+
// Update the MarkLogic group resources
113+
feature.Setup(func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
114+
t.Log("Updating MarkLogic group resources")
115+
client := c.Client()
116+
var mlcluster databasev1alpha1.MarklogicCluster
117+
var resources = coreV1.ResourceRequirements{
118+
Requests: coreV1.ResourceList{
119+
"memory": resource.MustParse("8Gi"),
120+
},
121+
Limits: coreV1.ResourceList{
122+
"memory": resource.MustParse("8Gi"),
123+
"hugepages-2Mi": resource.MustParse("1Gi"),
124+
},
125+
}
126+
if err := client.Resources().Get(ctx, "marklogicclusters", mlNamespace, &mlcluster); err != nil {
127+
t.Fatal(err)
128+
}
129+
130+
mlcluster.Spec.MarkLogicGroups[0].Resources = &resources
131+
if err := client.Resources().Update(ctx, &mlcluster); err != nil {
132+
t.Log("Failed to update MarkLogic group resources")
133+
t.Fatal(err)
134+
}
135+
return ctx
136+
})
137+
138+
// Assessment to verify the hugepages is configured
139+
feature.Assess("Verify Huge pages", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
140+
podName := "node-0"
141+
containerName := "marklogic-server"
142+
cmd := fmt.Sprintf("cat /var/opt/MarkLogic/Logs/ErrorLog.txt")
143+
144+
output, err := utils.ExecCmdInPod(podName, mlNamespace, containerName, cmd)
145+
if err != nil {
146+
t.Fatalf("Failed to execute kubectl command in pod: %v", err)
147+
}
148+
expectedOutput := "Linux Huge Pages: detected 1280"
149+
150+
if !strings.Contains(string(output), expectedOutput) {
151+
t.Fatal("Huge Pages not configured for the MarLogic node")
152+
}
153+
return ctx
154+
})
155+
}
156+
96157
// Using feature.Teardown to clean up
97158
feature.Teardown(func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
98159
return ctx

test/e2e/3_ml_cluster_ednode_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ var (
3131
home = homedir.HomeDir()
3232
initialPodCount int
3333
incrReplica = int32(2)
34-
adminUsername = "admin"
35-
adminPassword = "Admin@8001"
3634
marklogicgroups = []*databasev1alpha1.MarklogicGroups{
3735
{
3836
Name: dnodeGrpName,

0 commit comments

Comments
 (0)