Skip to content

Commit d8ff9e4

Browse files
author
Barkha Choithani
committed
impl and tests for upgradeStrategy
1 parent fa53785 commit d8ff9e4

File tree

5 files changed

+159
-0
lines changed

5 files changed

+159
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ This table describes the list of available parameters for Helm Chart.
516516
| `networkPolicy.customRules` | Placeholder to specify selectors | `{}` |
517517
| `networkPolicy.ports` | Ports to which traffic is allowed | `[8000, 8001, 8002]` |
518518
| `priorityClassName` | Name of a PriortyClass defined to set pod priority | `""` |
519+
| `updateStrategy` | Update strategy for helm chart and app version updates | `RollingUpdate` |
519520

520521
# Known Issues and Limitations
521522

charts/templates/statefulset.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ metadata:
88
spec:
99
serviceName: {{ include "marklogic.headlessServiceName" . }}
1010
replicas: {{ .Values.replicaCount }}
11+
updateStrategy:
12+
type: {{ .Values.updateStrategy.type }}
1113
selector:
1214
matchLabels:
1315
{{- include "marklogic.selectorLabels" . | nindent 6 }}

charts/values.yaml

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

6+
# update strategy for MarkLogic and Helm chart upgrades
7+
updateStrategy:
8+
type: RollingUpdate
9+
610
# Termination Grace Period
711
terminationGracePeriod: 120
812

test/e2e/ml_upgrade_test.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package e2e
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"path/filepath"
7+
"strings"
8+
"testing"
9+
"time"
10+
11+
"github.com/gruntwork-io/terratest/modules/helm"
12+
"github.com/gruntwork-io/terratest/modules/k8s"
13+
"github.com/gruntwork-io/terratest/modules/random"
14+
"github.com/stretchr/testify/assert"
15+
"github.com/tidwall/gjson"
16+
digestAuth "github.com/xinsnake/go-http-digest-auth-client"
17+
)
18+
19+
func TestHelmMLupgrade(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+
28+
namespaceName := "marklogic-" + strings.ToLower(random.UniqueId())
29+
kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName)
30+
options := &helm.Options{
31+
KubectlOptions: kubectlOptions,
32+
SetValues: map[string]string{
33+
"persistence.enabled": "false",
34+
"replicaCount": "1",
35+
"image.repository": "marklogicdb/marklogic-db",
36+
"image.tag": "latest-10.0",
37+
"auth.adminUsername": username,
38+
"auth.adminPassword": password,
39+
},
40+
}
41+
42+
t.Logf("====Creating namespace: " + namespaceName)
43+
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
44+
defer t.Logf("====Deleting namespace: " + namespaceName)
45+
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
46+
47+
t.Logf("====Installing Helm Chart")
48+
releaseName := "test-ml-upgrade"
49+
helm.Install(t, options, helmChartPath, releaseName)
50+
51+
podName := releaseName + "-marklogic-0"
52+
53+
// wait until second pod is in Ready status
54+
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 20, 20*time.Second)
55+
56+
newOptions := &helm.Options{
57+
KubectlOptions: kubectlOptions,
58+
SetValues: map[string]string{
59+
"persistence.enabled": "false",
60+
"image.repository": "marklogicdb/marklogic-db",
61+
"image.tag": "latest",
62+
"logCollection.enabled": "false",
63+
},
64+
}
65+
66+
t.Logf("====Upgrading Helm Chart")
67+
helm.Upgrade(t, newOptions, helmChartPath, releaseName)
68+
69+
// Give time to change status of pod from running to terminate during upgrade
70+
time.Sleep(10 * time.Second)
71+
72+
// wait until second pod is in Ready status
73+
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 15, 30*time.Second)
74+
75+
tunnel := k8s.NewTunnel(
76+
kubectlOptions, k8s.ResourceTypePod, podName, 8002, 8002)
77+
defer tunnel.Close()
78+
tunnel.ForwardPort(t)
79+
80+
clusterEndpoint := fmt.Sprintf("http://%s/manage/v2?format=json", tunnel.Endpoint())
81+
t.Logf(`Endpoint: %s`, clusterEndpoint)
82+
83+
getMLversion := digestAuth.NewRequest(username, password, "GET", clusterEndpoint, "")
84+
85+
resp, err := getMLversion.Execute()
86+
if err != nil {
87+
t.Fatalf(err.Error())
88+
}
89+
defer resp.Body.Close()
90+
body, err := ioutil.ReadAll(resp.Body)
91+
if err != nil {
92+
t.Fatalf(err.Error())
93+
}
94+
mlVersion := gjson.Get(string(body), `local-cluster-default.version`)
95+
96+
// verify latest MarkLogic version after upgrade
97+
assert.Equal(t, mlVersion.Str, "11.0.0")
98+
99+
}

test/template/upgrade_templ_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package template_test
2+
3+
import (
4+
"path/filepath"
5+
"strings"
6+
"testing"
7+
8+
"github.com/stretchr/testify/require"
9+
appsv1 "k8s.io/api/apps/v1"
10+
11+
"github.com/gruntwork-io/terratest/modules/helm"
12+
"github.com/gruntwork-io/terratest/modules/k8s"
13+
"github.com/gruntwork-io/terratest/modules/random"
14+
)
15+
16+
func TestChartTemplateUpgradeStrategy(t *testing.T) {
17+
t.Parallel()
18+
19+
// Path to the helm chart we will test
20+
helmChartPath, err := filepath.Abs("../../charts")
21+
releaseName := "marklogic-upgrade-test"
22+
t.Log(helmChartPath, releaseName)
23+
require.NoError(t, err)
24+
25+
// Set up the namespace; confirm that the template renders the expected value for the namespace.
26+
namespaceName := "marklogic-" + strings.ToLower(random.UniqueId())
27+
t.Logf("Namespace: %s\n", namespaceName)
28+
29+
// Setup the args for helm install
30+
options := &helm.Options{
31+
SetValues: map[string]string{
32+
"image.repository": "marklogicdb/marklogic-db",
33+
"image.tag": "latest",
34+
"persistence.enabled": "false",
35+
"updateStrategy.type": "RollingUpdate",
36+
},
37+
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
38+
}
39+
40+
// render the tempate
41+
output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/statefulset.yaml"})
42+
43+
var statefulset appsv1.StatefulSet
44+
helm.UnmarshalK8SYaml(t, output, &statefulset)
45+
46+
// Verify the name and namespace matches
47+
require.Equal(t, namespaceName, statefulset.Namespace)
48+
49+
// Verify the updateStrategy type set for upgrade
50+
expectedUpgradeStrategy := "RollingUpdate"
51+
actualUpgradeStrategy := statefulset.Spec.UpdateStrategy.Type
52+
require.Equal(t, string(actualUpgradeStrategy), expectedUpgradeStrategy)
53+
}

0 commit comments

Comments
 (0)