@@ -22,137 +22,6 @@ import (
22
22
"github.com/tidwall/gjson"
23
23
)
24
24
25
- func TestHelmUpgrade (t * testing.T ) {
26
- // Path to the helm chart we will test
27
- helmChartPath , e := filepath .Abs ("../../charts" )
28
- if e != nil {
29
- t .Fatalf (e .Error ())
30
- }
31
- imageRepo , repoPres := os .LookupEnv ("dockerRepository" )
32
- imageTag , tagPres := os .LookupEnv ("dockerVersion" )
33
-
34
- if ! repoPres {
35
- imageRepo = "ml-docker-db-dev-tierpoint.bed-artifactory.bedford.progress.com/marklogic/marklogic-server-ubi-rootless"
36
- t .Logf ("No imageRepo variable present, setting to default value: " + imageRepo )
37
- }
38
-
39
- if ! tagPres {
40
- imageTag = "latest-11"
41
- t .Logf ("No imageTag variable present, setting to default value: " + imageTag )
42
- }
43
-
44
- namespaceName := "ml-" + strings .ToLower (random .UniqueId ())
45
- kubectlOptions := k8s .NewKubectlOptions ("" , "" , namespaceName )
46
- options := & helm.Options {
47
- KubectlOptions : kubectlOptions ,
48
- SetValues : map [string ]string {
49
- "persistence.enabled" : "true" ,
50
- "replicaCount" : "1" ,
51
- "image.repository" : imageRepo ,
52
- "image.tag" : imageTag ,
53
- "logCollection.enabled" : "false" ,
54
- },
55
- }
56
-
57
- t .Logf ("====Creating namespace: " + namespaceName )
58
- k8s .CreateNamespace (t , kubectlOptions , namespaceName )
59
- defer t .Logf ("====Deleting namespace: " + namespaceName )
60
- defer k8s .DeleteNamespace (t , kubectlOptions , namespaceName )
61
-
62
- t .Logf ("====Installing Helm Chart" )
63
- releaseName := "test-upgrade"
64
- helm .Install (t , options , helmChartPath , releaseName )
65
-
66
- // save the generated password from first installation
67
- secretName := releaseName + "-admin"
68
- secret := k8s .GetSecret (t , kubectlOptions , secretName )
69
- usernameArr := secret .Data ["username" ]
70
- username := string (usernameArr )
71
- passwordArr := secret .Data ["password" ]
72
- passwordAfterInstall := string (passwordArr [:])
73
-
74
- newOptions := & helm.Options {
75
- KubectlOptions : kubectlOptions ,
76
- SetValues : map [string ]string {
77
- "persistence.enabled" : "true" ,
78
- "replicaCount" : "2" ,
79
- "image.repository" : imageRepo ,
80
- "image.tag" : imageTag ,
81
- "logCollection.enabled" : "false" ,
82
- },
83
- }
84
-
85
- t .Logf ("====Upgrading Helm Chart" )
86
- helm .Upgrade (t , newOptions , helmChartPath , releaseName )
87
-
88
- tlsConfig := tls.Config {}
89
- podOneName := releaseName + "-1"
90
- podZeroName := releaseName + "-0"
91
-
92
- // wait until the pod is in Ready status
93
- k8s .WaitUntilPodAvailable (t , kubectlOptions , podOneName , 20 , 20 * time .Second )
94
-
95
- t .Log ("====Test password in secret should not change after upgrade====" )
96
- secret = k8s .GetSecret (t , kubectlOptions , secretName )
97
- passwordArr = secret .Data ["password" ]
98
- passwordAfterUpgrade := string (passwordArr [:])
99
- assert .Equal (t , passwordAfterUpgrade , passwordAfterInstall )
100
-
101
- // verify MarkLogic is ready
102
- _ , err := testUtil .MLReadyCheck (t , kubectlOptions , podZeroName , & tlsConfig )
103
- if err != nil {
104
- t .Fatal ("MarkLogic failed to start" )
105
- }
106
-
107
- tunnel8002 := k8s .NewTunnel (
108
- kubectlOptions , k8s .ResourceTypePod , podZeroName , 8002 , 8002 )
109
- defer tunnel8002 .Close ()
110
- tunnel8002 .ForwardPort (t )
111
-
112
- hostsEndpoint := fmt .Sprintf ("http://%s/manage/v2/hosts?view=status&format=json" , tunnel8002 .Endpoint ())
113
- t .Logf (`Endpoint: %s` , hostsEndpoint )
114
-
115
- totalHosts := 1
116
- client := req .C ().
117
- SetCommonDigestAuth (username , passwordAfterUpgrade ).
118
- SetCommonRetryCount (10 ).
119
- SetCommonRetryFixedInterval (10 * time .Second )
120
-
121
- resp , err := client .R ().
122
- AddRetryCondition (func (resp * req.Response , err error ) bool {
123
- if err != nil {
124
- t .Logf ("error in getting the response: %s" , err .Error ())
125
- return true
126
- }
127
- if resp == nil || resp .Body == nil {
128
- t .Logf ("error in getting the response body" )
129
- return true
130
- }
131
- body , err := io .ReadAll (resp .Body )
132
- if err != nil {
133
- t .Logf ("error in reading the response: %s" , err .Error ())
134
- }
135
- totalHosts = int (gjson .Get (string (body ), `host-status-list.status-list-summary.total-hosts.value` ).Num )
136
- if totalHosts != 2 {
137
- t .Log ("Waiting for second host to join MarkLogic cluster" )
138
- }
139
- return totalHosts != 2
140
- }).
141
- Get (hostsEndpoint )
142
-
143
- if err != nil {
144
- t .Fatalf (err .Error ())
145
- }
146
- defer resp .Body .Close ()
147
-
148
- if totalHosts != 2 {
149
- t .Errorf ("Incorrect number of MarkLogic hosts found after helm upgrade" )
150
- }
151
-
152
- // restart all pods at once in the cluster and verify its ready and MarkLogic server is healthy
153
- testUtil .RestartPodAndVerify (t , true , []string {podZeroName , podOneName }, namespaceName , kubectlOptions , & tlsConfig )
154
- }
155
-
156
25
func TestMLupgrade (t * testing.T ) {
157
26
// Path to the helm chart we will test
158
27
helmChartPath , e := filepath .Abs ("../../charts" )
0 commit comments