fix(chart): blockmaster is recreated on upgrade, not rolled (#1031)

Merge note (batch b10; pull_request_target spec-trace workflow has a startup_failure, so its checks run locally):
- One Test run (47257294637) succeeded (go test (linux), process-level tests (real binaries)) on the integration tree 0dc39105 = main 6880c49c + #1030 #1031  in this order; these squash merges reproduce that tree, verified after the last one.
- spec-trace-check.sh and public-text-check.sh, run with main's scripts against this head and body: both exit 0.
This commit is contained in:
pingqiu-cpu authored and GitHub committed 2026-12-03 19:45:41 -08:00
1 parent b6ca54c4c8
commit 063aa07ae2
3 files changed
+176

No files matched your search

@@ -35,6 +35,11 @@ metadata:
app: sw-blockmaster
spec:
replicas: {{ .Values.blockmaster.replicas }}
# blockmaster uses the host network and, with a state path, is pinned to
# one node: a rolling update's new pod can never start beside the old one
# (same host ports, only that node). An upgrade stops the old pod first.
strategy:
type: Recreate
selector:
matchLabels:
app: sw-blockmaster
@@ -0,0 +1,165 @@
package main
import (
"bytes"
"fmt"
"os"
"path/filepath"
"reflect"
"strconv"
"strings"
"testing"
"text/template"
"gopkg.in/yaml.v3"
)
// renderChartTemplate renders one chart template, with the chart's helpers,
// from its values.yaml changed by edit, using the Helm functions the chart
// uses (lookup answers nothing: a new release). It returns the rendered
// documents decoded as YAML.
func renderChartTemplate(t *testing.T, name string, edit func(values map[string]any)) []map[string]any {
t.Helper()
chart := filepath.Join("..", "..", "charts", "seaweed-block")
read := func(p ...string) []byte {
b, err := os.ReadFile(filepath.Join(append([]string{chart}, p...)...))
if err != nil {
t.Fatal(err)
}
return b
}
values, meta := map[string]any{}, map[string]any{}
if err := yaml.Unmarshal(read("values.yaml"), &values); err != nil {
t.Fatal(err)
}
if err := yaml.Unmarshal(read("Chart.yaml"), &meta); err != nil {
t.Fatal(err)
}
edit(values)
empty := func(v any) bool {
if v == nil {
return true
}
r := reflect.ValueOf(v)
switch r.Kind() {
case reflect.Map, reflect.Slice, reflect.String:
return r.Len() == 0
case reflect.Bool:
return !r.Bool()
}
return r.IsZero()
}
var tp *template.Template
funcs := template.FuncMap{
"fail": func(msg string) (string, error) { return "", &templateFail{msg} },
"include": func(name string, data any) (string, error) {
var b bytes.Buffer
err := tp.ExecuteTemplate(&b, name, data)
return b.String(), err
},
"toYaml": func(v any) (string, error) {
b, err := yaml.Marshal(v)
return strings.TrimSuffix(string(b), "\n"), err
},
"nindent": func(n int, s string) string {
pad := strings.Repeat(" ", n)
return "\n" + pad + strings.ReplaceAll(s, "\n", "\n"+pad)
},
"quote": func(v any) string {
if v == nil {
return `""`
}
return strconv.Quote(fmt.Sprint(v))
},
"default": func(d any, given ...any) any {
if len(given) == 0 || empty(given[0]) {
return d
}
return given[0]
},
"dict": func() map[string]any { return map[string]any{} },
"empty": empty,
"int": func(v any) int {
switch x := v.(type) {
case int:
return x
case float64:
return int(x)
case string:
n, _ := strconv.Atoi(x)
return n
}
return 0
},
"lookup": func(string, string, string, string) map[string]any { return map[string]any{} },
"replace": func(old, new, s string) string { return strings.ReplaceAll(s, old, new) },
"trimSuffix": func(suffix, s string) string { return strings.TrimSuffix(s, suffix) },
"trunc": func(n int, s string) string {
if len(s) > n {
return s[:n]
}
return s
},
}
tp = template.New(name).Funcs(funcs)
if _, err := tp.New("_helpers.tpl").Parse(string(read("templates", "_helpers.tpl"))); err != nil {
t.Fatal(err)
}
if _, err := tp.New(name).Parse(string(read("templates", name))); err != nil {
t.Fatal(err)
}
var out bytes.Buffer
data := map[string]any{
"Values": values,
"Release": map[string]any{"Name": "sw-block", "Namespace": "sw", "Service": "Helm"},
"Chart": map[string]any{"Name": meta["name"], "Version": meta["version"]},
}
if err := tp.ExecuteTemplate(&out, name, data); err != nil {
t.Fatalf("render %s: %v", name, err)
}
var docs []map[string]any
for _, part := range strings.Split(out.String(), "\n---") {
doc := map[string]any{}
if err := yaml.Unmarshal([]byte(part), &doc); err != nil {
t.Fatalf("rendered %s is not YAML: %v\n%s", name, err, part)
}
if len(doc) > 0 {
docs = append(docs, doc)
}
}
return docs
}
// blockmaster uses the host network and, with a state path, is pinned to one
// node by hostname: a rolling update's new pod can never be scheduled beside
// the old one (same host ports, only that node), so every upgrade that
// changes its pod would wait forever. Its Deployment is replaced, not rolled:
// rendered with the default state path and with ephemeral state alike.
func TestBlockmasterDeploymentIsRecreatedNotRolled(t *testing.T) {
section := func(v map[string]any, k string) map[string]any { return v[k].(map[string]any) }
pinned := func(v map[string]any) {
section(v, "blockmaster")["nodeSelector"] = map[string]any{"kubernetes.io/hostname": "n1"}
}
for _, c := range []struct {
name string
edit func(map[string]any)
}{
{"state path, pinned by hostname", pinned},
{"ephemeral state", func(v map[string]any) { section(v, "blockmaster")["stateHostPath"] = "" }},
} {
var deployment map[string]any
for _, doc := range renderChartTemplate(t, "blockmaster.yaml", c.edit) {
if md, _ := doc["metadata"].(map[string]any); doc["kind"] == "Deployment" && md["name"] == "sw-blockmaster" {
deployment = doc
}
}
if deployment == nil {
t.Fatalf("%s: no sw-blockmaster Deployment rendered", c.name)
}
spec, _ := deployment["spec"].(map[string]any)
strategy, _ := spec["strategy"].(map[string]any)
if strategy["type"] != "Recreate" {
t.Errorf("%s: blockmaster strategy %v, want Recreate (a rolling update never schedules its new pod)", c.name, spec["strategy"])
}
}
}
+6
View File
@@ -128,6 +128,12 @@ v1.1.1 is a fix release of the v1.1 line. None of its changes alters a stored fo
starts as before, and one with an empty state directory exits 75 `master_too_old`.
- blockmaster keeps its stores on the same path, so the chart requires `blockmaster.nodeSelector` with a
state path (`generate-helm-values` sets it to the target node).
- A `helm upgrade` that changes blockmaster's pod stops blockmaster briefly: its Deployment is recreated, not
rolled (`strategy: Recreate`), so the old pod exits before the new one starts. A rolling update could never
start the new pod, which needs the old one's host ports on the same node. Holders keep serving I/O during that
stop while their current lease lasts (about 20 s). If blockmaster is down longer, holders stop I/O and restart;
volumes resume once blockmaster is back. Upgrade at a quiet time, and check with `helm upgrade --wait` that
blockmaster is back.
- Upgrading a release that runs with ephemeral state to a state path stops at render unless
`restartPersistence.acknowledgeEphemeralDataLoss=true`: the switch discards those volumes' data (still
live in their pods until they restart), and their holders then refuse to start empty.