Skip to content

Commit 7bbf774

Browse files
committed
Merge commit 'c8398c93263bb470094dba10223763093b60ea98' into develop
* commit 'c8398c93263bb470094dba10223763093b60ea98': CLD-479: Adding ML Host changes commit Fix package issue Update makefile Seperate tests into catagorys instead of all being in one file Update e2e tests to create a seperate namespace for each test CLD-515: Add aditional test cases CLD-488: Move MARKLOGIC_INIT to configmap.yaml and add MARKLOGIC_JOIN_CLUSTER to add functionality requested in sprint review meeting Remove replica count and shell command Make naming conventions consistent Changes based on PR comments Remove direct call of start-marklogic.sh as it is the entry point of the docker image already. CLD-488: Update Helm Chart to use docker image scripts
2 parents 9377261 + c8398c9 commit 7bbf774

File tree

11 files changed

+247
-92
lines changed

11 files changed

+247
-92
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vscode
2+
values.yaml

charts/templates/configmap.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ metadata:
66
labels:
77
{{- include "marklogic.labels" . | nindent 4 }}
88
data:
9-
ML_BOOTSTRAP_HOST: {{ include "marklogic.fullname" . }}-0
10-
ML_FQDN_SUFFIX: {{ include "marklogic.headlessURL" . }}
11-
9+
MARKLOGIC_BOOTSTRAP_HOST: {{ include "marklogic.fullname" . }}-0
10+
MARKLOGIC_FQDN_SUFFIX: {{ include "marklogic.headlessURL" . }}
11+
MARKLOGIC_INIT: "true"
12+
MARKLOGIC_JOIN_CLUSTER: "true"

charts/templates/statefulset.yaml

