Skip to content

Commit dc9763a

Browse files
MLE-13839: added changes for helm upgrade e2e test (#250) (#259)
* added changes for helm upgrade e2e test
1 parent 4d9b86f commit dc9763a

18 files changed

+993
-394
lines changed

Jenkinsfile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pipeline {
158158
skipStagesAfterUnstable()
159159
}
160160
triggers {
161-
parameterizedCron( env.BRANCH_NAME == 'develop' ? '''00 04 * * * % IMAGE_SCAN=true;HC_TESTS=true''' : '')
161+
parameterizedCron( env.BRANCH_NAME == 'develop' ? '''00 04 * * * % IMAGE_SCAN=true;HELM_UPGRADE_TESTS=true;HC_TESTS=true''' : '')
162162
}
163163
environment {
164164
dockerRegistry = 'ml-docker-db-dev-tierpoint.bed-artifactory.bedford.progress.com'
@@ -174,6 +174,8 @@ pipeline {
174174
string(name: 'KUBERNETES_TEST_SELECTION', defaultValue: '...', description: 'Pick one test to run. (e.g. tls_test.go) ... will run all tests.', trim: true)
175175
booleanParam(name: 'HC_TESTS', defaultValue: false, description: 'Run Hub Central E2E UI tests (takes about 3 hours)')
176176
booleanParam(name: 'IMAGE_SCAN', defaultValue: false, description: 'Find and scan dependent Docker images for security vulnerabilities')
177+
booleanParam(name: 'HELM_UPGRADE_TESTS', defaultValue: false, description: 'Run Helm upgrade in E2E tests (runs nightly on develop)')
178+
string(name: 'InitialChartVersion', defaultValue: '1.1.2', description: 'Helm Chart Version to use for upgrade tests. (e.g. 1.1.2)', trim: true)
177179
string(name: 'emailList', defaultValue: emailList, description: 'List of email for build notification', trim: true)
178180
}
179181

@@ -209,6 +211,16 @@ pipeline {
209211
"""
210212
}
211213
}
214+
stage('Kubernetes-Run-Upgrade-Tests') {
215+
when {
216+
expression { return params.HELM_UPGRADE_TESTS }
217+
}
218+
steps {
219+
sh """
220+
export MINIKUBE_HOME=/space; export KUBECONFIG=/space/.kube-config; export GOPATH=/space/go; export upgradeTest=true; export initialChartVersion=${params.InitialChartVersion}; make upgrade-test dockerImage=${dockerRepository}:${dockerVersion} prevDockerImage=${dockerRepository}:${prevDockerVersion} kubernetesVersion=${params.K8_VERSION} saveOutput=true minikubeMemory=20gb
221+
"""
222+
}
223+
}
212224
stage('Kubernetes-Run-HC-Tests') {
213225
when {
214226
expression { return params.HC_TESTS }

makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,24 @@ template-test: prepare
192192
.PHONY: test
193193
test: template-test e2e-test
194194

195+
#***************************************************************************
196+
# test
197+
#***************************************************************************
198+
## Run upgrade in e2e tests
199+
## Set following environment variables
200+
## [upgradeTest] to true. Use `export upgradeTest=true`
201+
## [initialChartVersion] to a valid MarkLogic helm chart version for ex.: 1.1.2 to run upgrade tests. Use `export initialChartVersion=1.1.2`
202+
.PHONY: upgrade-test
203+
upgrade-test: prepare
204+
@echo "=====upgradeTest env var for upgrade tests"
205+
echo $(upgradeTest)
206+
207+
@echo "=====initialChartVersion env var for upgrade tests"
208+
echo ${initialChartVersion}
209+
210+
@echo "=====Running upgrades in e2e tests"
211+
make e2e-test
212+
195213
#***************************************************************************
196214
# image-scan
197215
#***************************************************************************

test/e2e/admin_secrets_test.go

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"crypto/tls"
55
"os"
66
"path/filepath"
7+
"strconv"
78
"strings"
89
"testing"
910
"time"
@@ -15,10 +16,13 @@ import (
1516
)
1617

1718
func TestMlAdminSecrets(t *testing.T) {
18-
// Path to the helm chart we will test
19-
helmChartPath, e := filepath.Abs("../../charts")
20-
if e != nil {
21-
t.Fatalf(e.Error())
19+
var helmChartPath string
20+
var initialChartVersion string
21+
upgradeHelm, _ := os.LookupEnv("upgradeTest")
22+
runUpgradeTest, err := strconv.ParseBool(upgradeHelm)
23+
if runUpgradeTest {
24+
initialChartVersion, _ = os.LookupEnv("initialChartVersion")
25+
t.Logf("====Setting initial Helm chart version: %s", initialChartVersion)
2226
}
2327
imageRepo, repoPres := os.LookupEnv("dockerRepository")
2428
imageTag, tagPres := os.LookupEnv("dockerVersion")
@@ -40,12 +44,13 @@ func TestMlAdminSecrets(t *testing.T) {
4044
SetValues: map[string]string{
4145
"persistence.enabled": "true",
4246
"replicaCount": "1",
43-
"image.repository": imageRepo,
44-
"image.tag": imageTag,
47+
"image.repository": "ml-docker-db-dev-tierpoint.bed-artifactory.bedford.progress.com/marklogic/marklogic-server-ubi-rootless",
48+
"image.tag": "latest-11",
4549
"auth.adminUsername": "admin",
4650
"auth.adminPassword": "admin",
4751
"auth.walletPassword": "admin",
4852
},
53+
Version: initialChartVersion,
4954
}
5055

5156
t.Logf("====Creating namespace: " + namespaceName)
@@ -54,14 +59,51 @@ func TestMlAdminSecrets(t *testing.T) {
5459
defer t.Logf("====Deleting namespace: " + namespaceName)
5560
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
5661

62+
// Path to the helm chart we will test
63+
helmChartPath, err = filepath.Abs("../../charts")
64+
if err != nil {
65+
t.Fatalf(err.Error())
66+
}
67+
68+
//add the helm chart repo and install the last helm chart release from repository
69+
//to test and upgrade this chart to the latest one to be released
70+
if runUpgradeTest {
71+
helm.AddRepo(t, options, "marklogic", "https://marklogic.github.io/marklogic-kubernetes/")
72+
defer helm.RemoveRepo(t, options, "marklogic")
73+
helmChartPath = "marklogic/marklogic"
74+
}
75+
76+
t.Logf("====Setting helm chart path to %s", helmChartPath)
5777
t.Logf("====Installing Helm Chart")
5878
releaseName := "test-ml-secrets"
59-
helm.Install(t, options, helmChartPath, releaseName)
79+
podName := testUtil.HelmInstall(t, options, releaseName, kubectlOptions, helmChartPath)
6080

61-
podName := releaseName + "-0"
6281
// wait until the pod is in Ready status
6382
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 15, 15*time.Second)
6483

84+
if runUpgradeTest {
85+
// create options for helm upgrade
86+
upgradeOptionsMap := map[string]string{
87+
"persistence.enabled": "true",
88+
"replicaCount": "1",
89+
"logCollection.enabled": "false",
90+
"allowLongHostnames": "true",
91+
}
92+
93+
if strings.HasPrefix(initialChartVersion, "1.0") {
94+
podName = releaseName + "-marklogic-0"
95+
upgradeOptionsMap["useLegacyHostnames"] = "true"
96+
}
97+
98+
//set helm options for upgrading helm chart version
99+
helmUpgradeOptions := &helm.Options{
100+
KubectlOptions: kubectlOptions,
101+
SetValues: upgradeOptionsMap,
102+
}
103+
t.Logf("UpgradeHelmTest is enabled. Running helm upgrade test")
104+
testUtil.HelmUpgrade(t, helmUpgradeOptions, releaseName, kubectlOptions, []string{podName}, initialChartVersion)
105+
}
106+
65107
// get corev1.Pod to get logs of a pod
66108
pod := k8s.GetPod(t, kubectlOptions, podName)
67109

test/e2e/backup_restore_test.go

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ import (
66
"fmt"
77
"io"
88
"os"
9+
"path/filepath"
10+
"strconv"
911
"strings"
1012
"testing"
1113
"time"
1214

15+
"github.com/gruntwork-io/terratest/modules/helm"
1316
"github.com/gruntwork-io/terratest/modules/k8s"
1417
"github.com/gruntwork-io/terratest/modules/random"
1518
"github.com/imroc/req/v3"
@@ -136,9 +139,16 @@ func RunRequests(client *req.Client, dbReq string, hostsEndpoint string) (string
136139

137140
func TestMlDbBackupRestore(t *testing.T) {
138141
// var resp *http.Response
139-
142+
var helmChartPath string
140143
var err error
141144
var podName string
145+
var initialChartVersion string
146+
upgradeHelm, _ := os.LookupEnv("upgradeTest")
147+
runUpgradeTest, err := strconv.ParseBool(upgradeHelm)
148+
if runUpgradeTest {
149+
initialChartVersion, _ = os.LookupEnv("initialChartVersion")
150+
t.Logf("====Setting initial Helm chart version: %s", initialChartVersion)
151+
}
142152
imageRepo, repoPres := os.LookupEnv("dockerRepository")
143153
imageTag, tagPres := os.LookupEnv("dockerVersion")
144154

@@ -155,37 +165,76 @@ func TestMlDbBackupRestore(t *testing.T) {
155165
username := "admin"
156166
password := "admin"
157167

158-
options := map[string]string{
159-
"persistence.enabled": "true",
160-
"replicaCount": "1",
161-
"image.repository": imageRepo,
162-
"image.tag": imageTag,
163-
"auth.adminUsername": username,
164-
"auth.adminPassword": password,
165-
"logCollection.enabled": "false",
168+
namespaceName := "ml-" + strings.ToLower(random.UniqueId())
169+
kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName)
170+
options := &helm.Options{
171+
KubectlOptions: kubectlOptions,
172+
SetValues: map[string]string{
173+
"persistence.enabled": "true",
174+
"replicaCount": "1",
175+
"image.repository": imageRepo,
176+
"image.tag": imageTag,
177+
"auth.adminUsername": username,
178+
"auth.adminPassword": password,
179+
"logCollection.enabled": "false",
180+
},
181+
Version: initialChartVersion,
166182
}
167183

168184
t.Logf("====Installing Helm Chart")
169185
releaseName := "bkuprestore"
170186

171-
namespaceName := "ml-" + strings.ToLower(random.UniqueId())
172-
kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName)
173-
174187
t.Logf("====Creating namespace: " + namespaceName)
175188
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
176189

177190
defer t.Logf("====Deleting namespace: " + namespaceName)
178191
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
179192

180-
podName = testUtil.HelmInstall(t, options, releaseName, kubectlOptions)
193+
helmChartPath, err = filepath.Abs("../../charts")
194+
if err != nil {
195+
t.Fatalf(err.Error())
196+
}
197+
198+
//add the helm chart repo and install the last helm chart release from repository
199+
//to test and upgrade this chart to the latest one to be released
200+
if runUpgradeTest {
201+
helm.AddRepo(t, options, "marklogic", "https://marklogic.github.io/marklogic-kubernetes/")
202+
defer helm.RemoveRepo(t, options, "marklogic")
203+
helmChartPath = "marklogic/marklogic"
204+
}
205+
206+
t.Logf("====Setting helm chart path to %s", helmChartPath)
207+
t.Logf("====Installing Helm Chart")
208+
podName = testUtil.HelmInstall(t, options, releaseName, kubectlOptions, helmChartPath)
181209

182210
t.Logf("====Describe pod for backup restore test")
183211
k8s.RunKubectl(t, kubectlOptions, "describe", "pod", podName)
184212

185-
tlsConfig := tls.Config{}
186213
// wait until the pod is in Ready status
187214
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 15*time.Second)
188215

216+
if runUpgradeTest {
217+
// create options for helm upgrade
218+
upgradeOptionsMap := map[string]string{
219+
"persistence.enabled": "true",
220+
"replicaCount": "1",
221+
"logCollection.enabled": "false",
222+
"allowLongHostnames": "true",
223+
}
224+
if strings.HasPrefix(initialChartVersion, "1.0") {
225+
podName = releaseName + "-marklogic-0"
226+
upgradeOptionsMap["useLegacyHostnames"] = "true"
227+
}
228+
//set helm options for upgrading helm chart version
229+
helmUpgradeOptions := &helm.Options{
230+
KubectlOptions: kubectlOptions,
231+
SetValues: upgradeOptionsMap,
232+
}
233+
234+
t.Logf("UpgradeHelmTest is enabled. Running helm upgrade test")
235+
testUtil.HelmUpgrade(t, helmUpgradeOptions, releaseName, kubectlOptions, []string{podName}, initialChartVersion)
236+
}
237+
189238
//create backup directories and setup permissions
190239
k8s.RunKubectl(t, kubectlOptions, "exec", podName, "--", "/bin/bash", "-c", "cd /tmp && mkdir backup && chmod 777 backup && mkdir backup/incrBackup && chmod 777 backup/incrBackup")
191240

@@ -327,6 +376,7 @@ func TestMlDbBackupRestore(t *testing.T) {
327376
t.Errorf("Both docs are restored")
328377
}
329378

379+
tlsConfig := tls.Config{}
330380
// restart pods in the cluster and verify its ready and MarkLogic server is healthy
331381
testUtil.RestartPodAndVerify(t, false, []string{podName}, namespaceName, kubectlOptions, &tlsConfig)
332382
}

0 commit comments

Comments
 (0)