@@ -6,10 +6,13 @@ import (
6
6
"fmt"
7
7
"io"
8
8
"os"
9
+ "path/filepath"
10
+ "strconv"
9
11
"strings"
10
12
"testing"
11
13
"time"
12
14
15
+ "github.com/gruntwork-io/terratest/modules/helm"
13
16
"github.com/gruntwork-io/terratest/modules/k8s"
14
17
"github.com/gruntwork-io/terratest/modules/random"
15
18
"github.com/imroc/req/v3"
@@ -136,9 +139,16 @@ func RunRequests(client *req.Client, dbReq string, hostsEndpoint string) (string
136
139
137
140
func TestMlDbBackupRestore (t * testing.T ) {
138
141
// var resp *http.Response
139
-
142
+ var helmChartPath string
140
143
var err error
141
144
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
+ }
142
152
imageRepo , repoPres := os .LookupEnv ("dockerRepository" )
143
153
imageTag , tagPres := os .LookupEnv ("dockerVersion" )
144
154
@@ -155,37 +165,76 @@ func TestMlDbBackupRestore(t *testing.T) {
155
165
username := "admin"
156
166
password := "admin"
157
167
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 ,
166
182
}
167
183
168
184
t .Logf ("====Installing Helm Chart" )
169
185
releaseName := "bkuprestore"
170
186
171
- namespaceName := "ml-" + strings .ToLower (random .UniqueId ())
172
- kubectlOptions := k8s .NewKubectlOptions ("" , "" , namespaceName )
173
-
174
187
t .Logf ("====Creating namespace: " + namespaceName )
175
188
k8s .CreateNamespace (t , kubectlOptions , namespaceName )
176
189
177
190
defer t .Logf ("====Deleting namespace: " + namespaceName )
178
191
defer k8s .DeleteNamespace (t , kubectlOptions , namespaceName )
179
192
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 )
181
209
182
210
t .Logf ("====Describe pod for backup restore test" )
183
211
k8s .RunKubectl (t , kubectlOptions , "describe" , "pod" , podName )
184
212
185
- tlsConfig := tls.Config {}
186
213
// wait until the pod is in Ready status
187
214
k8s .WaitUntilPodAvailable (t , kubectlOptions , podName , 10 , 15 * time .Second )
188
215
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
+
189
238
//create backup directories and setup permissions
190
239
k8s .RunKubectl (t , kubectlOptions , "exec" , podName , "--" , "/bin/bash" , "-c" , "cd /tmp && mkdir backup && chmod 777 backup && mkdir backup/incrBackup && chmod 777 backup/incrBackup" )
191
240
@@ -327,6 +376,7 @@ func TestMlDbBackupRestore(t *testing.T) {
327
376
t .Errorf ("Both docs are restored" )
328
377
}
329
378
379
+ tlsConfig := tls.Config {}
330
380
// restart pods in the cluster and verify its ready and MarkLogic server is healthy
331
381
testUtil .RestartPodAndVerify (t , false , []string {podName }, namespaceName , kubectlOptions , & tlsConfig )
332
382
}
0 commit comments