mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
fix(k8s): generated volumes' state is apart from blockmaster's stores (#1036)
Merge note (batch b13; pull_request_target spec-trace workflow has a startup_failure, so its checks run locally): - One Test run (47268279447) succeeded (go test (linux), process-level tests (real binaries)) on the integration tree 78104cee = main 40c56035 + #1033 #1034 #1036 #1038 #1035 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:
1 parent
17d01be259
commit
bddb559dff
11 files changed
+282
-104
No files matched your search
@@ -8,7 +8,11 @@ Next checks:
|
||||
Create volumes through Kubernetes PVCs using StorageClass {{ .Values.storageClass.name }}.
|
||||
{{- if .Values.blockmaster.stateHostPath }}
|
||||
|
||||
Volume state is kept on each node under {{ .Values.blockmaster.stateHostPath }}.
|
||||
Volume state is kept on each node under {{ include "seaweed-block.volumeStatePath" . }}; blockmaster's stores under {{ .Values.blockmaster.stateHostPath }}.
|
||||
{{- if eq (include "seaweed-block.volumeStatePath" .) (clean .Values.blockmaster.stateHostPath) }}
|
||||
|
||||
WARNING: the generated blockvolume pods share blockmaster's state path (a v1.1.0 layout), so every one of them on blockmaster's node mounts blockmaster's authority and lifecycle stores read-write. To separate them without moving volume data, see "Kubernetes: volume state persists by default" in the v1.1.1 release notes.
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
|
||||
WARNING: ephemeral restart persistence loses all data whenever a holder pod restarts (blockmaster.stateHostPath is empty).
|
||||
|
||||
@@ -98,3 +98,20 @@ helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
|
||||
secret:
|
||||
secretName: {{ . }}
|
||||
{{- end -}}
|
||||
|
||||
{{/*
|
||||
The generated blockvolume pods' state path on each node: restartPersistence.stateHostPath when set; empty, the
|
||||
volumes directory beside blockmaster's when blockmaster's path ends in /master (this release's layout); otherwise
|
||||
blockmaster's own path (the shared layout of a v1.1.0 install). "" with ephemeral state.
|
||||
*/}}
|
||||
{{- define "seaweed-block.volumeStatePath" -}}
|
||||
{{- $master := .Values.blockmaster.stateHostPath | default "" -}}
|
||||
{{- if not $master -}}
|
||||
{{- else if .Values.restartPersistence.stateHostPath -}}
|
||||
{{- clean .Values.restartPersistence.stateHostPath -}}
|
||||
{{- else if eq (base (clean $master)) "master" -}}
|
||||
{{- printf "%s/volumes" (dir (clean $master)) | clean -}}
|
||||
{{- else -}}
|
||||
{{- clean $master -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -13,6 +13,13 @@
|
||||
{{- if and .Values.blockmaster.stateHostPath (not (index (.Values.blockmaster.nodeSelector | default dict) "kubernetes.io/hostname")) -}}
|
||||
{{- fail "blockmaster.stateHostPath keeps blockmaster's stores on one node: set blockmaster.nodeSelector.kubernetes.io/hostname to that node (a broader selector can start it on another node, on an empty state path)" -}}
|
||||
{{- end -}}
|
||||
{{- $volumeState := include "seaweed-block.volumeStatePath" . -}}
|
||||
{{- if and $volumeState (ne $volumeState (clean .Values.blockmaster.stateHostPath)) (hasPrefix (printf "%s/" (trimSuffix "/" $volumeState)) (clean .Values.blockmaster.stateHostPath)) -}}
|
||||
{{- fail "restartPersistence.stateHostPath is above blockmaster.stateHostPath: every generated blockvolume pod mounts its state path, so it would mount blockmaster's stores: put the two side by side (for example <base>/volumes and <base>/master)" -}}
|
||||
{{- end -}}
|
||||
{{- if and .Release.IsInstall .Values.blockmaster.stateHostPath (not .Values.restartPersistence.stateHostPath) (ne (base (clean .Values.blockmaster.stateHostPath)) "master") -}}
|
||||
{{- fail "blockmaster.stateHostPath is outside the default layout and restartPersistence.stateHostPath is unset: a new install would put the generated blockvolume pods' state in blockmaster's directory, so they would mount its stores: set restartPersistence.stateHostPath beside blockmaster.stateHostPath (not above it)" -}}
|
||||
{{- end -}}
|
||||
{{- if and .Values.blockmaster.stateHostPath (not .Values.restartPersistence.acknowledgeEphemeralDataLoss) -}}
|
||||
{{- $running := lookup "apps/v1" "Deployment" .Release.Namespace "sw-blockmaster" -}}
|
||||
{{- if $running -}}
|
||||
@@ -110,7 +117,7 @@ spec:
|
||||
- "--launcher-pvc-owner-ref"
|
||||
{{- end }}
|
||||
{{- if .Values.blockmaster.stateHostPath }}
|
||||
- "--launcher-state-hostpath={{ .Values.blockmaster.stateHostPath }}"
|
||||
- "--launcher-state-hostpath={{ include "seaweed-block.volumeStatePath" . }}"
|
||||
{{- end }}
|
||||
{{- if .Values.network.externalISCSI }}
|
||||
- "--launcher-external-iscsi"
|
||||
|
||||
@@ -46,13 +46,13 @@ blockmaster:
|
||||
durableImpl: walstore
|
||||
durableWALMultiBlockRecords: false
|
||||
durableWALRecoveryTestDisableFlusher: false
|
||||
# Generated blockvolume state (and blockmaster's stores) on this node path,
|
||||
# one directory per volume replica; the holder pod is pinned to its node.
|
||||
# blockmaster keeps its stores here too: set blockmaster.nodeSelector's
|
||||
# blockmaster's stores on this node path: set blockmaster.nodeSelector's
|
||||
# kubernetes.io/hostname to the node that holds them (rendering fails
|
||||
# without it; generate-helm-values sets it).
|
||||
# without it; generate-helm-values sets it). Generated blockvolume state
|
||||
# goes to restartPersistence.stateHostPath, a separate path, so a holder
|
||||
# pod never mounts blockmaster's stores.
|
||||
# "" is ephemeral: an emptyDir, and ephemeral restart persistence loses all data whenever a holder pod restarts.
|
||||
stateHostPath: /var/lib/sw-block/k8s
|
||||
stateHostPath: /var/lib/sw-block/k8s/master
|
||||
stateHostPathType: DirectoryOrCreate
|
||||
statePermissionsImage:
|
||||
repository: busybox
|
||||
@@ -65,7 +65,13 @@ restartPersistence:
|
||||
# across Kubernetes pod restarts. ephemeral is an explicit opt-in (with
|
||||
# blockmaster.stateHostPath ""): ephemeral restart persistence loses all data whenever a holder pod restarts.
|
||||
mode: hostpath
|
||||
stateHostPath: /var/lib/sw-block/k8s
|
||||
# Generated blockvolume state on each node, one directory per volume
|
||||
# replica (<stateHostPath>/<replica>/<volume>-<id>); the holder pod is
|
||||
# pinned to its node. Empty (the default): the volumes directory beside
|
||||
# blockmaster's when blockmaster.stateHostPath ends in /master
|
||||
# (/var/lib/sw-block/k8s/volumes by default); otherwise
|
||||
# blockmaster.stateHostPath itself, the shared layout of a v1.1.0 install.
|
||||
stateHostPath: ""
|
||||
# Upgrading a release that runs with ephemeral state to a stateHostPath
|
||||
# stops at render unless this is true: the switch discards its volumes'
|
||||
# data (still live in their pods until they restart).
|
||||
|
||||
@@ -2,8 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strconv"
|
||||
@@ -14,11 +16,45 @@ import (
|
||||
"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.
|
||||
// renderChartTemplate renders one chart template for a new release (lookup
|
||||
// answers nothing) and fails the test if the template refuses to render.
|
||||
func renderChartTemplate(t *testing.T, name string, edit func(values map[string]any)) []map[string]any {
|
||||
t.Helper()
|
||||
docs, refused := renderChart(t, name, edit, nil)
|
||||
if refused != "" {
|
||||
t.Fatalf("render %s refused: %s", name, refused)
|
||||
}
|
||||
return docs
|
||||
}
|
||||
|
||||
// renderChart renders one chart template (see renderChartText) and returns
|
||||
// its documents decoded as YAML, or the template's fail message when it
|
||||
// refuses to render.
|
||||
func renderChart(t *testing.T, name string, edit func(values map[string]any), running map[string]any) ([]map[string]any, string) {
|
||||
t.Helper()
|
||||
text, refused := renderChartText(t, name, edit, running)
|
||||
if refused != "" {
|
||||
return nil, refused
|
||||
}
|
||||
var docs []map[string]any
|
||||
for _, part := range strings.Split(text, "\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, ""
|
||||
}
|
||||
|
||||
// renderChartText renders one chart template, with the chart's helpers, from
|
||||
// its values.yaml changed by edit, using the Helm functions the chart uses.
|
||||
// running is the release's existing blockmaster Deployment, which lookup
|
||||
// answers: nil renders an install (.Release.IsInstall), anything else an
|
||||
// upgrade. It returns the rendered text, or the template's fail message.
|
||||
func renderChartText(t *testing.T, name string, edit func(values map[string]any), running map[string]any) (string, string) {
|
||||
t.Helper()
|
||||
chart := filepath.Join("..", "..", "charts", "seaweed-block")
|
||||
read := func(p ...string) []byte {
|
||||
@@ -91,8 +127,17 @@ func renderChartTemplate(t *testing.T, name string, edit func(values map[string]
|
||||
}
|
||||
return 0
|
||||
},
|
||||
"lookup": func(string, string, string, string) map[string]any { return map[string]any{} },
|
||||
"lookup": func(apiVersion, kind, namespace, name string) map[string]any {
|
||||
if apiVersion != "apps/v1" || kind != "Deployment" || namespace != "sw" || name != "sw-blockmaster" || running == nil {
|
||||
return map[string]any{} // Helm answers an absent object with an empty map
|
||||
}
|
||||
return running
|
||||
},
|
||||
"clean": path.Clean,
|
||||
"base": path.Base,
|
||||
"dir": path.Dir,
|
||||
"replace": func(old, new, s string) string { return strings.ReplaceAll(s, old, new) },
|
||||
"hasPrefix": func(prefix, s string) bool { return strings.HasPrefix(s, prefix) },
|
||||
"trimSuffix": func(suffix, s string) string { return strings.TrimSuffix(s, suffix) },
|
||||
"trunc": func(n int, s string) string {
|
||||
if len(s) > n {
|
||||
@@ -111,23 +156,17 @@ func renderChartTemplate(t *testing.T, name string, edit func(values map[string]
|
||||
var out bytes.Buffer
|
||||
data := map[string]any{
|
||||
"Values": values,
|
||||
"Release": map[string]any{"Name": "sw-block", "Namespace": "sw", "Service": "Helm"},
|
||||
"Release": map[string]any{"Name": "sw-block", "Namespace": "sw", "Service": "Helm", "IsInstall": running == nil, "IsUpgrade": running != nil},
|
||||
"Chart": map[string]any{"Name": meta["name"], "Version": meta["version"]},
|
||||
}
|
||||
if err := tp.ExecuteTemplate(&out, name, data); err != nil {
|
||||
var f *templateFail
|
||||
if errors.As(err, &f) {
|
||||
return "", f.msg
|
||||
}
|
||||
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
|
||||
return out.String(), ""
|
||||
}
|
||||
|
||||
// blockmaster uses the host network and, with a state path, is pinned to one
|
||||
@@ -163,3 +202,123 @@ func TestBlockmasterDeploymentIsRecreatedNotRolled(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// blockmaster's stores and the generated blockvolume pods' state are on
|
||||
// separate node paths: a holder pod mounts only its own state path, never
|
||||
// blockmaster's authority and lifecycle stores. A release that sets one path
|
||||
// for both (a v1.1.0 install) keeps that shared layout instead of moving
|
||||
// its volumes; ephemeral state passes no path.
|
||||
func TestHolderStateIsApartFromBlockmasterStores(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"}
|
||||
}
|
||||
// upgrade renders over a running blockmaster on a state path (an
|
||||
// existing release); otherwise the render is a new install.
|
||||
upgradeOf := blockmasterDeploymentWith(map[string]any{"name": "state", "hostPath": map[string]any{"path": "/var/lib/sw-block"}})
|
||||
render := func(edit func(map[string]any), upgrade bool) ([]map[string]any, string) {
|
||||
t.Helper()
|
||||
var running map[string]any
|
||||
if upgrade {
|
||||
running = upgradeOf
|
||||
}
|
||||
return renderChart(t, "blockmaster.yaml", edit, running)
|
||||
}
|
||||
paths := func(edit func(map[string]any), upgrade bool) (master, holders string) {
|
||||
t.Helper()
|
||||
docs, refused := render(edit, upgrade)
|
||||
if refused != "" {
|
||||
t.Fatalf("render refused: %s", refused)
|
||||
}
|
||||
for _, doc := range docs {
|
||||
if md, _ := doc["metadata"].(map[string]any); doc["kind"] != "Deployment" || md["name"] != "sw-blockmaster" {
|
||||
continue
|
||||
}
|
||||
pod := doc["spec"].(map[string]any)["template"].(map[string]any)["spec"].(map[string]any)
|
||||
for _, v := range pod["volumes"].([]any) {
|
||||
if vol := v.(map[string]any); vol["name"] == "state" {
|
||||
if hp, ok := vol["hostPath"].(map[string]any); ok {
|
||||
master, _ = hp["path"].(string)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, c := range pod["containers"].([]any) {
|
||||
for _, a := range c.(map[string]any)["args"].([]any) {
|
||||
if s, _ := a.(string); strings.HasPrefix(s, "--launcher-state-hostpath=") {
|
||||
holders = strings.TrimPrefix(s, "--launcher-state-hostpath=")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return master, holders
|
||||
}
|
||||
if m, h := paths(pinned, false); m != "/var/lib/sw-block/k8s/master" || h != "/var/lib/sw-block/k8s/volumes" {
|
||||
t.Errorf("default paths: blockmaster %q, holders %q; want /var/lib/sw-block/k8s/master and /var/lib/sw-block/k8s/volumes", m, h)
|
||||
}
|
||||
v110 := map[string]func(map[string]any){
|
||||
"a v1.1.0 values file that sets only blockmaster.stateHostPath": func(v map[string]any) {
|
||||
pinned(v)
|
||||
section(v, "blockmaster")["stateHostPath"] = "/var/lib/sw-block"
|
||||
},
|
||||
"a v1.1.0 generated values file (both paths the same)": func(v map[string]any) {
|
||||
pinned(v)
|
||||
section(v, "blockmaster")["stateHostPath"] = "/var/lib/sw-block"
|
||||
section(v, "restartPersistence")["stateHostPath"] = "/var/lib/sw-block"
|
||||
},
|
||||
}
|
||||
for name, edit := range v110 {
|
||||
if m, h := paths(edit, true); m != "/var/lib/sw-block" || h != "/var/lib/sw-block" {
|
||||
t.Errorf("%s: blockmaster %q, holders %q; want both /var/lib/sw-block (its volumes stay where they are)", name, m, h)
|
||||
}
|
||||
}
|
||||
if m, h := paths(func(v map[string]any) {
|
||||
pinned(v)
|
||||
section(v, "blockmaster")["stateHostPath"] = "/srv/sw/master/"
|
||||
}, false); m != "/srv/sw/master/" || h != "/srv/sw/volumes" {
|
||||
t.Errorf("a master path ending in /master: blockmaster %q, holders %q; want the volumes directory beside it", m, h)
|
||||
}
|
||||
if m, h := paths(func(v map[string]any) { section(v, "blockmaster")["stateHostPath"] = "" }, false); m != "" || h != "" {
|
||||
t.Errorf("ephemeral: blockmaster %q, holders %q; want no host paths", m, h)
|
||||
}
|
||||
|
||||
// A new install never gets the shared layout silently: a custom
|
||||
// blockmaster path outside the default layout needs the volumes path
|
||||
// set; with it, the install renders apart.
|
||||
custom := func(volumes string) func(map[string]any) {
|
||||
return func(v map[string]any) {
|
||||
pinned(v)
|
||||
section(v, "blockmaster")["stateHostPath"] = "/data/swb"
|
||||
section(v, "restartPersistence")["stateHostPath"] = volumes
|
||||
}
|
||||
}
|
||||
if _, refused := render(custom(""), false); !strings.Contains(refused, "set restartPersistence.stateHostPath beside blockmaster.stateHostPath") {
|
||||
t.Errorf("a new install with a custom blockmaster path and no volumes path: refused %q, want the beside-it refusal", refused)
|
||||
}
|
||||
if m, h := paths(custom("/data/swb-volumes"), false); m != "/data/swb" || h != "/data/swb-volumes" {
|
||||
t.Errorf("a new install with both paths set: blockmaster %q, holders %q", m, h)
|
||||
}
|
||||
|
||||
// Kept shared layout on an upgrade: the install notes warn and name the
|
||||
// exposure; the default layout prints no warning.
|
||||
notes := func(edit func(map[string]any), upgrade bool) string {
|
||||
t.Helper()
|
||||
var running map[string]any
|
||||
if upgrade {
|
||||
running = upgradeOf
|
||||
}
|
||||
text, refused := renderChartText(t, "NOTES.txt", edit, running)
|
||||
if refused != "" {
|
||||
t.Fatalf("NOTES refused: %s", refused)
|
||||
}
|
||||
return text
|
||||
}
|
||||
const shared = "WARNING: the generated blockvolume pods share blockmaster's state path"
|
||||
for name, edit := range v110 {
|
||||
if text := notes(edit, true); !strings.Contains(text, shared) || !strings.Contains(text, "authority and lifecycle stores") {
|
||||
t.Errorf("%s: the install notes do not warn about the shared layout:\n%s", name, text)
|
||||
}
|
||||
}
|
||||
if text := notes(pinned, false); strings.Contains(text, shared) {
|
||||
t.Errorf("the default layout warns about a shared layout:\n%s", text)
|
||||
}
|
||||
}
|
||||
@@ -1,76 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"text/template"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// renderBlockmasterGuards executes the guard block at the head of the chart's
|
||||
// blockmaster template (everything before its first manifest) with the
|
||||
// chart's own values.yaml, changed by edit, and the Helm functions it uses:
|
||||
// fail, default, dict and lookup, whose answer for the release's existing
|
||||
// blockmaster Deployment is running (nil: none). It returns the template's
|
||||
// fail message, "" when the render is admitted.
|
||||
// renderBlockmasterGuards renders the chart's blockmaster template with the
|
||||
// chart's own values.yaml, changed by edit, while lookup answers the
|
||||
// release's existing blockmaster Deployment with running (nil: none). It
|
||||
// returns the template's fail message, "" when the render is admitted.
|
||||
func renderBlockmasterGuards(t *testing.T, edit func(values map[string]any), running map[string]any) string {
|
||||
t.Helper()
|
||||
chart := filepath.Join("..", "..", "charts", "seaweed-block")
|
||||
raw, err := os.ReadFile(filepath.Join(chart, "values.yaml"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
values := map[string]any{}
|
||||
if err := yaml.Unmarshal(raw, &values); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
edit(values)
|
||||
tmpl, err := os.ReadFile(filepath.Join(chart, "templates", "blockmaster.yaml"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
head, _, found := strings.Cut(string(tmpl), "apiVersion: apps/v1")
|
||||
if !found || !strings.Contains(head, "lookup") {
|
||||
t.Fatal("the blockmaster template's guard block was not found before its Deployment")
|
||||
}
|
||||
funcs := template.FuncMap{
|
||||
"fail": func(msg string) (string, error) { return "", &templateFail{msg} },
|
||||
"dict": func() map[string]any { return map[string]any{} },
|
||||
"default": func(d any, given ...any) any {
|
||||
if len(given) == 0 || given[0] == nil {
|
||||
return d
|
||||
}
|
||||
if v := reflect.ValueOf(given[0]); (v.Kind() == reflect.Map || v.Kind() == reflect.Slice || v.Kind() == reflect.String) && v.Len() == 0 {
|
||||
return d
|
||||
}
|
||||
return given[0]
|
||||
},
|
||||
"lookup": func(apiVersion, kind, namespace, name string) map[string]any {
|
||||
if apiVersion != "apps/v1" || kind != "Deployment" || namespace != "sw" || name != "sw-blockmaster" || running == nil {
|
||||
return map[string]any{} // Helm answers an absent object with an empty map
|
||||
}
|
||||
return running
|
||||
},
|
||||
}
|
||||
tp, err := template.New("blockmaster").Funcs(funcs).Parse(head)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var out strings.Builder
|
||||
err = tp.Execute(&out, map[string]any{"Values": values, "Release": map[string]any{"Namespace": "sw"}})
|
||||
var f *templateFail
|
||||
if errors.As(err, &f) {
|
||||
return f.msg
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("render: %v", err)
|
||||
}
|
||||
return ""
|
||||
_, refused := renderChart(t, "blockmaster.yaml", edit, running)
|
||||
return refused
|
||||
}
|
||||
|
||||
type templateFail struct{ msg string }
|
||||
@@ -95,6 +37,10 @@ func TestChartStatePathGuardsRender(t *testing.T) {
|
||||
ephemeralRun := blockmasterDeploymentWith(map[string]any{"name": "state", "emptyDir": map[string]any{}})
|
||||
hostPathRun := blockmasterDeploymentWith(map[string]any{"name": "state", "hostPath": map[string]any{"path": "/var/lib/sw-block/k8s"}})
|
||||
const hostnameRefusal, ackRefusal = "set blockmaster.nodeSelector.kubernetes.io/hostname", "set restartPersistence.acknowledgeEphemeralDataLoss=true"
|
||||
const aboveRefusal = "restartPersistence.stateHostPath is above blockmaster.stateHostPath"
|
||||
volumes := func(p string) func(map[string]any) {
|
||||
return func(v map[string]any) { pinned(v); section(v, "restartPersistence")["stateHostPath"] = p }
|
||||
}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
edit func(map[string]any)
|
||||
@@ -112,6 +58,14 @@ func TestChartStatePathGuardsRender(t *testing.T) {
|
||||
section(v, "restartPersistence")["acknowledgeEphemeralDataLoss"] = true
|
||||
}, ephemeralRun, ""},
|
||||
{"pinned, over a release already on a state path", pinned, hostPathRun, ""},
|
||||
{"volumes path above the master's (v1.1.0's default base)", volumes("/var/lib/sw-block/k8s"), nil, aboveRefusal},
|
||||
{"volumes path above the master's, trailing slash", volumes("/var/lib/sw-block/k8s/"), nil, aboveRefusal},
|
||||
{"volumes path is the root", volumes("/"), nil, aboveRefusal},
|
||||
{"volumes path equal to the master's (kept v1.1.0 layout)", volumes("/var/lib/sw-block/k8s/master"), nil, ""},
|
||||
{"volumes path empty (beside the master's)", volumes(""), nil, ""},
|
||||
{"volumes path above the master's once cleaned", volumes("/var/lib/sw-block/k8s/x/.."), nil, aboveRefusal},
|
||||
{"volumes path beside the master's, a common name prefix", volumes("/var/lib/sw-block/k8s/mast"), nil, ""},
|
||||
{"volumes path below the master's", volumes("/var/lib/sw-block/k8s/master/volumes"), nil, ""},
|
||||
{"ephemeral stays ephemeral", func(v map[string]any) {
|
||||
section(v, "blockmaster")["stateHostPath"] = ""
|
||||
section(v, "blockmaster")["nodeSelector"] = map[string]any{"kubernetes.io/os": "linux"}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -1933,8 +1934,11 @@ func runOpsGenerateHelmValues(args []string, stdout, stderr io.Writer) int {
|
||||
values.Restart = &helmValuesRestart{Mode: restartPersistence}
|
||||
if restartPersistence == "hostpath" {
|
||||
// blockmaster's stores live on one node: pin it to the first selected one.
|
||||
values.Blockmaster = &helmValuesBlockmaster{StateHostPath: &stateHostPath, NodeSelector: map[string]string{"kubernetes.io/hostname": selected[0].Name}}
|
||||
values.Restart.StateHostPath = stateHostPath
|
||||
// Its stores and the volumes' state get separate paths under the base,
|
||||
// so a holder pod never mounts blockmaster's stores.
|
||||
masterPath := path.Join(stateHostPath, "master")
|
||||
values.Blockmaster = &helmValuesBlockmaster{StateHostPath: &masterPath, NodeSelector: map[string]string{"kubernetes.io/hostname": selected[0].Name}}
|
||||
values.Restart.StateHostPath = path.Join(stateHostPath, "volumes")
|
||||
} else {
|
||||
ephemeral := ""
|
||||
values.Blockmaster = &helmValuesBlockmaster{StateHostPath: &ephemeral}
|
||||
@@ -2006,6 +2010,8 @@ func runOpsGenerateHelmValues(args []string, stdout, stderr io.Writer) int {
|
||||
fmt.Fprintf(stdout, "restart_persistence_mode=%s\n", restartPersistence)
|
||||
if restartPersistence == "hostpath" {
|
||||
fmt.Fprintf(stdout, "state_hostpath=%s\n", stateHostPath)
|
||||
fmt.Fprintf(stdout, "master_state_hostpath=%s\n", path.Join(stateHostPath, "master"))
|
||||
fmt.Fprintf(stdout, "volume_state_hostpath=%s\n", path.Join(stateHostPath, "volumes"))
|
||||
} else {
|
||||
fmt.Fprintln(stdout, "warning=ephemeral restart persistence loses all data whenever a holder pod restarts")
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestEphemeralStateIsAnOptInThatSaysItLosesData(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, want := range []string{"stateHostPath: /var/lib/sw-block/k8s", "mode: hostpath", "acknowledgeEphemeralDataLoss: false", sentence} {
|
||||
for _, want := range []string{"stateHostPath: /var/lib/sw-block/k8s/master", "mode: hostpath", "acknowledgeEphemeralDataLoss: false", sentence} {
|
||||
if !strings.Contains(string(values), want) {
|
||||
t.Fatalf("chart values lack %q", want)
|
||||
}
|
||||
@@ -61,10 +61,10 @@ func TestEphemeralStateIsAnOptInThatSaysItLosesData(t *testing.T) {
|
||||
return stdout.String(), string(v)
|
||||
}
|
||||
out, vals := gen()
|
||||
if !strings.Contains(out, "restart_persistence_mode=hostpath") || !strings.Contains(out, "state_hostpath=/var/lib/sw-block/k8s") || strings.Contains(out, sentence) {
|
||||
if !strings.Contains(out, "restart_persistence_mode=hostpath") || !strings.Contains(out, "master_state_hostpath=/var/lib/sw-block/k8s/master") || !strings.Contains(out, "volume_state_hostpath=/var/lib/sw-block/k8s/volumes") || strings.Contains(out, sentence) {
|
||||
t.Fatalf("default generate output:\n%s", out)
|
||||
}
|
||||
if !strings.Contains(vals, "stateHostPath: /var/lib/sw-block/k8s") || !strings.Contains(vals, "kubernetes.io/hostname: m02") {
|
||||
if !strings.Contains(vals, "stateHostPath: /var/lib/sw-block/k8s/master") || !strings.Contains(vals, "stateHostPath: /var/lib/sw-block/k8s/volumes") || !strings.Contains(vals, "kubernetes.io/hostname: m02") {
|
||||
t.Fatalf("default values do not pin blockmaster with its state path:\n%s", vals)
|
||||
}
|
||||
out, vals = gen("--restart-persistence", "ephemeral")
|
||||
|
||||
@@ -477,12 +477,12 @@ and the CSI delete answers `delete pending: blockmaster keeps the volume (the vo
|
||||
it; ...): <blockmaster's reason>` (FailedPrecondition; `kubectl describe pv` shows it). The PV stays.
|
||||
Where the volume's data is decides how long it stays:
|
||||
|
||||
- With the default restart persistence (`ephemeral`), the generated pod's state directory is an emptyDir
|
||||
(`/var/lib/kubelet/pods/<pod uid>/volumes/kubernetes.io~empty-dir/state/<volume>/<replica>`): the data
|
||||
lives only as long as that pod. Deleting the generated Deployment (`helm uninstall`), a node drain or a
|
||||
reschedule removes it.
|
||||
- With `--restart-persistence hostpath` (`blockmaster.stateHostPath`), it is
|
||||
`<stateHostPath>/<volume>/<replica>` on the node and stays there.
|
||||
- With the default restart persistence (`hostpath`, from v1.1.1), it is
|
||||
`<restartPersistence.stateHostPath>/<replica>/<volume>-<id>/` on the node (by default under
|
||||
`/var/lib/sw-block/k8s/volumes`) and stays there.
|
||||
- With the opt-in `ephemeral` restart persistence (`blockmaster.stateHostPath: ""`), the generated pod's state
|
||||
directory is an emptyDir: the data lives only as long as that pod. Deleting the generated Deployment
|
||||
(`helm uninstall`), a node drain or a reschedule removes it.
|
||||
|
||||
Removing such a volume comes with v1.2.
|
||||
|
||||
|
||||
@@ -110,9 +110,29 @@ v1.1.1 is a fix release of the v1.1 line. None of its changes alters a stored fo
|
||||
## Kubernetes: volume state persists by default
|
||||
|
||||
- The chart (and `sw-block ops generate-helm-values`) now default to hostpath restart persistence:
|
||||
each generated blockvolume keeps its state on its node under `/var/lib/sw-block/k8s` (and blockmaster
|
||||
its stores), and the holder pod is pinned to that node. Before, the default kept it on the pod's
|
||||
emptyDir, so a pod restart, a reschedule or `helm uninstall` lost the volume's data.
|
||||
each generated blockvolume keeps its state on its node under `/var/lib/sw-block/k8s/volumes`
|
||||
(`restartPersistence.stateHostPath`), and the holder pod is pinned to that node. blockmaster keeps its stores
|
||||
apart, under `/var/lib/sw-block/k8s/master` (`blockmaster.stateHostPath`), so a holder pod never mounts them.
|
||||
Before, the default kept the state on the pod's emptyDir, so a pod restart, a reschedule or `helm uninstall`
|
||||
lost the volume's data.
|
||||
- A v1.1.0 install that set a state path keeps its layout on `helm upgrade -f` with its values file: when
|
||||
`restartPersistence.stateHostPath` is empty (the chart default; a v1.1.0 values file that set only
|
||||
`blockmaster.stateHostPath`) or the same path (what v1.1.0's `generate-helm-values` wrote), the holders keep using
|
||||
`blockmaster.stateHostPath`, unless that path ends in `/master`, where they use the `volumes` directory beside it.
|
||||
Keep your values file on upgrade.
|
||||
- The kept layout keeps what v1.1.0 exposed: every generated holder pod on blockmaster's node mounts
|
||||
blockmaster's authority and lifecycle stores read-write, as the same user, so a faulty or compromised holder
|
||||
could rewrite the epochs, leases and records that fence a stale holder.
|
||||
- To separate them without moving any volume data, stop blockmaster
|
||||
(`kubectl -n <namespace> scale deploy/sw-blockmaster --replicas=0`), move its store directories (`authority`,
|
||||
`lifecycle`, `audit.log`) on its node to a new host path that is not under the old one, then `helm upgrade` with
|
||||
`blockmaster.stateHostPath` set to that path and `restartPersistence.stateHostPath` kept at the old one.
|
||||
- The chart refuses to render a holder state path above `blockmaster.stateHostPath`, compared as cleaned paths (for
|
||||
example `/var/lib/sw-block/k8s` with blockmaster at `/var/lib/sw-block/k8s/master`): every holder mounts its whole
|
||||
state path, so it would mount blockmaster's stores.
|
||||
- A new install never gets the shared layout silently: with a `blockmaster.stateHostPath` that does not end in
|
||||
`/master` and no `restartPersistence.stateHostPath`, `helm install` refuses to render; set the volumes path beside
|
||||
blockmaster's. On an upgrade that keeps the shared layout, the install notes print a WARNING naming the exposure.
|
||||
- Ephemeral state is an explicit opt-in (`blockmaster.stateHostPath: ""`,
|
||||
`--restart-persistence ephemeral`); the values comment, the install notes, the generate output and
|
||||
cluster status each say that ephemeral restart persistence loses all data whenever a holder pod restarts.
|
||||
@@ -157,7 +177,8 @@ v1.1.1 is a fix release of the v1.1 line. None of its changes alters a stored fo
|
||||
`delete pending: blockmaster keeps the volume (the volume's holder has not released it; ...)` (FailedPrecondition;
|
||||
`kubectl describe pv` shows it), the PV stays `Released`, and blockmaster keeps the volume's record.
|
||||
- The volume's state stays where the generated pod keeps it. With hostpath restart persistence, the default from this
|
||||
release, it is `<stateHostPath>/<volume>/<replica>` on the node (by default `/var/lib/sw-block/k8s/<volume>/<replica>`)
|
||||
release, it is `<restartPersistence.stateHostPath>/<replica>/<volume>-<id>/` on the node (by default
|
||||
`/var/lib/sw-block/k8s/volumes/<replica>/<volume>-<id>/`)
|
||||
and keeps that space; with the opt-in ephemeral restart persistence it is the pod's emptyDir, which a
|
||||
`helm uninstall`, a node drain or a reschedule removes.
|
||||
- v1.1.x has no way to remove such a volume; removal comes with v1.2.
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
@@ -191,6 +192,9 @@ func renderChartErr(t *testing.T, root, tpl string, vals map[string]any) (string
|
||||
},
|
||||
"trimSuffix": func(suf, s string) string { return strings.TrimSuffix(s, suf) },
|
||||
"replace": func(old, new, s string) string { return strings.ReplaceAll(s, old, new) },
|
||||
"clean": path.Clean,
|
||||
"base": path.Base,
|
||||
"dir": path.Dir,
|
||||
"int": func(v any) int { i, _ := strconv.Atoi(helmString(v)); return i },
|
||||
"fail": func(msg string) (string, error) { return "", errors.New(msg) },
|
||||
"toYaml": func(v any) string {
|
||||
|
||||
Reference in new issue
Block a user