Lines changed: 53 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ spec:
1717
{{- include "marklogic.selectorLabels" . | nindent 8 }}
1818
spec:
1919
serviceAccountName: {{ include "marklogic.serviceAccountName" . }}
20+
{{- with .Values.affinity }}
21+
affinity: {{- toYaml . | nindent 8}}
22+
{{- end }}
23+
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriod }}
2024
containers:
2125
- name: marklogic-server
2226
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
@@ -28,83 +32,19 @@ spec:
2832
{{- toYaml .Values.extraVolumeMounts | nindent 12 }}
2933
{{- end }}
3034
env:
31-
- name: ML_ADMIN_USER
35+
- name: MARKLOGIC_ADMIN_USERNAME
3236
valueFrom:
3337
secretKeyRef:
3438
name: {{ include "marklogic.fullname" . }}
3539
key: username
36-
- name: ML_ADMIN_PASS
40+
- name: MARKLOGIC_ADMIN_PASSWORD
3741
valueFrom:
3842
secretKeyRef:
3943
name: {{ include "marklogic.fullname" . }}
4044
key: password
4145
envFrom:
4246
- configMapRef:
4347
name: {{ include "marklogic.fullname" . }}
44-
command:
45-
- bash
46-
- '-c'
47-
- |
48-
echo '### Begin ML Container Config ###'
49-
50-
# Set Hostname to the value of hostname command to /etc/marklogic.conf
51-
HOST_FQDN="$(hostname).$ML_FQDN_SUFFIX"
52-
echo "export MARKLOGIC_HOSTNAME=\"$HOST_FQDN\"" | sudo tee /etc/marklogic.conf
53-
54-
cd ~
55-
56-
AUTH_CURL="curl --anyauth --user $ML_ADMIN_USER:$ML_ADMIN_PASS -m 20 -s "
57-
58-
# Start MarkLogic
59-
sudo service MarkLogic start
60-
sleep 5s
61-
62-
# Initialize and Setup Admin User
63-
echo '### Initialize and Setup Admin User ###'
64-
ML_STATUS_CODE=`curl -s -o /dev/null --write-out %{response_code} http://localhost:8001/admin/v1/init`
65-
if [ "$ML_STATUS_CODE" == "401" ]; then
66-
echo "Server is already configured."
67-
else
68-
curl -X POST -d "" http://$HOSTNAME:8001/admin/v1/init
69-
sleep 5s
70-
71-
curl -X POST -H "Content-type: application/x-www-form-urlencoded" \
72-
--data "admin-username=$ML_ADMIN_USER" --data "admin-password=$ML_ADMIN_PASS" \
73-
--data "realm=public" \
74-
http://$HOSTNAME:8001/admin/v1/instance-admin
75-
sleep 10s
76-
77-
# for EA1 release, disable turning on XDQP by default.
78-
# Turn on XDQP encryption via CMA
79-
# $AUTH_CURL -X POST -H 'Content-Type: application/json' \
80-
# -d '{"config":[{"op":"update","group":[{"group-name":"Default","xdqp-ssl-enabled":true}]}]}' \
81-
# http://$HOSTNAME:8002/manage/v3/
82-
83-
# Join Cluster
84-
if [ "$HOSTNAME" != "$ML_BOOTSTRAP_HOST" ]; then
85-
echo "### joining cluster ###"
86-
joiner=$HOSTNAME
87-
cluster="$ML_BOOTSTRAP_HOST"
88-
$AUTH_CURL -o host.xml -X GET -H "Accept: application/xml" http://${joiner}:8001/admin/v1/server-config
89-
$AUTH_CURL -X POST -d "group=Default" --data-urlencode "server-config@./host.xml" -H "Content-type: application/x-www-form-urlencoded" -o cluster.zip http://${cluster}:8001/admin/v1/cluster-config
90-
91-
sleep 10s
92-
93-
$AUTH_CURL -X POST -H "Content-type: application/zip" --data-binary @./cluster.zip http://${joiner}:8001/admin/v1/cluster-config
94-
sleep 5s
95-
96-
rm -f host.xml
97-
rm -f cluster.zip
98-
fi
99-
100-
fi
101-
102-
# mark the pod ready for readiness probe
103-
sudo touch /var/opt/MarkLogic/ready
104-
105-
echo '### END ML Container Config ###'
106-
107-
tail -f $MARKLOGIC_DATA_DIR/Logs/ErrorLog.txt
10848
ports:
10949
- containerPort: 7997
11050
name: health-check
@@ -121,6 +61,53 @@ spec:
12161
{{- if .Values.extraContainerPorts }}
12262
{{- toYaml .Values.extraContainerPorts | nindent 12 }}
12363
{{- end }}
64+
lifecycle:
65+
preStop:
66+
exec:
67+
command:
68+
- bash
69+
- '-c'
70+
- |
71+
log () {
72+
local TIMESTAMP=$(date +"%Y-%m-%d %T.%3N")
73+
echo "${TIMESTAMP} $@" > /proc/$pid/fd/1
74+
}
75+
76+
pid=$(ps aux | grep -i '/bin/bas[h] /usr' | awk {'print $2'})
77+
log "Info: [prestop] Prestop Hook Execution"
78+
79+
my_host=$(hostname -f)
80+
81+
log "Info: [prestop] MarkLogic Pod Hostname: "$my_host
82+
83+
for ((i = 0; i < 5; i = i + 1)); do
84+
res_code=$(curl --anyauth --user $MARKLOGIC_ADMIN_USERNAME:$MARKLOGIC_ADMIN_PASSWORD \
85+
-o /dev/null -m 10 -s -w %{http_code} \
86+
-i -X POST --data "state=shutdown&failover=true" \
87+
-H "Content-type: application/x-www-form-urlencoded" \
88+
http://localhost:8002/manage/v2/hosts/$my_host?format=json)
89+
90+
if [[ ${res_code} -eq 202 ]]; then
91+
log "Info: [prestop] Host shut down response code: "$res_code
92+
93+
while (true)
94+
do
95+
ml_status=$(service MarkLogic status)
96+
log "Info: [prestop] MarkLogic Status: "$ml_status
97+
if [[ "$ml_status" =~ "running" ]]; then
98+
sleep 5s
99+
continue
100+
else
101+
break
102+
fi
103+
done
104+
break
105+
else
106+
log "ERROR: [prestop] Retry Attempt: "$i
107+
log "ERROR: [prestop] Host shut down expected response code 202, got "$res_code
108+
sleep 10s
109+
fi
110+
done
124111
{{- if .Values.livenessProbe.enabled }}
125112
livenessProbe:
126113
httpGet:
@@ -157,9 +144,6 @@ spec:
157144
{{- with .Values.resources }}
158145
resources: {{- toYaml . | nindent 12 }}
159146
{{- end }}
160-
{{- with .Values.affinity }}
161-
affinity: {{- toYaml . | nindent 8}}
162-
{{- end }}
163147
{{- with .Values.nodeSelector }}
164148
nodeSelector: {{- toYaml . | nindent 8}}
165149
{{- end }}

charts/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# Number of Marklogic nodes
44
replicaCount: 1
55

6+
# Termination Grace Period
7+
terminationGracePeriod: 120
8+
69
# Marklogic image parameters
710
image:
811
repository: marklogicdb/marklogic-db

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.17
55
require (
66
github.com/gruntwork-io/terratest v0.40.6
77
github.com/stretchr/testify v1.7.0
8+
github.com/xinsnake/go-http-digest-auth-client v0.6.0
89
k8s.io/api v0.23.0
910
)
1011

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,8 @@ github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2
783783
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
784784
github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs=
785785
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
786+
github.com/xinsnake/go-http-digest-auth-client v0.6.0 h1:nrYFWDrB2F7VwYlNravXZS0nOtg9axlATH3Jns55/F0=
787+
github.com/xinsnake/go-http-digest-auth-client v0.6.0/go.mod h1:QK1t1v7ylyGb363vGWu+6Irh7gyFj+N7+UZzM0L6g8I=
786788
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
787789
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
788790
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ test/e2e: install-go-modules
66
sh ./test/e2e/e2e.sh
77

88
test/template: install-go-modules
9-
go test -v ./test/template/...
9+
go test -v ./test/template/...
10+
11+
test: test/template test/e2e

test/e2e/clustering_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package e2e
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"net/http"
7+
"path/filepath"
8+
"strings"
9+
"testing"
10+
"time"
11+
12+
"github.com/gruntwork-io/terratest/modules/helm"
13+
"github.com/gruntwork-io/terratest/modules/k8s"
14+
"github.com/gruntwork-io/terratest/modules/random"
15+
digest_auth "github.com/xinsnake/go-http-digest-auth-client"
16+
)
17+
18+
19+
func TestClusterJoin(t *testing.T) {
20+
// Path to the helm chart we will test
21+
helmChartPath, e := filepath.Abs("../../charts")
22+
if (e != nil) {
23+
t.Fatalf(e.Error())
24+
}
25+
username := "admin"
26+
password := "admin"
27+
var resp *http.Response
28+
var body []byte
29+
var err error
30+
namespaceName := "marklogic-" + strings.ToLower(random.UniqueId())
31+
kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName)
32+
options := &helm.Options{
33+
KubectlOptions: kubectlOptions,
34+
SetValues: map[string]string{
35+
"persistence.enabled": "false",
36+
"replicaCount": "2",
37+
"image.repository": "marklogic-centos/marklogic-server-centos",
38+
"image.tag": "10-internal",
39+
"auth.adminUsername": username,
40+
"auth.adminPassword": password,
41+
},
42+
}
43+
44+
t.Logf("====Creating namespace: " + namespaceName)
45+
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
46+
47+
defer t.Logf("====Deleting namespace: " + namespaceName)
48+
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
49+
50+
t.Logf("====Installing Helm Chart")
51+
releaseName := "test-join"
52+
helm.Install(t, options, helmChartPath, releaseName)
53+
54+
podName := releaseName + "-marklogic-1"
55+
56+
// wait until the pod is in Ready status
57+
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 20*time.Second)
58+
tunnel := k8s.NewTunnel(
59+
kubectlOptions, k8s.ResourceTypePod, podName, 8002, 8002)
60+
defer tunnel.Close()
61+
tunnel.ForwardPort(t)
62+
endpoint := fmt.Sprintf("http://%s/manage/v2/hosts", tunnel.Endpoint())
63+
t.Logf(`Endpoint: %s`, endpoint)
64+
65+
dr := digest_auth.NewRequest(username, password, "GET", endpoint, "")
66+
67+
if resp, err = dr.Execute(); err != nil {
68+
t.Fatalf(err.Error())
69+
}
70+
defer resp.Body.Close()
71+
72+
if body, err = ioutil.ReadAll(resp.Body); err != nil {
73+
t.Fatalf(err.Error())
74+
}
75+
76+
t.Logf("Response:\n" + string(body))
77+
if !strings.Contains(string(body), "<list-count units=\"quantity\">2</list-count>") {
78+
t.Errorf("Wrong number of hosts")
79+
}
80+
}

