Skip to content

Commit 643f3ee

Browse files
pengzhoumlPeng Zhou
andauthored
MLE-22135 Port Helm change to Operator (#93)
* MLE-22135: change liveness probe * add retry logic to group configuration * update haproxy image * adjust testing time * update marklogic image version * remove image * update image version in Jenkins * fix makefile for pipeline * fix validate rule and image load * push changes from build * MLE-22902: fix operator pipeline bug * ignore docker cache * fix validating rule * add debug message for Jenkins Pipeline * fix test with bug: index out of range [0] with length 0 * fix test bug with index out of range [1] with length 1 * add debug info * revert changes back to makefile * uncomment changes --------- Co-authored-by: Peng Zhou <[email protected]>
1 parent b726317 commit 643f3ee

File tree

11 files changed

+60
-46
lines changed

11 files changed

+60
-46
lines changed

Jenkinsfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ pipeline {
164164
// }
165165

166166
parameters {
167-
string(name: 'dockerImage', defaultValue: 'ml-docker-db-dev-tierpoint.bed-artifactory.bedford.progress.com/marklogic/marklogic-server-ubi:latest-11', description: 'Docker image to use for tests.', trim: true)
167+
string(name: 'E2E_MARKLOGIC_IMAGE_VERSION', defaultValue: 'ml-docker-db-dev-tierpoint.bed-artifactory.bedford.progress.com/marklogic/marklogic-server-ubi-rootless:latest-12', description: 'Docker image to use for tests.', trim: true)
168+
string(name: 'IMG', defaultValue: 'testrepo/marklogic-operator-image-dev:internal', description: 'Docker image for Running Operator Container', trim: true)
168169
string(name: 'emailList', defaultValue: emailList, description: 'List of email for build notification', trim: true)
169170
}
170171

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ VERIFY_HUGE_PAGES ?= false
1111
export E2E_DOCKER_IMAGE ?= $(IMG)
1212
export E2E_KUSTOMIZE_VERSION ?= $(KUSTOMIZE_VERSION)
1313
export E2E_CONTROLLER_TOOLS_VERSION ?= $(CONTROLLER_TOOLS_VERSION)
14-
export E2E_MARKLOGIC_IMAGE_VERSION ?= progressofficial/marklogic-db:11.3.1-ubi-rootless-2.1.0
14+
export E2E_MARKLOGIC_IMAGE_VERSION ?= progressofficial/marklogic-db:11.3.1-ubi-rootless-2.1.3
1515
export E2E_KUBERNETES_VERSION ?= v1.31.0
1616

1717
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
@@ -65,7 +65,8 @@ OPERATOR_SDK_VERSION ?= v1.34.2
6565

6666
# Image URL to use all building/pushing image targets
6767
# Image for dev: ml-marklogic-operator-dev.bed-artifactory.bedford.progress.com/marklogic-operator-kubernetes
68-
IMG ?= progressofficial/marklogic-operator-kubernetes:$(VERSION)
68+
# IMG ?= progressofficial/marklogic-operator-kubernetes:$(VERSION)
69+
IMG = "testrepo/marklogic-operator-image-dev:1.0.0"
6970

7071

7172
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
@@ -162,6 +163,9 @@ e2e-setup-minikube: kustomize controller-gen build docker-build
162163
minikube start --driver=docker --kubernetes-version=$(E2E_KUBERNETES_VERSION) --memory=8192 --cpus=2
163164
minikube addons enable ingress
164165
minikube image load $(IMG)
166+
minikube image load $(E2E_MARKLOGIC_IMAGE_VERSION)
167+
minikube image load "docker.io/haproxytech/haproxy-alpine:3.2"
168+
minikube image ls
165169

166170
.PHONY: e2e-cleanup-minikube
167171
e2e-cleanup-minikube:

api/v1/marklogiccluster_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727

2828
// MarklogicClusterSpec defines the desired state of MarklogicCluster
2929

30-
// +kubebuilder:validation:XValidation:rule="!(self.haproxy.enabled == true && self.haproxy.pathBasedRouting == true) || int(self.image.split(':')[1].split('.')[0] + self.image.split(':')[1].split('.')[1]) >= 111", message="HAProxy and Pathbased Routing is enabled. PathBasedRouting is only supported for MarkLogic 11.1 and above"
30+
// +kubebuilder:validation:XValidation:rule="!(self.haproxy.enabled == true && self.haproxy.pathBasedRouting == true) || self.image.split(':')[1].matches('.*latest.*') || int(self.image.split(':')[1].split('.')[0] + self.image.split(':')[1].split('.')[1]) >= 111", message="HAProxy and Pathbased Routing is enabled. PathBasedRouting is only supported for MarkLogic 11.1 and above"
3131
type MarklogicClusterSpec struct {
3232
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
3333
// Important: Run "make" to regenerate code after modifying this file

config/crd/bases/marklogic.progress.com_marklogicclusters.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11037,7 +11037,8 @@ spec:
1103711037
- message: HAProxy and Pathbased Routing is enabled. PathBasedRouting
1103811038
is only supported for MarkLogic 11.1 and above
1103911039
rule: '!(self.haproxy.enabled == true && self.haproxy.pathBasedRouting
11040-
== true) || int(self.image.split('':'')[1].split(''.'')[0] + self.image.split('':'')[1].split(''.'')[1])
11040+
== true) || self.image.split('':'')[1].matches(''.*latest.*'') ||
11041+
int(self.image.split('':'')[1].split(''.'')[0] + self.image.split('':'')[1].split(''.'')[1])
1104111042
>= 111'
1104211043
status:
1104311044
description: MarklogicClusterStatus defines the observed state of MarklogicCluster

pkg/k8sutil/scripts/liveness-probe.sh

Lines changed: 0 additions & 31 deletions
This file was deleted.

pkg/k8sutil/scripts/poststart-hook.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ log () {
5353
echo $message >> /tmp/script.log
5454
}
5555

56+
# Function to retry a command based on the return code
57+
# $1: The number of retries
58+
# $2: The command to run
59+
retry() {
60+
local retries=$1
61+
shift
62+
local count=0
63+
until "$@"; do
64+
exit_code=$?
65+
count=$((count + 1))
66+
if [ $count -ge $retries ]; then
67+
echo "Command failed after $retries attempts."
68+
return $exit_code
69+
fi
70+
echo "Attempt $count failed. Retrying..."
71+
sleep 5
72+
done
73+
}
74+
5675
###############################################################
5776
# Function to get the current host protocol
5877
# $1: The host name
@@ -699,10 +718,10 @@ if [[ "$IS_BOOTSTRAP_HOST" == "true" ]]; then
699718
if [[ "${MARKLOGIC_CLUSTER_TYPE}" == "bootstrap" ]]; then
700719
log "Info: bootstrap host is ready"
701720
init_security_db
702-
configure_group
721+
retry 5 configure_group
703722
else
704723
log "Info: bootstrap host is ready"
705-
configure_group
724+
retry 5 configure_group
706725
join_cluster $HOST_FQDN
707726
fi
708727
configure_path_based_routing

pkg/k8sutil/statefulset.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,8 +696,11 @@ func getLivenessProbe(probe marklogicv1.ContainerProbe) *corev1.Probe {
696696
TimeoutSeconds: probe.TimeoutSeconds,
697697
SuccessThreshold: probe.SuccessThreshold,
698698
ProbeHandler: corev1.ProbeHandler{
699-
Exec: &corev1.ExecAction{
700-
Command: []string{"/bin/bash", "/tmp/helm-scripts/liveness-probe.sh"},
699+
TCPSocket: &corev1.TCPSocketAction{
700+
Port: intstr.IntOrString{
701+
Type: intstr.Int,
702+
IntVal: 8001,
703+
},
701704
},
702705
},
703706
}

test/e2e/2_marklogic_cluster_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,17 @@ func TestMarklogicCluster(t *testing.T) {
134134
if err != nil {
135135
t.Fatalf("Failed to install grafana helm chart: %v", err)
136136
}
137-
137+
// Wait for Grafana pod to be ready
138+
time.Sleep(5 * time.Second) // Give some time for Grafana to start
138139
podList := &corev1.PodList{}
139140
if err := client.Resources().List(ctx, podList, func(lo *metav1.ListOptions) {
140141
lo.FieldSelector = "metadata.namespace=" + "grafana"
141142
}); err != nil {
142143
t.Fatal(err)
143144
}
144-
145+
if len(podList.Items) == 0 {
146+
t.Fatal("No Grafana pods found")
147+
}
145148
grafanaPodName := podList.Items[0].Name
146149
err = utils.WaitForPod(ctx, t, client, "grafana", grafanaPodName, 120*time.Second)
147150
if err != nil {
@@ -228,7 +231,7 @@ func TestMarklogicCluster(t *testing.T) {
228231
client := c.Client()
229232

230233
podName := "node-0"
231-
err := utils.WaitForPod(ctx, t, client, mlNamespace, podName, 180*time.Second)
234+
err := utils.WaitForPod(ctx, t, client, mlNamespace, podName, 240*time.Second)
232235
if err != nil {
233236
t.Fatalf("Failed to wait for pod creation: %v", err)
234237
}
@@ -245,6 +248,10 @@ func TestMarklogicCluster(t *testing.T) {
245248
}); err != nil {
246249
t.Fatal(err)
247250
}
251+
time.Sleep(5 * time.Second) // Wait for Grafana to be fully ready
252+
if len(podList.Items) == 0 {
253+
t.Fatal("No Grafana pods found")
254+
}
248255
grafanaPodName := podList.Items[0].Name
249256
grafanaAdminUser, grafanaAdminPassword, err := utils.GetSecretData(ctx, client, "grafana", "grafana", "admin-user", "admin-password")
250257
if err != nil {
@@ -337,7 +344,7 @@ func TestMarklogicCluster(t *testing.T) {
337344
if err := client.Resources().Get(ctx, "marklogicclusters", mlNamespace, &mlcluster); err != nil {
338345
t.Fatal(err)
339346
}
340-
347+
341348
mlcluster.Spec.MarkLogicGroups[0].Resources = &resources
342349
if err := client.Resources().Update(ctx, &mlcluster); err != nil {
343350
t.Log("Failed to update MarkLogic group resources")

test/e2e/4_tls_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ func TestTlsWithNamedCert(t *testing.T) {
240240
}
241241
certURIs := gjson.Get(certs, `certificate-default-list.list-items.list-item.#.uriref`).Array()
242242
t.Log("Certificates URL list", certURIs)
243+
if len(certURIs) < 2 {
244+
t.Fatalf("Expected at least 2 certificates, found %d", len(certURIs))
245+
}
243246
cert0Url := fmt.Sprintf("https://localhost:8002%s?format=json", certURIs[0])
244247
cert1Url := fmt.Sprintf("https://localhost:8002%s?format=json", certURIs[1])
245248
command = fmt.Sprintf("curl -k --anyauth -u %s:%s %s", adminUsername, adminPassword, cert0Url)
@@ -404,8 +407,12 @@ func TestTlsWithMultiNode(t *testing.T) {
404407
if err != nil {
405408
t.Fatalf("Failed to get certificates list: %v", err)
406409
}
410+
t.Log("Certificates list", certs)
407411
certURIs := gjson.Get(certs, `certificate-default-list.list-items.list-item.#.uriref`).Array()
408412
t.Log("Dnode Cert Url", certURIs)
413+
if len(certURIs) < 2 {
414+
t.Fatalf("Expected at least 2 certificates, found %d", len(certURIs))
415+
}
409416
cert0Url := fmt.Sprintf("https://localhost:8002%s?format=json", certURIs[0])
410417
cert1Url := fmt.Sprintf("https://localhost:8002%s?format=json", certURIs[1])
411418
command = fmt.Sprintf("curl -k --anyauth -u %s:%s %s", adminUsername, adminPassword, cert0Url)

test/e2e/main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ func TestMain(m *testing.M) {
9494
log.Println("Deploying controller-manager resources...")
9595
p := utils.RunCommand(`kubectl version`)
9696
log.Printf("Output of kubectl: %s", p.Result())
97-
p = utils.RunCommand(`bash -c "kustomize build config/default | kubectl apply --server-side -f -"`)
98-
log.Printf("Output: %s", p.Result())
97+
p = utils.RunCommand(`make deploy`)
98+
log.Printf("Output of make deploy: %s", p.Result())
9999
if p.Err() != nil {
100100
log.Printf("Failed to deploy resource configurations: %s: %s", p.Err(), p.Result())
101101
return ctx, p.Err()

0 commit comments

Comments
 (0)