Skip to content

Commit 6c9bcc6

Browse files
authored
Fix dapr upgrade command incorrectly detecting HA mode for new version 1.15 (#1494)
* Fix dapr upgrade command detecting HA mode for new version 1.15 The issue is that the scheduler by default uses 3 replicas, which incorrectly identified non-HA install as HA. Signed-off-by: Anton Troshin <[email protected]> * Fix e2e Signed-off-by: Anton Troshin <[email protected]> --------- Signed-off-by: Anton Troshin <[email protected]>
1 parent bd09c94 commit 6c9bcc6

File tree

3 files changed

+100
-5
lines changed

3 files changed

+100
-5
lines changed

pkg/kubernetes/upgrade.go

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"fmt"
1818
"net/http"
1919
"os"
20+
"strings"
2021
"time"
2122

2223
helm "helm.sh/helm/v3/pkg/action"
@@ -255,6 +256,11 @@ func highAvailabilityEnabled(status []StatusOutput) bool {
255256
if s.Name == "dapr-dashboard" {
256257
continue
257258
}
259+
// Skip the scheduler server because it's in HA mode by default since version 1.15.0
260+
// This will fall back to other dapr services to determine if HA mode is enabled.
261+
if strings.HasPrefix(s.Name, "dapr-scheduler-server") {
262+
continue
263+
}
258264
if s.Replicas > 1 {
259265
return true
260266
}

pkg/kubernetes/upgrade_test.go

+72
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,38 @@ func TestHAMode(t *testing.T) {
3131
assert.True(t, r)
3232
})
3333

34+
t.Run("ha mode with scheduler and other services", func(t *testing.T) {
35+
s := []StatusOutput{
36+
{
37+
Name: "dapr-scheduler-server",
38+
Replicas: 3,
39+
},
40+
{
41+
Name: "dapr-placement-server",
42+
Replicas: 3,
43+
},
44+
}
45+
46+
r := highAvailabilityEnabled(s)
47+
assert.True(t, r)
48+
})
49+
50+
t.Run("non-ha mode with only scheduler image variant", func(t *testing.T) {
51+
s := []StatusOutput{
52+
{
53+
Name: "dapr-scheduler-server-mariner",
54+
Replicas: 3,
55+
},
56+
{
57+
Name: "dapr-placement-server-mariner",
58+
Replicas: 3,
59+
},
60+
}
61+
62+
r := highAvailabilityEnabled(s)
63+
assert.True(t, r)
64+
})
65+
3466
t.Run("non-ha mode", func(t *testing.T) {
3567
s := []StatusOutput{
3668
{
@@ -41,6 +73,46 @@ func TestHAMode(t *testing.T) {
4173
r := highAvailabilityEnabled(s)
4274
assert.False(t, r)
4375
})
76+
77+
t.Run("non-ha mode with scheduler and other services", func(t *testing.T) {
78+
s := []StatusOutput{
79+
{
80+
Name: "dapr-scheduler-server",
81+
Replicas: 3,
82+
},
83+
{
84+
Name: "dapr-placement-server",
85+
Replicas: 1,
86+
},
87+
}
88+
89+
r := highAvailabilityEnabled(s)
90+
assert.False(t, r)
91+
})
92+
93+
t.Run("non-ha mode with only scheduler", func(t *testing.T) {
94+
s := []StatusOutput{
95+
{
96+
Name: "dapr-scheduler-server",
97+
Replicas: 3,
98+
},
99+
}
100+
101+
r := highAvailabilityEnabled(s)
102+
assert.False(t, r)
103+
})
104+
105+
t.Run("non-ha mode with only scheduler image variant", func(t *testing.T) {
106+
s := []StatusOutput{
107+
{
108+
Name: "dapr-scheduler-server-mariner",
109+
Replicas: 3,
110+
},
111+
}
112+
113+
r := highAvailabilityEnabled(s)
114+
assert.False(t, r)
115+
})
44116
}
45117

46118
func TestMTLSChartValues(t *testing.T) {

tests/e2e/common/common.go

+22-5
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,12 @@ func StatusTestOnInstallUpgrade(details VersionDetails, opts TestOptions) func(t
368368
daprPath := GetDaprPath()
369369
output, err := spawn.Command(daprPath, "status", "-k")
370370
require.NoError(t, err, "status check failed")
371+
372+
version, err := semver.NewVersion(details.RuntimeVersion)
373+
if err != nil {
374+
t.Error("failed to parse runtime version", err)
375+
}
376+
371377
var notFound map[string][]string
372378
if !opts.HAEnabled {
373379
notFound = map[string][]string{
@@ -377,6 +383,11 @@ func StatusTestOnInstallUpgrade(details VersionDetails, opts TestOptions) func(t
377383
"dapr-placement-server": {details.RuntimeVersion, "1"},
378384
"dapr-operator": {details.RuntimeVersion, "1"},
379385
}
386+
if version.GreaterThanEqual(VersionWithHAScheduler) {
387+
notFound["dapr-scheduler-server"] = []string{details.RuntimeVersion, "3"}
388+
} else if version.GreaterThanEqual(VersionWithScheduler) {
389+
notFound["dapr-scheduler-server"] = []string{details.RuntimeVersion, "1"}
390+
}
380391
} else {
381392
notFound = map[string][]string{
382393
"dapr-sentry": {details.RuntimeVersion, "3"},
@@ -385,13 +396,19 @@ func StatusTestOnInstallUpgrade(details VersionDetails, opts TestOptions) func(t
385396
"dapr-placement-server": {details.RuntimeVersion, "3"},
386397
"dapr-operator": {details.RuntimeVersion, "3"},
387398
}
399+
if version.GreaterThanEqual(VersionWithScheduler) {
400+
notFound["dapr-scheduler-server"] = []string{details.RuntimeVersion, "3"}
401+
}
388402
}
389403

390404
if details.ImageVariant != "" {
391405
notFound["dapr-sentry"][0] = notFound["dapr-sentry"][0] + "-" + details.ImageVariant
392406
notFound["dapr-sidecar-injector"][0] = notFound["dapr-sidecar-injector"][0] + "-" + details.ImageVariant
393407
notFound["dapr-placement-server"][0] = notFound["dapr-placement-server"][0] + "-" + details.ImageVariant
394408
notFound["dapr-operator"][0] = notFound["dapr-operator"][0] + "-" + details.ImageVariant
409+
if notFound["dapr-scheduler-server"] != nil {
410+
notFound["dapr-scheduler-server"][0] = notFound["dapr-scheduler-server"][0] + "-" + details.ImageVariant
411+
}
395412
}
396413

397414
lines := strings.Split(output, "\n")[1:] // remove header of status.
@@ -400,13 +417,13 @@ func StatusTestOnInstallUpgrade(details VersionDetails, opts TestOptions) func(t
400417
cols := strings.Fields(strings.TrimSpace(line))
401418
if len(cols) > 6 { // atleast 6 fields are verified from status (Age and created time are not).
402419
if toVerify, ok := notFound[cols[0]]; ok { // get by name.
403-
require.Equal(t, DaprTestNamespace, cols[1], "namespace must match")
404-
require.Equal(t, "True", cols[2], "healthly field must be true")
405-
require.Equal(t, "Running", cols[3], "pods must be Running")
406-
require.Equal(t, toVerify[1], cols[4], "replicas must be equal")
420+
require.Equal(t, DaprTestNamespace, cols[1], "%s namespace must match", cols[0])
421+
require.Equal(t, "True", cols[2], "%s healthy field must be true", cols[0])
422+
require.Equal(t, "Running", cols[3], "%s pods must be Running", cols[0])
423+
require.Equal(t, toVerify[1], cols[4], "%s replicas must be equal", cols[0])
407424
// TODO: Skip the dashboard version check for now until the helm chart is updated.
408425
if cols[0] != "dapr-dashboard" {
409-
require.Equal(t, toVerify[0], cols[5], "versions must match")
426+
require.Equal(t, toVerify[0], cols[5], "%s versions must match", cols[0])
410427
}
411428
delete(notFound, cols[0])
412429
}

0 commit comments

Comments
 (0)