test/e2e/e2e.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/bin/bash
22

3-
echo "=====Delete minikube cluster"
4-
minikube delete
5-
63
echo "=====Installing minikube cluster"
74
minikube start --driver=docker -n=1
85

96
echo "=====Loading marklogc images to minikube cluster"
10-
minikube image load marklogicdb/marklogic-db:10.0-9.1-centos-1.0.0-ea4
7+
minikube image load marklogicdb/marklogic-db:latest
118

129
echo "=====Running tests"
1310
go test -v -count=1 ./test/e2e/...
11+
12+
echo "=====Delete minikube cluster"
13+
minikube delete

test/e2e/e2e_test.go renamed to test/e2e/install_test.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,40 @@ import (
1212
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
1313
"github.com/gruntwork-io/terratest/modules/k8s"
1414
"github.com/gruntwork-io/terratest/modules/random"
15-
"github.com/stretchr/testify/require"
1615
)
1716

1817
func TestHelmInstall(t *testing.T) {
1918
// Path to the helm chart we will test
20-
helmChartPath, err := filepath.Abs("../../charts")
21-
releaseName := "marklogic-test"
22-
t.Log(helmChartPath, releaseName)
23-
require.NoError(t, err)
19+
helmChartPath, e := filepath.Abs("../../charts")
20+
if e != nil {
21+
t.Fatalf(e.Error())
22+
}
2423
namespaceName := "marklogic-" + strings.ToLower(random.UniqueId())
25-
t.Logf("creating namespace: %s", namespaceName)
2624
kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName)
27-
28-
// create a new namespace for testing
29-
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
30-
31-
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
3225
options := &helm.Options{
3326
KubectlOptions: kubectlOptions,
3427
SetValues: map[string]string{
3528
"persistence.enabled": "false",
29+
"replicaCount": "1",
30+
"image.repository": "marklogic-centos/marklogic-server-centos",
31+
"image.tag": "10-internal",
3632
},
3733
}
3834

39-
defer helm.Delete(t, options, releaseName, true)
35+
t.Logf("====Creating namespace: " + namespaceName)
36+
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
37+
38+
defer t.Logf("====Deleting namespace: " + namespaceName)
39+
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
4040

41-
//install Helm Chart for testing
41+
t.Logf("====Installing Helm Chart")
42+
releaseName := "test-install"
4243
helm.Install(t, options, helmChartPath, releaseName)
4344

4445
tlsConfig := tls.Config{}
45-
podName := "marklogic-test-0"
46+
podName := releaseName + "-marklogic-0"
4647
// wait until the pod is in Ready status
47-
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 10*time.Second)
48+
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 15*time.Second)
4849
tunnel := k8s.NewTunnel(
4950
kubectlOptions, k8s.ResourceTypePod, podName, 7997, 7997)
5051
defer tunnel.Close()

0 commit comments

Comments
 (0)