Skip to content

Commit

Permalink
Fix TE preference query annotation key (#259)
Browse files Browse the repository at this point in the history
Fixed the TE preference query annotation key to be the one expected by the admin.
  • Loading branch information
sivanov-nuodb authored Dec 3, 2021
1 parent 185ccb8 commit b91d12d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 22 deletions.
2 changes: 1 addition & 1 deletion stable/database/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ The configuration is imported only in the entrypoint cluster.
{{- if (eq (default "cluster0" .Values.cloud.cluster.name) (default "cluster0" .Values.cloud.cluster.entrypointName)) }}
"nuodb.com/automatic-database-protocol-upgrade": "true"
{{- with .Values.database.automaticProtocolUpgrade.tePreferenceQuery }}
"nuodb.com/automatic-database-protocol-upgrade.te-preference-policy": {{ . | quote }}
"nuodb.com/automatic-database-protocol-upgrade.te-preference-query": {{ . | quote }}
{{- end -}}
{{- end -}}
{{- end -}}
Expand Down
27 changes: 14 additions & 13 deletions test/integration/process_marshall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package integration

import (
"encoding/json"

"github.com/nuodb/nuodb-helm-charts/v3/test/testlib"
"github.com/stretchr/testify/assert"

"testing"
)

func TestUnmarshall(t *testing.T) {
s := (
`{
s := (`{
"address": "172.17.0.6",
"dbName": "demo",
"durableState": "MONITORED",
Expand Down Expand Up @@ -64,6 +64,7 @@ func TestUnmarshall(t *testing.T) {
assert.True(t, obj.Hostname == "te-database-rggfj1-nuodb-demo-57f984dcd5-s7nhr")
assert.True(t, obj.Host == "admin-kljkzo-nuodb-0")
assert.True(t, obj.DbName == "demo")
assert.True(t, obj.StartId == "1")

_, ok := obj.Labels["cloud"]
assert.True(t, ok)
Expand All @@ -79,8 +80,7 @@ func TestUnmarshall(t *testing.T) {
}

func TestUnmarshallMany(t *testing.T) {
s := (
`{
s := (`{
"address": "172.17.0.7",
"archiveDir": "/var/opt/nuodb/archive/nuodb/demo",
"archiveId": 0,
Expand Down Expand Up @@ -136,22 +136,23 @@ func TestUnmarshallMany(t *testing.T) {

func TestMarshall(t *testing.T) {

labels := map[string]string {
"cloud": "minikube",
labels := map[string]string{
"cloud": "minikube",
"region": "local",
"zone": "local-b",
"zone": "local-b",
}

obj := testlib.NuoDBProcess {
Address: "172.17.0.6",
DbName: "demo",
Host: "admin-kljkzo-nuodb-0",
obj := testlib.NuoDBProcess{
Address: "172.17.0.6",
DbName: "demo",
Host: "admin-kljkzo-nuodb-0",
Hostname: "te-database-rggfj1-nuodb-demo-57f984dcd5-s7nhr",
Labels: labels,
Labels: labels,
StartId: "0",
}
b, err := json.Marshal(&obj)

assert.NoError(t, err)

t.Log(string(b))
}
}
2 changes: 1 addition & 1 deletion test/integration/template_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ func TestAutomaticDatabaseProtocolUpgrade(t *testing.T) {
assert.Equal(t, "true", obj.Annotations["nuodb.com/automatic-database-protocol-upgrade"])
assert.Equal(t,
options.SetValues["database.automaticProtocolUpgrade.tePreferenceQuery"],
obj.Annotations["nuodb.com/automatic-database-protocol-upgrade.te-preference-policy"])
obj.Annotations["nuodb.com/automatic-database-protocol-upgrade.te-preference-query"])
}
})
}
Expand Down
38 changes: 31 additions & 7 deletions test/minikube/minikube_rolling_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package minikube
import (
"fmt"
"regexp"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -244,8 +245,33 @@ func TestKubernetesUpgradeFullDatabase(t *testing.T) {
// check that KAA will upgrade database protocol version and restart TE
// automatically
t.Run("verifyProtocolVersion", func(t *testing.T) {
// start two TEs so that we can supply TE preference query
options.SetValues["database.te.replicas"] = "2"
helm.Upgrade(t, &options, testlib.DATABASE_HELM_CHART_PATH, databaseHelmChartReleaseName)
testlib.AwaitDatabaseUp(t, namespaceName, admin0, opt.DbName, 3)
// find the startId of the second TE
var toShutdownStartId int64 = -1
toShutdownPod := ""
processes, err := testlib.GetDatabaseProcessesE(t, namespaceName, admin0, opt.DbName)
require.NoError(t, err)
for _, process := range processes {
if process.Type == "TE" {
startId, err := strconv.ParseInt(process.StartId, 10, 64)
require.NoError(t, err)
if startId > toShutdownStartId {
toShutdownStartId = startId
toShutdownPod = process.Hostname
}
}
}
require.NotEqual(t, -1, toShutdownStartId, "Unable to find TE to shutdown")
// enable automatic protocol upgrade
options.SetValues["database.automaticProtocolUpgrade.enabled"] = "true"
// supply LB query which will select the second TE to be shutdown
// after protocol upgrade
options.SetValues["database.automaticProtocolUpgrade.tePreferenceQuery"] =
fmt.Sprintf("random(start_id(%d))", toShutdownStartId)

helm.Upgrade(t, &options, testlib.DATABASE_HELM_CHART_PATH, databaseHelmChartReleaseName)

// protocol upgrade is async task
Expand Down Expand Up @@ -276,14 +302,12 @@ func TestKubernetesUpgradeFullDatabase(t *testing.T) {
// verify that a TE has been restarted and SQL layer version is
// upgrade is performed
testlib.Await(t, func() bool {
return testlib.GetRegexOccurrenceInLog(t, namespaceName, admin0,
"Shutting down startId=[0-9]+ to finalize the database protocol upgrade",
return testlib.GetStringOccurrenceInLog(t, namespaceName, admin0,
fmt.Sprintf("Shutting down startId=%d to finalize the database protocol upgrade", toShutdownStartId),
&corev1.PodLogOptions{}) >= 1
}, 60*time.Second)
podName := testlib.GetPodName(t, namespaceName,
fmt.Sprintf("te-%s-nuodb-cluster0-%s", databaseHelmChartReleaseName, opt.DbName))
testlib.AwaitPodRestartCountGreaterThan(t, namespaceName, podName, 0, 30*time.Second)
testlib.AwaitDatabaseUp(t, namespaceName, admin0, opt.DbName, 2)
testlib.AwaitPodRestartCountGreaterThan(t, namespaceName, toShutdownPod, 0, 30*time.Second)
testlib.AwaitDatabaseUp(t, namespaceName, admin0, opt.DbName, 3)
output, err = testlib.RunSQL(t, namespaceName, admin0, opt.DbName,
"select version from system.versions"+
" where property = 'SYSTEM_TABLES_VERSION'"+
Expand All @@ -297,7 +321,7 @@ func TestKubernetesUpgradeFullDatabase(t *testing.T) {
// response is inspected
testlib.Await(t, func() bool {
adminPod := testlib.GetPod(t, namespaceName, admin0)
actualImageId, err := k8s.RunKubectlAndGetOutputE(t, options.KubectlOptions, "exec", admin0, "--",
actualImageId, err := k8s.RunKubectlAndGetOutputE(t, options.KubectlOptions, "exec", admin0, "-c", "admin", "--",
"nuocmd", "get", "value", "--key", fmt.Sprintf("upgradeDatabaseLastObservedImage/%s", opt.DbName))
require.NoError(t, err, "error getting last observed image ID")
return adminPod.Status.ContainerStatuses[0].ImageID == actualImageId
Expand Down
1 change: 1 addition & 0 deletions test/testlib/NuoDBProcess.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type NuoDBProcess struct {
IpAddress string `json:"ipAddress"`
Options map[string]string `json:"options"`
NodeId int32 `json:"nodeId"`
StartId string `json:"startId"`
}

func Unmarshal(s string) (err error, processes []NuoDBProcess) {
Expand Down

0 comments on commit b91d12d

Please sign in to comment.