mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
phase75: add returned replica failback target owner
This commit is contained in:
1 parent
54699f00e1
commit
90697fa45e
18 files changed
+1609
-99
No files matched your search
+144
@@ -0,0 +1,144 @@
|
||||
apiVersion: apiextensions.k8s.io/v1
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
name: swblockreplicafailbacks.block.seaweedfs.com
|
||||
spec:
|
||||
group: block.seaweedfs.com
|
||||
scope: Namespaced
|
||||
names:
|
||||
plural: swblockreplicafailbacks
|
||||
singular: swblockreplicafailback
|
||||
kind: SwBlockReplicaFailback
|
||||
shortNames:
|
||||
- swbrf
|
||||
versions:
|
||||
- name: v1alpha1
|
||||
served: true
|
||||
storage: true
|
||||
subresources:
|
||||
status: {}
|
||||
additionalPrinterColumns:
|
||||
- name: Volume
|
||||
type: string
|
||||
jsonPath: .spec.volumeName
|
||||
- name: Replica
|
||||
type: string
|
||||
jsonPath: .spec.replicaID
|
||||
- name: State
|
||||
type: string
|
||||
jsonPath: .status.state
|
||||
- name: Reason
|
||||
type: string
|
||||
jsonPath: .status.reasonCode
|
||||
- name: Age
|
||||
type: date
|
||||
jsonPath: .metadata.creationTimestamp
|
||||
schema:
|
||||
openAPIV3Schema:
|
||||
type: object
|
||||
description: Narrow target for future returned-replica authority failback. Phase 75 creates the target only; it does not mutate authority.
|
||||
properties:
|
||||
spec:
|
||||
type: object
|
||||
description: Identity and terminal ACK evidence required before a future failback executor may act.
|
||||
required:
|
||||
- volumeName
|
||||
- replicaID
|
||||
properties:
|
||||
volumeName:
|
||||
type: string
|
||||
volumeID:
|
||||
type: string
|
||||
pvcName:
|
||||
type: string
|
||||
replicaID:
|
||||
type: string
|
||||
ackEligible:
|
||||
type: boolean
|
||||
frontendFencedBeforeFailback:
|
||||
type: boolean
|
||||
durableFrontierCovered:
|
||||
type: boolean
|
||||
noCrossVolumeIdentityChange:
|
||||
type: boolean
|
||||
status:
|
||||
type: object
|
||||
properties:
|
||||
observedAt:
|
||||
type: string
|
||||
format: date-time
|
||||
observedGeneration:
|
||||
type: integer
|
||||
format: int64
|
||||
minimum: 0
|
||||
executor:
|
||||
type: string
|
||||
state:
|
||||
type: string
|
||||
enum:
|
||||
- planned
|
||||
- blocked
|
||||
- failed_back
|
||||
reasonCode:
|
||||
type: string
|
||||
failbackMutationAllowed:
|
||||
type: boolean
|
||||
failbackStarted:
|
||||
type: boolean
|
||||
authorityEpochAdvanced:
|
||||
type: boolean
|
||||
singlePrimaryAfterFailback:
|
||||
type: boolean
|
||||
publishTargetSwappedAfterFailback:
|
||||
type: boolean
|
||||
noCrossVolumeIdentityChange:
|
||||
type: boolean
|
||||
evidenceGeneration:
|
||||
type: string
|
||||
conditions:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
required:
|
||||
- type
|
||||
- status
|
||||
properties:
|
||||
type:
|
||||
type: string
|
||||
enum:
|
||||
- Ready
|
||||
- Blocked
|
||||
- Recovering
|
||||
- Recovered
|
||||
- EvidenceStale
|
||||
status:
|
||||
type: string
|
||||
enum:
|
||||
- "True"
|
||||
- "False"
|
||||
- Unknown
|
||||
reason:
|
||||
type: string
|
||||
severity:
|
||||
type: string
|
||||
enum:
|
||||
- info
|
||||
- warning
|
||||
- error
|
||||
message:
|
||||
type: string
|
||||
lastTransitionTime:
|
||||
type: string
|
||||
format: date-time
|
||||
evidenceRefs:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
evidenceRefs:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
nonClaims:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
@@ -0,0 +1,38 @@
|
||||
{{- if and .Values.failbackTargetOwner.create .Values.failbackTargetOwner.rbac.create }}
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: {{ include "seaweed-block.fullname" . }}-failback-target-owner
|
||||
namespace: {{ .Release.Namespace }}
|
||||
labels:
|
||||
{{- include "seaweed-block.labels" . | nindent 4 }}
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: {{ include "seaweed-block.fullname" . }}-failback-target-owner
|
||||
labels:
|
||||
{{- include "seaweed-block.labels" . | nindent 4 }}
|
||||
rules:
|
||||
- apiGroups: ["block.seaweedfs.com"]
|
||||
resources: ["swblockvolumes"]
|
||||
verbs: ["get", "list", "watch"]
|
||||
- apiGroups: ["block.seaweedfs.com"]
|
||||
resources: ["swblockreplicafailbacks"]
|
||||
verbs: ["get", "list", "watch", "create"]
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRoleBinding
|
||||
metadata:
|
||||
name: {{ include "seaweed-block.fullname" . }}-failback-target-owner
|
||||
labels:
|
||||
{{- include "seaweed-block.labels" . | nindent 4 }}
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: {{ include "seaweed-block.fullname" . }}-failback-target-owner
|
||||
namespace: {{ .Release.Namespace }}
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: {{ include "seaweed-block.fullname" . }}-failback-target-owner
|
||||
{{- end }}
|
||||
@@ -0,0 +1,39 @@
|
||||
{{- if .Values.failbackTargetOwner.create }}
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: sw-block-failback-target-owner
|
||||
namespace: {{ .Release.Namespace }}
|
||||
labels:
|
||||
{{- include "seaweed-block.labels" . | nindent 4 }}
|
||||
app: sw-block-failback-target-owner
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: sw-block-failback-target-owner
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: sw-block-failback-target-owner
|
||||
{{- include "seaweed-block.labels" . | nindent 8 }}
|
||||
spec:
|
||||
serviceAccountName: {{ include "seaweed-block.fullname" . }}-failback-target-owner
|
||||
{{- with .Values.failbackTargetOwner.nodeSelector }}
|
||||
nodeSelector:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
containers:
|
||||
- name: failback-target-owner
|
||||
image: {{ include "seaweed-block.image" . | quote }}
|
||||
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||
command: ["/usr/local/bin/sw-block"]
|
||||
args:
|
||||
- "ops"
|
||||
- "failback-target-owner"
|
||||
- "--namespace={{ .Release.Namespace }}"
|
||||
{{- if .Values.failbackTargetOwner.dryRun }}
|
||||
- "--dry-run"
|
||||
{{- end }}
|
||||
- "--interval={{ .Values.failbackTargetOwner.interval }}"
|
||||
{{- end }}
|
||||
@@ -168,6 +168,18 @@ rebuildTargetOwner:
|
||||
create: true
|
||||
nodeSelector: {}
|
||||
|
||||
failbackTargetOwner:
|
||||
# Failback target owner. Disabled by default. When enabled it creates
|
||||
# SwBlockReplicaFailback target CRs from ready failback_returned_replica
|
||||
# executor contracts. It does not execute failback, publish frontend paths,
|
||||
# write status, or mutate storage.
|
||||
create: false
|
||||
dryRun: true
|
||||
interval: 30s
|
||||
rbac:
|
||||
create: true
|
||||
nodeSelector: {}
|
||||
|
||||
frontendPublicationTargetOwner:
|
||||
# Frontend publication target owner. Disabled by default. When enabled it
|
||||
# creates SwBlockFrontendPublication target CRs from terminal ACK eligibility
|
||||
|
||||
@@ -54,6 +54,9 @@ var (
|
||||
opsRebuildTargetOwnerClientFactory = func() (ops.RebuildTargetOwnerClient, error) {
|
||||
return ops.NewInClusterKubernetesStatusClient()
|
||||
}
|
||||
opsFailbackTargetOwnerClientFactory = func() (ops.FailbackTargetOwnerClient, error) {
|
||||
return ops.NewInClusterKubernetesStatusClient()
|
||||
}
|
||||
opsFrontendPublicationTargetOwnerClientFactory = func() (ops.FrontendPublicationTargetOwnerClient, error) {
|
||||
return ops.NewInClusterKubernetesStatusClient()
|
||||
}
|
||||
@@ -77,7 +80,7 @@ func run(args []string, stdout, stderr io.Writer) int {
|
||||
return ops.VolumeStatusExitInvalid
|
||||
}
|
||||
if len(args) < 2 {
|
||||
fmt.Fprintln(stderr, "sw-block: expected subcommand ops status|inventory|list|cluster|volumes|describe|timeline|explain|report|dashboard|generate-helm-values|operator-status|lifecycle-owner|authority-executor|rebuild-target-owner|frontend-publication-target-owner|frontend-publication-executor")
|
||||
fmt.Fprintln(stderr, "sw-block: expected subcommand ops status|inventory|list|cluster|volumes|describe|timeline|explain|report|dashboard|generate-helm-values|operator-status|lifecycle-owner|authority-executor|rebuild-target-owner|failback-target-owner|frontend-publication-target-owner|frontend-publication-executor")
|
||||
usage(stderr)
|
||||
return ops.VolumeStatusExitInvalid
|
||||
}
|
||||
@@ -110,6 +113,8 @@ func run(args []string, stdout, stderr io.Writer) int {
|
||||
return runOpsAuthorityExecutor(args[2:], stdout, stderr)
|
||||
case "rebuild-target-owner":
|
||||
return runOpsRebuildTargetOwner(args[2:], stdout, stderr)
|
||||
case "failback-target-owner":
|
||||
return runOpsFailbackTargetOwner(args[2:], stdout, stderr)
|
||||
case "frontend-publication-target-owner":
|
||||
return runOpsFrontendPublicationTargetOwner(args[2:], stdout, stderr)
|
||||
case "frontend-publication-executor":
|
||||
@@ -311,6 +316,72 @@ func runOpsRebuildTargetOwner(args []string, stdout, stderr io.Writer) int {
|
||||
}
|
||||
}
|
||||
|
||||
func runOpsFailbackTargetOwner(args []string, stdout, stderr io.Writer) int {
|
||||
fs := flag.NewFlagSet("sw-block ops failback-target-owner", flag.ContinueOnError)
|
||||
fs.SetOutput(stderr)
|
||||
var (
|
||||
dryRun bool
|
||||
namespace string
|
||||
interval time.Duration
|
||||
)
|
||||
fs.BoolVar(&dryRun, "dry-run", false, "evaluate failback target planning without creating SwBlockReplicaFailback objects")
|
||||
fs.StringVar(&namespace, "namespace", "default", "Kubernetes namespace containing SwBlockVolume objects")
|
||||
fs.DurationVar(&interval, "interval", 0, "repeat failback-target-owner reconciliation at this interval; 0 runs once")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return ops.VolumeStatusExitInvalid
|
||||
}
|
||||
if fs.NArg() != 0 {
|
||||
fmt.Fprintf(stderr, "sw-block ops failback-target-owner: unexpected args %s\n", strings.Join(fs.Args(), " "))
|
||||
return ops.VolumeStatusExitInvalid
|
||||
}
|
||||
runOnce := func() int {
|
||||
client, err := opsFailbackTargetOwnerClientFactory()
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "sw-block ops failback-target-owner: %v\n", err)
|
||||
return ops.VolumeStatusExitInvalid
|
||||
}
|
||||
result, err := (ops.FailbackTargetOwnerReconciler{
|
||||
Namespace: namespace,
|
||||
Client: client,
|
||||
DryRun: dryRun,
|
||||
}).Reconcile(context.Background())
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "sw-block ops failback-target-owner: %v\n", err)
|
||||
return ops.VolumeStatusExitInvalid
|
||||
}
|
||||
mode := "target_mutation"
|
||||
if dryRun {
|
||||
mode = "dry_run"
|
||||
}
|
||||
fmt.Fprintf(stdout, "failback_target_owner=%s namespace=%s volumes=%d contracts=%d targets_planned=%d targets_existing=%d targets_created=%d invalid_contracts=%d terminal_evidence_ready=%d terminal_evidence_missing=%d failback_attempts=%d mutation_allowed=%t storage_mutation_allowed=%t frontend_publication_allowed=%t\n",
|
||||
mode,
|
||||
namespace,
|
||||
result.VolumeCount,
|
||||
result.ContractCount,
|
||||
result.TargetPlannedCount,
|
||||
result.TargetExistingCount,
|
||||
result.TargetCreateCount,
|
||||
result.InvalidContractCount,
|
||||
result.TerminalEvidenceReady,
|
||||
result.TerminalEvidenceMissing,
|
||||
result.FailbackAttempts,
|
||||
!dryRun && result.TargetCreateCount > 0,
|
||||
result.StorageMutationAllowed,
|
||||
result.FrontendPublicationAllowed)
|
||||
return ops.VolumeStatusExitOK
|
||||
}
|
||||
if interval <= 0 {
|
||||
return runOnce()
|
||||
}
|
||||
for {
|
||||
code := runOnce()
|
||||
if code != ops.VolumeStatusExitOK {
|
||||
fmt.Fprintf(stderr, "sw-block ops failback-target-owner: iteration failed exit=%d; retrying in %s\n", code, interval)
|
||||
}
|
||||
time.Sleep(interval)
|
||||
}
|
||||
}
|
||||
|
||||
func runOpsAuthorityExecutor(args []string, stdout, stderr io.Writer) int {
|
||||
fs := flag.NewFlagSet("sw-block ops authority-executor", flag.ContinueOnError)
|
||||
fs.SetOutput(stderr)
|
||||
@@ -1935,6 +2006,7 @@ func usage(w io.Writer) {
|
||||
fmt.Fprintln(w, " sw-block ops lifecycle-owner [--dry-run] [--namespace <ns>] [--interval 30s]")
|
||||
fmt.Fprintln(w, " sw-block ops authority-executor [--namespace <ns>] [--allowed-mutation-class ack_eligibility|rebuild_traffic] [--interval 30s]")
|
||||
fmt.Fprintln(w, " sw-block ops rebuild-target-owner [--dry-run] [--namespace <ns>] [--interval 30s]")
|
||||
fmt.Fprintln(w, " sw-block ops failback-target-owner [--dry-run] [--namespace <ns>] [--interval 30s]")
|
||||
fmt.Fprintln(w, " sw-block ops frontend-publication-target-owner [--dry-run] [--namespace <ns>] [--interval 30s]")
|
||||
fmt.Fprintln(w, " sw-block ops frontend-publication-executor [--dry-run] [--namespace <ns>] [--interval 30s]")
|
||||
}
|
||||
|
||||
@@ -1050,6 +1050,90 @@ func TestOpsRebuildTargetOwnerDoesNotCreateTargetWhenRuntimeFactsMissing(t *test
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpsFailbackTargetOwnerCreatesTarget(t *testing.T) {
|
||||
client := &lifecycleOwnerTestClient{
|
||||
volumes: []ops.SwBlockVolumeObject{cmdFailbackTargetVolume()},
|
||||
}
|
||||
oldFactory := opsFailbackTargetOwnerClientFactory
|
||||
opsFailbackTargetOwnerClientFactory = func() (ops.FailbackTargetOwnerClient, error) {
|
||||
return client, nil
|
||||
}
|
||||
t.Cleanup(func() { opsFailbackTargetOwnerClientFactory = oldFactory })
|
||||
|
||||
var stdout, stderr bytes.Buffer
|
||||
code := run([]string{"ops", "failback-target-owner", "--namespace", "kube-system"}, &stdout, &stderr)
|
||||
if code != ops.VolumeStatusExitOK {
|
||||
t.Fatalf("exit=%d stderr=%s stdout=%s", code, stderr.String(), stdout.String())
|
||||
}
|
||||
if len(client.failbackCreates) != 1 {
|
||||
t.Fatalf("failbackCreates=%+v", client.failbackCreates)
|
||||
}
|
||||
created := client.failbackCreates[0]
|
||||
if created.Ref.Name != "demo-pvc-r1-failback" ||
|
||||
created.Spec.VolumeName != "demo-pvc" ||
|
||||
created.Spec.VolumeID != "pvc-demo" ||
|
||||
created.Spec.PVCName != "demo-pvc" ||
|
||||
created.Spec.ReplicaID != "r1" ||
|
||||
!created.Spec.AckEligible ||
|
||||
!created.Spec.FrontendFencedBeforeFailback ||
|
||||
!created.Spec.DurableFrontierCovered ||
|
||||
!created.Spec.NoCrossVolumeIdentityChange {
|
||||
t.Fatalf("created=%+v", created)
|
||||
}
|
||||
out := stdout.String()
|
||||
for _, want := range []string{
|
||||
"failback_target_owner=target_mutation",
|
||||
"namespace=kube-system",
|
||||
"volumes=1",
|
||||
"contracts=1",
|
||||
"targets_planned=1",
|
||||
"targets_existing=0",
|
||||
"targets_created=1",
|
||||
"terminal_evidence_ready=1",
|
||||
"terminal_evidence_missing=0",
|
||||
"failback_attempts=0",
|
||||
"mutation_allowed=true",
|
||||
"storage_mutation_allowed=false",
|
||||
"frontend_publication_allowed=false",
|
||||
} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Fatalf("stdout missing %q:\n%s", want, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpsFailbackTargetOwnerDryRunDoesNotCreateTarget(t *testing.T) {
|
||||
client := &lifecycleOwnerTestClient{
|
||||
volumes: []ops.SwBlockVolumeObject{cmdFailbackTargetVolume()},
|
||||
}
|
||||
oldFactory := opsFailbackTargetOwnerClientFactory
|
||||
opsFailbackTargetOwnerClientFactory = func() (ops.FailbackTargetOwnerClient, error) {
|
||||
return client, nil
|
||||
}
|
||||
t.Cleanup(func() { opsFailbackTargetOwnerClientFactory = oldFactory })
|
||||
|
||||
var stdout, stderr bytes.Buffer
|
||||
code := run([]string{"ops", "failback-target-owner", "--dry-run", "--namespace", "kube-system"}, &stdout, &stderr)
|
||||
if code != ops.VolumeStatusExitOK {
|
||||
t.Fatalf("exit=%d stderr=%s stdout=%s", code, stderr.String(), stdout.String())
|
||||
}
|
||||
if len(client.failbackCreates) != 0 {
|
||||
t.Fatalf("dry-run creates=%+v", client.failbackCreates)
|
||||
}
|
||||
out := stdout.String()
|
||||
for _, want := range []string{
|
||||
"failback_target_owner=dry_run",
|
||||
"targets_planned=1",
|
||||
"targets_created=0",
|
||||
"terminal_evidence_ready=1",
|
||||
"mutation_allowed=false",
|
||||
} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Fatalf("stdout missing %q:\n%s", want, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpsFrontendPublicationTargetOwnerCreatesTarget(t *testing.T) {
|
||||
client := &lifecycleOwnerTestClient{
|
||||
eligibilities: []ops.SwBlockReplicaEligibilityObject{cmdFrontendPublicationEligibility()},
|
||||
@@ -1635,6 +1719,42 @@ func cmdFrontendPublicationTarget() ops.SwBlockFrontendPublicationObject {
|
||||
}
|
||||
}
|
||||
|
||||
func cmdFailbackTargetVolume() ops.SwBlockVolumeObject {
|
||||
return ops.SwBlockVolumeObject{
|
||||
Ref: ops.OperatorObjectRef{
|
||||
APIVersion: ops.SwBlockVolumeAPIVersion,
|
||||
Kind: ops.SwBlockVolumeKind,
|
||||
Namespace: "kube-system",
|
||||
Name: "demo-pvc",
|
||||
},
|
||||
Status: ops.SwBlockVolumeCRDStatus{
|
||||
VolumeID: "pvc-demo",
|
||||
PVCName: "demo-pvc",
|
||||
ReplicaReintegrations: []ops.SwBlockVolumeCRDReturnedReplica{{
|
||||
ReplicaID: "r1",
|
||||
State: ops.ReturnedReplicaStateFenced,
|
||||
FrontendFenced: true,
|
||||
FrontendPrimaryReady: false,
|
||||
AckEligibilityKnown: true,
|
||||
AckEligible: true,
|
||||
DurableFrontierKnown: true,
|
||||
DurableFrontierLSN: 52,
|
||||
RequiredFrontierKnown: true,
|
||||
RequiredFrontierLSN: 52,
|
||||
}},
|
||||
ExecutorContracts: []ops.SwBlockVolumeCRDExecutorContract{{
|
||||
ActionType: ops.ManagedVolumeActionFailbackReturned,
|
||||
ReplicaID: "r1",
|
||||
Decision: ops.ReturnedReplicaExecutorContractDisabled,
|
||||
Reason: ops.ReturnedReplicaExecutorContractReasonExecutorDisabled,
|
||||
PreflightDecision: ops.ReturnedReplicaExecutorPreflightReady,
|
||||
PreflightReason: ops.ReturnedReplicaExecutorPreflightReasonSatisfied,
|
||||
AllowedMutationClass: []string{"failback"},
|
||||
}},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (w *operatorStatusTestWriter) WriteClusterStatus(_ context.Context, _ ops.OperatorObjectRef, status ops.SwBlockClusterCRDStatus) error {
|
||||
w.cluster = status
|
||||
return nil
|
||||
@@ -1649,12 +1769,14 @@ type lifecycleOwnerTestClient struct {
|
||||
volumes []ops.SwBlockVolumeObject
|
||||
eligibilities []ops.SwBlockReplicaEligibilityObject
|
||||
rebuilds []ops.SwBlockReplicaRebuildObject
|
||||
failbacks []ops.SwBlockReplicaFailbackObject
|
||||
frontendTargets []ops.SwBlockFrontendPublicationObject
|
||||
patches []lifecycleOwnerTestPatch
|
||||
events []ops.OperatorKubernetesEvent
|
||||
eligibilityWrites []lifecycleOwnerTestEligibilityWrite
|
||||
rebuildWrites []lifecycleOwnerTestRebuildWrite
|
||||
rebuildCreates []ops.SwBlockReplicaRebuildObject
|
||||
failbackCreates []ops.SwBlockReplicaFailbackObject
|
||||
frontendPublicationCreates []ops.SwBlockFrontendPublicationObject
|
||||
frontendPublicationStatusWrites []lifecycleOwnerTestFrontendPublicationWrite
|
||||
}
|
||||
@@ -1691,6 +1813,10 @@ func (c *lifecycleOwnerTestClient) ListSwBlockReplicaRebuilds(_ context.Context,
|
||||
return append([]ops.SwBlockReplicaRebuildObject(nil), c.rebuilds...), nil
|
||||
}
|
||||
|
||||
func (c *lifecycleOwnerTestClient) ListSwBlockReplicaFailbacks(_ context.Context, _ string) ([]ops.SwBlockReplicaFailbackObject, error) {
|
||||
return append([]ops.SwBlockReplicaFailbackObject(nil), c.failbacks...), nil
|
||||
}
|
||||
|
||||
func (c *lifecycleOwnerTestClient) ListSwBlockFrontendPublications(_ context.Context, _ string) ([]ops.SwBlockFrontendPublicationObject, error) {
|
||||
return append([]ops.SwBlockFrontendPublicationObject(nil), c.frontendTargets...), nil
|
||||
}
|
||||
@@ -1715,6 +1841,11 @@ func (c *lifecycleOwnerTestClient) CreateSwBlockReplicaRebuild(_ context.Context
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *lifecycleOwnerTestClient) CreateSwBlockReplicaFailback(_ context.Context, _ string, obj ops.SwBlockReplicaFailbackObject) error {
|
||||
c.failbackCreates = append(c.failbackCreates, obj)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *lifecycleOwnerTestClient) CreateSwBlockFrontendPublication(_ context.Context, _ string, obj ops.SwBlockFrontendPublicationObject) error {
|
||||
c.frontendPublicationCreates = append(c.frontendPublicationCreates, obj)
|
||||
return nil
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
package ops
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type FailbackTargetOwnerClient interface {
|
||||
ListSwBlockVolumes(ctx context.Context, namespace string) ([]SwBlockVolumeObject, error)
|
||||
ListSwBlockReplicaFailbacks(ctx context.Context, namespace string) ([]SwBlockReplicaFailbackObject, error)
|
||||
CreateSwBlockReplicaFailback(ctx context.Context, namespace string, obj SwBlockReplicaFailbackObject) error
|
||||
}
|
||||
|
||||
type FailbackTargetOwnerReconciler struct {
|
||||
Namespace string
|
||||
Client FailbackTargetOwnerClient
|
||||
DryRun bool
|
||||
Now func() time.Time
|
||||
}
|
||||
|
||||
type FailbackTargetOwnerReconcileResult struct {
|
||||
VolumeCount int `json:"volumeCount"`
|
||||
ContractCount int `json:"contractCount"`
|
||||
TargetPlannedCount int `json:"targetPlannedCount"`
|
||||
TargetExistingCount int `json:"targetExistingCount"`
|
||||
TargetCreateCount int `json:"targetCreateCount"`
|
||||
InvalidContractCount int `json:"invalidContractCount"`
|
||||
TerminalEvidenceReady int `json:"terminalEvidenceReady"`
|
||||
TerminalEvidenceMissing int `json:"terminalEvidenceMissing"`
|
||||
FailbackAttempts int `json:"failbackAttempts"`
|
||||
StorageMutationAllowed bool `json:"storageMutationAllowed"`
|
||||
FrontendPublicationAllowed bool `json:"frontendPublicationAllowed"`
|
||||
}
|
||||
|
||||
func (r FailbackTargetOwnerReconciler) Reconcile(ctx context.Context) (FailbackTargetOwnerReconcileResult, error) {
|
||||
if r.Client == nil {
|
||||
return FailbackTargetOwnerReconcileResult{}, fmt.Errorf("failback target owner client is required")
|
||||
}
|
||||
namespace := defaultString(r.Namespace, "default")
|
||||
volumes, err := r.Client.ListSwBlockVolumes(ctx, namespace)
|
||||
if err != nil {
|
||||
return FailbackTargetOwnerReconcileResult{}, err
|
||||
}
|
||||
targets, err := r.Client.ListSwBlockReplicaFailbacks(ctx, namespace)
|
||||
if err != nil {
|
||||
return FailbackTargetOwnerReconcileResult{}, err
|
||||
}
|
||||
result := FailbackTargetOwnerReconcileResult{VolumeCount: len(volumes)}
|
||||
for _, volume := range volumes {
|
||||
for _, contract := range volume.Status.ExecutorContracts {
|
||||
if contract.ActionType != ManagedVolumeActionFailbackReturned {
|
||||
continue
|
||||
}
|
||||
result.ContractCount++
|
||||
if !failbackTargetOwnerContractReady(contract) {
|
||||
result.InvalidContractCount++
|
||||
continue
|
||||
}
|
||||
returned, ok := failbackTargetOwnerReturnedReplica(volume, contract)
|
||||
if !ok || !failbackTargetOwnerTerminalEvidenceReady(returned) {
|
||||
result.TerminalEvidenceMissing++
|
||||
continue
|
||||
}
|
||||
result.TerminalEvidenceReady++
|
||||
result.TargetPlannedCount++
|
||||
if failbackTargetOwnerHasTarget(volume, contract, targets) {
|
||||
result.TargetExistingCount++
|
||||
continue
|
||||
}
|
||||
obj := failbackTargetOwnerObject(namespace, volume, contract, returned)
|
||||
if !r.DryRun {
|
||||
if err := r.Client.CreateSwBlockReplicaFailback(ctx, namespace, obj); err != nil {
|
||||
return result, err
|
||||
}
|
||||
result.TargetCreateCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func failbackTargetOwnerContractReady(contract SwBlockVolumeCRDExecutorContract) bool {
|
||||
return contract.Decision == ReturnedReplicaExecutorContractDisabled &&
|
||||
contract.Reason == ReturnedReplicaExecutorContractReasonExecutorDisabled &&
|
||||
contract.PreflightDecision == ReturnedReplicaExecutorPreflightReady &&
|
||||
contract.PreflightReason == ReturnedReplicaExecutorPreflightReasonSatisfied &&
|
||||
authorityExecutorStringSliceContains(contract.AllowedMutationClass, "failback") &&
|
||||
contract.ReplicaID != ""
|
||||
}
|
||||
|
||||
func failbackTargetOwnerReturnedReplica(volume SwBlockVolumeObject, contract SwBlockVolumeCRDExecutorContract) (SwBlockVolumeCRDReturnedReplica, bool) {
|
||||
for _, returned := range volume.Status.ReplicaReintegrations {
|
||||
if returned.ReplicaID == contract.ReplicaID {
|
||||
return returned, true
|
||||
}
|
||||
}
|
||||
return SwBlockVolumeCRDReturnedReplica{}, false
|
||||
}
|
||||
|
||||
func failbackTargetOwnerTerminalEvidenceReady(returned SwBlockVolumeCRDReturnedReplica) bool {
|
||||
return returned.FrontendFenced &&
|
||||
!returned.FrontendPrimaryReady &&
|
||||
returned.AckEligibilityKnown &&
|
||||
returned.AckEligible &&
|
||||
returned.DurableFrontierKnown &&
|
||||
returned.RequiredFrontierKnown &&
|
||||
returned.DurableFrontierLSN >= returned.RequiredFrontierLSN
|
||||
}
|
||||
|
||||
func failbackTargetOwnerHasTarget(volume SwBlockVolumeObject, contract SwBlockVolumeCRDExecutorContract, targets []SwBlockReplicaFailbackObject) bool {
|
||||
for _, target := range targets {
|
||||
if target.Spec.ReplicaID != contract.ReplicaID {
|
||||
continue
|
||||
}
|
||||
if target.Spec.VolumeName != "" && target.Spec.VolumeName == volume.Ref.Name {
|
||||
return true
|
||||
}
|
||||
if target.Spec.VolumeID != "" && target.Spec.VolumeID == volume.Status.VolumeID {
|
||||
return true
|
||||
}
|
||||
if target.Spec.PVCName != "" && target.Spec.PVCName == volume.Status.PVCName {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func failbackTargetOwnerObject(namespace string, volume SwBlockVolumeObject, contract SwBlockVolumeCRDExecutorContract, returned SwBlockVolumeCRDReturnedReplica) SwBlockReplicaFailbackObject {
|
||||
return SwBlockReplicaFailbackObject{
|
||||
Ref: OperatorObjectRef{
|
||||
APIVersion: SwBlockVolumeAPIVersion,
|
||||
Kind: SwBlockReplicaFailbackKind,
|
||||
Namespace: namespace,
|
||||
Name: failbackTargetOwnerName(volume.Ref.Name, contract.ReplicaID),
|
||||
},
|
||||
Spec: SwBlockReplicaFailbackSpec{
|
||||
VolumeName: volume.Ref.Name,
|
||||
VolumeID: volume.Status.VolumeID,
|
||||
PVCName: volume.Status.PVCName,
|
||||
ReplicaID: contract.ReplicaID,
|
||||
AckEligible: returned.AckEligibilityKnown && returned.AckEligible,
|
||||
FrontendFencedBeforeFailback: returned.FrontendFenced && !returned.FrontendPrimaryReady,
|
||||
DurableFrontierCovered: returned.DurableFrontierKnown && returned.RequiredFrontierKnown && returned.DurableFrontierLSN >= returned.RequiredFrontierLSN,
|
||||
NoCrossVolumeIdentityChange: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func failbackTargetOwnerName(volumeName, replicaID string) string {
|
||||
name := strings.ToLower(strings.TrimSpace(volumeName + "-" + replicaID + "-failback"))
|
||||
var b strings.Builder
|
||||
lastDash := false
|
||||
for _, r := range name {
|
||||
ok := (r >= 'a' && r <= 'z') || (r >= '0' && r <= '9')
|
||||
if ok {
|
||||
b.WriteRune(r)
|
||||
lastDash = false
|
||||
continue
|
||||
}
|
||||
if !lastDash {
|
||||
b.WriteByte('-')
|
||||
lastDash = true
|
||||
}
|
||||
}
|
||||
out := strings.Trim(b.String(), "-")
|
||||
if out == "" {
|
||||
return "failback-target"
|
||||
}
|
||||
if len(out) > 63 {
|
||||
out = strings.TrimRight(out[:63], "-")
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
package ops
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFailbackTargetOwnerCreatesTargetFromReadyContract(t *testing.T) {
|
||||
client := &fakeFailbackTargetOwnerClient{volumes: []SwBlockVolumeObject{failbackTargetOwnerTestVolume()}}
|
||||
|
||||
result, err := (FailbackTargetOwnerReconciler{
|
||||
Namespace: "kube-system",
|
||||
Client: client,
|
||||
}).Reconcile(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("reconcile: %v", err)
|
||||
}
|
||||
if result.VolumeCount != 1 ||
|
||||
result.ContractCount != 1 ||
|
||||
result.TargetPlannedCount != 1 ||
|
||||
result.TargetCreateCount != 1 ||
|
||||
result.TerminalEvidenceReady != 1 ||
|
||||
result.FailbackAttempts != 0 ||
|
||||
result.StorageMutationAllowed ||
|
||||
result.FrontendPublicationAllowed {
|
||||
t.Fatalf("result=%+v", result)
|
||||
}
|
||||
if len(client.creates) != 1 {
|
||||
t.Fatalf("creates=%+v", client.creates)
|
||||
}
|
||||
created := client.creates[0]
|
||||
if created.Ref.Kind != SwBlockReplicaFailbackKind ||
|
||||
created.Ref.Name != "demo-pvc-r1-failback" ||
|
||||
created.Spec.VolumeName != "demo-pvc" ||
|
||||
created.Spec.VolumeID != "pvc-demo" ||
|
||||
created.Spec.PVCName != "demo-pvc" ||
|
||||
created.Spec.ReplicaID != "r1" ||
|
||||
!created.Spec.AckEligible ||
|
||||
!created.Spec.FrontendFencedBeforeFailback ||
|
||||
!created.Spec.DurableFrontierCovered ||
|
||||
!created.Spec.NoCrossVolumeIdentityChange {
|
||||
t.Fatalf("created=%+v", created)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFailbackTargetOwnerDryRunDoesNotCreateTarget(t *testing.T) {
|
||||
client := &fakeFailbackTargetOwnerClient{volumes: []SwBlockVolumeObject{failbackTargetOwnerTestVolume()}}
|
||||
|
||||
result, err := (FailbackTargetOwnerReconciler{
|
||||
Namespace: "kube-system",
|
||||
Client: client,
|
||||
DryRun: true,
|
||||
}).Reconcile(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("reconcile: %v", err)
|
||||
}
|
||||
if result.TargetPlannedCount != 1 || result.TargetCreateCount != 0 {
|
||||
t.Fatalf("result=%+v", result)
|
||||
}
|
||||
if len(client.creates) != 0 {
|
||||
t.Fatalf("dry-run creates=%+v", client.creates)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFailbackTargetOwnerRejectsNonFailbackContract(t *testing.T) {
|
||||
volume := failbackTargetOwnerTestVolume()
|
||||
volume.Status.ExecutorContracts[0].AllowedMutationClass = []string{AuthorityExecutorAllowedMutationAckEligibility}
|
||||
client := &fakeFailbackTargetOwnerClient{volumes: []SwBlockVolumeObject{volume}}
|
||||
|
||||
result, err := (FailbackTargetOwnerReconciler{
|
||||
Namespace: "kube-system",
|
||||
Client: client,
|
||||
}).Reconcile(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("reconcile: %v", err)
|
||||
}
|
||||
if result.ContractCount != 1 || result.InvalidContractCount != 1 || result.TargetCreateCount != 0 {
|
||||
t.Fatalf("result=%+v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFailbackTargetOwnerRequiresTerminalEvidence(t *testing.T) {
|
||||
volume := failbackTargetOwnerTestVolume()
|
||||
volume.Status.ReplicaReintegrations[0].AckEligible = false
|
||||
client := &fakeFailbackTargetOwnerClient{volumes: []SwBlockVolumeObject{volume}}
|
||||
|
||||
result, err := (FailbackTargetOwnerReconciler{
|
||||
Namespace: "kube-system",
|
||||
Client: client,
|
||||
}).Reconcile(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("reconcile: %v", err)
|
||||
}
|
||||
if result.TerminalEvidenceMissing != 1 || result.TargetCreateCount != 0 {
|
||||
t.Fatalf("result=%+v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFailbackTargetOwnerSkipsExistingTarget(t *testing.T) {
|
||||
volume := failbackTargetOwnerTestVolume()
|
||||
client := &fakeFailbackTargetOwnerClient{
|
||||
volumes: []SwBlockVolumeObject{volume},
|
||||
targets: []SwBlockReplicaFailbackObject{{
|
||||
Spec: SwBlockReplicaFailbackSpec{
|
||||
VolumeName: "demo-pvc",
|
||||
ReplicaID: "r1",
|
||||
},
|
||||
}},
|
||||
}
|
||||
|
||||
result, err := (FailbackTargetOwnerReconciler{
|
||||
Namespace: "kube-system",
|
||||
Client: client,
|
||||
}).Reconcile(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("reconcile: %v", err)
|
||||
}
|
||||
if result.TargetExistingCount != 1 || result.TargetCreateCount != 0 {
|
||||
t.Fatalf("result=%+v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func failbackTargetOwnerTestVolume() SwBlockVolumeObject {
|
||||
return SwBlockVolumeObject{
|
||||
Ref: OperatorObjectRef{
|
||||
APIVersion: SwBlockVolumeAPIVersion,
|
||||
Kind: SwBlockVolumeKind,
|
||||
Namespace: "kube-system",
|
||||
Name: "demo-pvc",
|
||||
},
|
||||
Status: SwBlockVolumeCRDStatus{
|
||||
VolumeID: "pvc-demo",
|
||||
PVCName: "demo-pvc",
|
||||
ReplicaReintegrations: []SwBlockVolumeCRDReturnedReplica{{
|
||||
ReplicaID: "r1",
|
||||
State: ReturnedReplicaStateFenced,
|
||||
FrontendFenced: true,
|
||||
FrontendPrimaryReady: false,
|
||||
AckEligibilityKnown: true,
|
||||
AckEligible: true,
|
||||
DurableFrontierKnown: true,
|
||||
DurableFrontierLSN: 52,
|
||||
RequiredFrontierKnown: true,
|
||||
RequiredFrontierLSN: 52,
|
||||
}},
|
||||
ExecutorContracts: []SwBlockVolumeCRDExecutorContract{{
|
||||
ActionType: ManagedVolumeActionFailbackReturned,
|
||||
ReplicaID: "r1",
|
||||
Decision: ReturnedReplicaExecutorContractDisabled,
|
||||
Reason: ReturnedReplicaExecutorContractReasonExecutorDisabled,
|
||||
PreflightDecision: ReturnedReplicaExecutorPreflightReady,
|
||||
PreflightReason: ReturnedReplicaExecutorPreflightReasonSatisfied,
|
||||
AllowedMutationClass: []string{"failback"},
|
||||
}},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type fakeFailbackTargetOwnerClient struct {
|
||||
volumes []SwBlockVolumeObject
|
||||
targets []SwBlockReplicaFailbackObject
|
||||
creates []SwBlockReplicaFailbackObject
|
||||
}
|
||||
|
||||
func (f *fakeFailbackTargetOwnerClient) ListSwBlockVolumes(context.Context, string) ([]SwBlockVolumeObject, error) {
|
||||
return append([]SwBlockVolumeObject(nil), f.volumes...), nil
|
||||
}
|
||||
|
||||
func (f *fakeFailbackTargetOwnerClient) ListSwBlockReplicaFailbacks(context.Context, string) ([]SwBlockReplicaFailbackObject, error) {
|
||||
return append([]SwBlockReplicaFailbackObject(nil), f.targets...), nil
|
||||
}
|
||||
|
||||
func (f *fakeFailbackTargetOwnerClient) CreateSwBlockReplicaFailback(_ context.Context, _ string, obj SwBlockReplicaFailbackObject) error {
|
||||
f.creates = append(f.creates, obj)
|
||||
return nil
|
||||
}
|
||||
@@ -541,6 +541,91 @@ func TestPhase69SwBlockFrontendPublicationTargetSchema(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPhase75SwBlockReplicaFailbackTargetSchema(t *testing.T) {
|
||||
doc := readYAMLMap(t, "charts/seaweed-block/crds/swblockreplicafailbacks.block.seaweedfs.com.yaml")
|
||||
spec := yamlMap(t, doc, "spec")
|
||||
names := yamlMap(t, spec, "names")
|
||||
assertYAMLString(t, names, "kind", SwBlockReplicaFailbackKind)
|
||||
assertYAMLString(t, names, "plural", SwBlockReplicaFailbackPlural)
|
||||
assertYAMLString(t, names, "singular", SwBlockReplicaFailbackSingular)
|
||||
|
||||
version := yamlMapFromValue(t, yamlSlice(t, spec, "versions")[0])
|
||||
if _, ok := yamlMap(t, version, "subresources")["status"]; !ok {
|
||||
t.Fatalf("%s missing status subresource", SwBlockReplicaFailbackKind)
|
||||
}
|
||||
|
||||
rootProperties := yamlMap(t,
|
||||
yamlMap(t,
|
||||
yamlMap(t, version, "schema"),
|
||||
"openAPIV3Schema"),
|
||||
"properties")
|
||||
specProperties := yamlMap(t, yamlMap(t, rootProperties, "spec"), "properties")
|
||||
for _, want := range []string{
|
||||
"volumeName",
|
||||
"volumeID",
|
||||
"pvcName",
|
||||
"replicaID",
|
||||
"ackEligible",
|
||||
"frontendFencedBeforeFailback",
|
||||
"durableFrontierCovered",
|
||||
"noCrossVolumeIdentityChange",
|
||||
} {
|
||||
if _, ok := specProperties[want]; !ok {
|
||||
t.Fatalf("%s.spec schema missing %s", SwBlockReplicaFailbackKind, want)
|
||||
}
|
||||
}
|
||||
required := yamlStringSet(t, yamlMap(t, rootProperties, "spec"), "required")
|
||||
for _, want := range []string{"volumeName", "replicaID"} {
|
||||
if !required[want] {
|
||||
t.Fatalf("%s.spec required missing %s: %+v", SwBlockReplicaFailbackKind, want, required)
|
||||
}
|
||||
}
|
||||
|
||||
statusProperties := yamlMap(t, yamlMap(t, rootProperties, "status"), "properties")
|
||||
for _, want := range []string{
|
||||
"observedAt",
|
||||
"observedGeneration",
|
||||
"executor",
|
||||
"state",
|
||||
"reasonCode",
|
||||
"failbackMutationAllowed",
|
||||
"failbackStarted",
|
||||
"authorityEpochAdvanced",
|
||||
"singlePrimaryAfterFailback",
|
||||
"publishTargetSwappedAfterFailback",
|
||||
"noCrossVolumeIdentityChange",
|
||||
"evidenceGeneration",
|
||||
"conditions",
|
||||
"evidenceRefs",
|
||||
"nonClaims",
|
||||
} {
|
||||
if _, ok := statusProperties[want]; !ok {
|
||||
t.Fatalf("%s.status schema missing %s", SwBlockReplicaFailbackKind, want)
|
||||
}
|
||||
}
|
||||
stateEnum := yamlStringSet(t, yamlMap(t, statusProperties, "state"), "enum")
|
||||
for _, want := range []string{"planned", "blocked", "failed_back"} {
|
||||
if !stateEnum[want] {
|
||||
t.Fatalf("%s.status.state enum missing %s: %+v", SwBlockReplicaFailbackKind, want, stateEnum)
|
||||
}
|
||||
}
|
||||
for _, forbidden := range []string{
|
||||
"ack_eligible",
|
||||
"frontend_fenced_before_failback",
|
||||
"failback_mutation_allowed",
|
||||
"publish_target_swapped_after_failback",
|
||||
"frontendPublished",
|
||||
"rebuildTrafficStarted",
|
||||
} {
|
||||
if _, ok := specProperties[forbidden]; ok {
|
||||
t.Fatalf("%s.spec leaked forbidden field %s", SwBlockReplicaFailbackKind, forbidden)
|
||||
}
|
||||
if _, ok := statusProperties[forbidden]; ok {
|
||||
t.Fatalf("%s.status leaked forbidden field %s", SwBlockReplicaFailbackKind, forbidden)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOperatorStatusRBACIsStatusEventsOnly(t *testing.T) {
|
||||
raw := readRepoFile(t, "charts/seaweed-block/templates/operator-status-rbac.yaml")
|
||||
required := []string{
|
||||
@@ -757,6 +842,62 @@ func TestPhase58RebuildTargetOwnerPackagingIsNarrow(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPhase75FailbackTargetOwnerPackagingIsNarrow(t *testing.T) {
|
||||
values := readYAMLMap(t, "charts/seaweed-block/values.yaml")
|
||||
targetOwner := yamlMap(t, values, "failbackTargetOwner")
|
||||
assertYAMLBool(t, targetOwner, "create", false)
|
||||
assertYAMLBool(t, targetOwner, "dryRun", true)
|
||||
rbacValues := yamlMap(t, targetOwner, "rbac")
|
||||
assertYAMLBool(t, rbacValues, "create", true)
|
||||
|
||||
deploy := readRepoFile(t, "charts/seaweed-block/templates/failback-target-owner.yaml")
|
||||
for _, want := range []string{
|
||||
`kind: Deployment`,
|
||||
`name: sw-block-failback-target-owner`,
|
||||
`serviceAccountName: {{ include "seaweed-block.fullname" . }}-failback-target-owner`,
|
||||
`command: ["/usr/local/bin/sw-block"]`,
|
||||
`- "failback-target-owner"`,
|
||||
`- "--namespace={{ .Release.Namespace }}"`,
|
||||
`{{- if .Values.failbackTargetOwner.dryRun }}`,
|
||||
`- "--dry-run"`,
|
||||
`- "--interval={{ .Values.failbackTargetOwner.interval }}"`,
|
||||
} {
|
||||
if !strings.Contains(deploy, want) {
|
||||
t.Fatalf("failback-target-owner deployment missing %q\n%s", want, deploy)
|
||||
}
|
||||
}
|
||||
|
||||
rbac := readRepoFile(t, "charts/seaweed-block/templates/failback-target-owner-rbac.yaml")
|
||||
for _, want := range []string{
|
||||
`resources: ["swblockvolumes"]`,
|
||||
`verbs: ["get", "list", "watch"]`,
|
||||
`resources: ["swblockreplicafailbacks"]`,
|
||||
`verbs: ["get", "list", "watch", "create"]`,
|
||||
} {
|
||||
if !strings.Contains(rbac, want) {
|
||||
t.Fatalf("failback-target-owner RBAC missing %q\n%s", want, rbac)
|
||||
}
|
||||
}
|
||||
for _, forbidden := range []string{
|
||||
`resources: ["swblockvolumes/status"]`,
|
||||
`resources: ["swblockvolumes/finalizers"]`,
|
||||
`resources: ["swblockreplicafailbacks/status"]`,
|
||||
`resources: ["events"]`,
|
||||
`resources: ["pods"]`,
|
||||
`resources: ["persistentvolumes"]`,
|
||||
`resources: ["persistentvolumeclaims"]`,
|
||||
`resources: ["storageclasses"]`,
|
||||
`resources: ["secrets"]`,
|
||||
`"update"`,
|
||||
`"patch"`,
|
||||
`"delete"`,
|
||||
} {
|
||||
if strings.Contains(rbac, forbidden) {
|
||||
t.Fatalf("failback-target-owner RBAC contains forbidden fragment %q\n%s", forbidden, rbac)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPhase69FrontendPublicationTargetOwnerPackagingIsNarrow(t *testing.T) {
|
||||
values := readYAMLMap(t, "charts/seaweed-block/values.yaml")
|
||||
targetOwner := yamlMap(t, values, "frontendPublicationTargetOwner")
|
||||
|
||||
@@ -283,6 +283,55 @@ func (c *KubernetesStatusClient) ListSwBlockFrontendPublications(ctx context.Con
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *KubernetesStatusClient) ListSwBlockReplicaFailbacks(ctx context.Context, namespace string) ([]SwBlockReplicaFailbackObject, error) {
|
||||
if namespace == "" {
|
||||
return nil, fmt.Errorf("namespace is required for SwBlockReplicaFailback list")
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.resourceCollectionURL(namespace, SwBlockReplicaFailbackPlural), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Accept", "application/json")
|
||||
if c.BearerToken != "" {
|
||||
req.Header.Set("Authorization", "Bearer "+c.BearerToken)
|
||||
}
|
||||
client := c.HTTPClient
|
||||
if client == nil {
|
||||
client = http.DefaultClient
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||
raw, _ := io.ReadAll(io.LimitReader(resp.Body, 4096))
|
||||
return nil, fmt.Errorf("list %s failed: http %d %s", SwBlockReplicaFailbackPlural, resp.StatusCode, strings.TrimSpace(string(raw)))
|
||||
}
|
||||
var list kubernetesSwBlockReplicaFailbackList
|
||||
if err := json.NewDecoder(io.LimitReader(resp.Body, 1<<20)).Decode(&list); err != nil {
|
||||
return nil, fmt.Errorf("decode %s list: %w", SwBlockReplicaFailbackPlural, err)
|
||||
}
|
||||
out := make([]SwBlockReplicaFailbackObject, 0, len(list.Items))
|
||||
for _, item := range list.Items {
|
||||
refNamespace := item.Metadata.Namespace
|
||||
if refNamespace == "" {
|
||||
refNamespace = namespace
|
||||
}
|
||||
out = append(out, SwBlockReplicaFailbackObject{
|
||||
Ref: OperatorObjectRef{
|
||||
APIVersion: SwBlockVolumeAPIVersion,
|
||||
Kind: SwBlockReplicaFailbackKind,
|
||||
Namespace: refNamespace,
|
||||
Name: item.Metadata.Name,
|
||||
},
|
||||
Spec: item.Spec,
|
||||
Status: item.Status,
|
||||
})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *KubernetesStatusClient) CreateSwBlockReplicaRebuild(ctx context.Context, namespace string, obj SwBlockReplicaRebuildObject) error {
|
||||
if namespace == "" || obj.Ref.Name == "" {
|
||||
return fmt.Errorf("namespace and name are required for SwBlockReplicaRebuild create")
|
||||
@@ -365,6 +414,47 @@ func (c *KubernetesStatusClient) CreateSwBlockFrontendPublication(ctx context.Co
|
||||
return fmt.Errorf("create %s/%s failed: http %d %s", SwBlockFrontendPublicationPlural, obj.Ref.Name, resp.StatusCode, strings.TrimSpace(string(raw)))
|
||||
}
|
||||
|
||||
func (c *KubernetesStatusClient) CreateSwBlockReplicaFailback(ctx context.Context, namespace string, obj SwBlockReplicaFailbackObject) error {
|
||||
if namespace == "" || obj.Ref.Name == "" {
|
||||
return fmt.Errorf("namespace and name are required for SwBlockReplicaFailback create")
|
||||
}
|
||||
body, err := json.Marshal(map[string]any{
|
||||
"apiVersion": SwBlockVolumeAPIVersion,
|
||||
"kind": SwBlockReplicaFailbackKind,
|
||||
"metadata": kubernetesMetadata{
|
||||
Name: obj.Ref.Name,
|
||||
Namespace: namespace,
|
||||
},
|
||||
"spec": obj.Spec,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshal SwBlockReplicaFailback create: %w", err)
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.resourceCollectionURL(namespace, SwBlockReplicaFailbackPlural), bytes.NewReader(body))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Accept", "application/json")
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
if c.BearerToken != "" {
|
||||
req.Header.Set("Authorization", "Bearer "+c.BearerToken)
|
||||
}
|
||||
client := c.HTTPClient
|
||||
if client == nil {
|
||||
client = http.DefaultClient
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
|
||||
return nil
|
||||
}
|
||||
raw, _ := io.ReadAll(io.LimitReader(resp.Body, 4096))
|
||||
return fmt.Errorf("create %s/%s failed: http %d %s", SwBlockReplicaFailbackPlural, obj.Ref.Name, resp.StatusCode, strings.TrimSpace(string(raw)))
|
||||
}
|
||||
|
||||
func (c *KubernetesStatusClient) PatchSwBlockVolumeFinalizers(ctx context.Context, ref OperatorObjectRef, finalizers []string) error {
|
||||
if ref.Namespace == "" || ref.Name == "" {
|
||||
return fmt.Errorf("namespace and name are required for SwBlockVolume finalizer patch")
|
||||
@@ -608,3 +698,13 @@ type kubernetesSwBlockFrontendPublication struct {
|
||||
Spec SwBlockFrontendPublicationSpec `json:"spec"`
|
||||
Status SwBlockFrontendPublicationCRDStatus `json:"status"`
|
||||
}
|
||||
|
||||
type kubernetesSwBlockReplicaFailbackList struct {
|
||||
Items []kubernetesSwBlockReplicaFailback `json:"items"`
|
||||
}
|
||||
|
||||
type kubernetesSwBlockReplicaFailback struct {
|
||||
Metadata kubernetesMetadata `json:"metadata"`
|
||||
Spec SwBlockReplicaFailbackSpec `json:"spec"`
|
||||
Status SwBlockReplicaFailbackCRDStatus `json:"status"`
|
||||
}
|
||||
@@ -83,6 +83,41 @@ type SwBlockFrontendPublicationSpec struct {
|
||||
RuntimeEndpoint string `json:"runtimeEndpoint,omitempty"`
|
||||
}
|
||||
|
||||
type SwBlockReplicaFailbackObject struct {
|
||||
Ref OperatorObjectRef `json:"ref"`
|
||||
Spec SwBlockReplicaFailbackSpec `json:"spec,omitempty"`
|
||||
Status SwBlockReplicaFailbackCRDStatus `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
type SwBlockReplicaFailbackSpec struct {
|
||||
VolumeName string `json:"volumeName,omitempty"`
|
||||
VolumeID string `json:"volumeID,omitempty"`
|
||||
PVCName string `json:"pvcName,omitempty"`
|
||||
ReplicaID string `json:"replicaID,omitempty"`
|
||||
AckEligible bool `json:"ackEligible"`
|
||||
FrontendFencedBeforeFailback bool `json:"frontendFencedBeforeFailback"`
|
||||
DurableFrontierCovered bool `json:"durableFrontierCovered"`
|
||||
NoCrossVolumeIdentityChange bool `json:"noCrossVolumeIdentityChange"`
|
||||
}
|
||||
|
||||
type SwBlockReplicaFailbackCRDStatus struct {
|
||||
ObservedAt time.Time `json:"observedAt,omitempty"`
|
||||
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
|
||||
Executor string `json:"executor,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
ReasonCode string `json:"reasonCode,omitempty"`
|
||||
FailbackMutationAllowed bool `json:"failbackMutationAllowed"`
|
||||
FailbackStarted bool `json:"failbackStarted"`
|
||||
AuthorityEpochAdvanced bool `json:"authorityEpochAdvanced"`
|
||||
SinglePrimaryAfterFailback bool `json:"singlePrimaryAfterFailback"`
|
||||
PublishTargetSwappedAfterFailback bool `json:"publishTargetSwappedAfterFailback"`
|
||||
NoCrossVolumeIdentityChange bool `json:"noCrossVolumeIdentityChange"`
|
||||
EvidenceGeneration string `json:"evidenceGeneration,omitempty"`
|
||||
Conditions []ObservationCondition `json:"conditions,omitempty"`
|
||||
EvidenceRefs []string `json:"evidenceRefs,omitempty"`
|
||||
NonClaims []string `json:"nonClaims,omitempty"`
|
||||
}
|
||||
|
||||
type SwBlockFrontendPublicationCRDStatus struct {
|
||||
ObservedAt time.Time `json:"observedAt,omitempty"`
|
||||
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
|
||||
|
||||
@@ -13,6 +13,9 @@ const (
|
||||
SwBlockFrontendPublicationKind = "SwBlockFrontendPublication"
|
||||
SwBlockFrontendPublicationPlural = "swblockfrontendpublications"
|
||||
SwBlockFrontendPublicationSingular = "swblockfrontendpublication"
|
||||
SwBlockReplicaFailbackKind = "SwBlockReplicaFailback"
|
||||
SwBlockReplicaFailbackPlural = "swblockreplicafailbacks"
|
||||
SwBlockReplicaFailbackSingular = "swblockreplicafailback"
|
||||
|
||||
ConditionReady = "Ready"
|
||||
ConditionRecovered = "Recovered"
|
||||
|
||||
@@ -281,7 +281,16 @@ Recommended order from here:
|
||||
It names `failback` as the future mutation envelope, requires terminal
|
||||
evidence for authority ownership, epoch advance, single-primary state, and
|
||||
publish-target swap, and still performs no failback or frontend publication.
|
||||
32. Add backup/restore and NVMe ANA parity after they can reuse the same action
|
||||
32. Phase 75: returned-replica failback target owner. **Closed 2026-06-25, local PASS**
|
||||
(`internal/docs/finished-plans/phase75_finishedplan_failback_target_owner.md`).
|
||||
A disabled-by-default target owner can convert a ready
|
||||
`authority.failback_returned_replica` contract into a
|
||||
`SwBlockReplicaFailback` handoff CR only after ACK eligibility, frontend
|
||||
fencing, durable-frontier coverage, and identity-isolation evidence are
|
||||
present. It can create the target object only; it cannot write status,
|
||||
finalizers, Events, storage/workloads, authority state, frontend
|
||||
publication, or failback execution.
|
||||
33. Add backup/restore and NVMe ANA parity after they can reuse the same action
|
||||
owner, evidence, and status model rather than creating another isolated
|
||||
control plane.
|
||||
|
||||
@@ -302,7 +311,9 @@ and then deliberately constrain frontend publication: the generic runtime seam
|
||||
exists, but returned-replica publication remains blocked until a real
|
||||
authority/failback owner is implemented and gated. Phase 74 names that missing
|
||||
owner contract explicitly as `authority.failback_returned_replica` while
|
||||
keeping execution disabled.
|
||||
keeping execution disabled. Phase 75 adds the first target-owner seam for that
|
||||
contract: `SwBlockReplicaFailback` can be planned as a handoff object, but no
|
||||
failback, authority mutation, or frontend publication is executed.
|
||||
|
||||
The practical rule is:
|
||||
|
||||
|
||||
@@ -1,125 +1,139 @@
|
||||
# Current Plan: Phase 74 Returned-Replica Failback Contract
|
||||
# Current Plan: Phase 75 Returned-Replica Failback Target Owner
|
||||
|
||||
Status: complete.
|
||||
|
||||
## Goal
|
||||
|
||||
Phase 73 correctly blocked returned-replica frontend publication unless a real
|
||||
authority/failback owner exists. Phase 74 names that missing owner as an
|
||||
explicit product contract:
|
||||
Phase 74 named the missing returned-replica failback owner as an explicit,
|
||||
disabled contract:
|
||||
|
||||
```text
|
||||
authority.failback_returned_replica
|
||||
```
|
||||
|
||||
This phase does not execute failback. It makes the ACK-after state visible and
|
||||
bounded so future implementation cannot reuse the ACK-eligibility or generic
|
||||
frontend-publication path as a fake failback.
|
||||
Phase 75 adds the next narrow control-plane seam: a target-owner process can
|
||||
materialize a `SwBlockReplicaFailback` handoff CR when the failback contract is
|
||||
ready and terminal evidence is present.
|
||||
|
||||
This phase does not execute failback. It does not advance authority, change the
|
||||
primary, publish a frontend, or mutate storage/workloads.
|
||||
|
||||
## Deliverables
|
||||
|
||||
### D1: Explicit Failback Action
|
||||
### D1: Failback Target CRD
|
||||
|
||||
When a returned replica is:
|
||||
Added `SwBlockReplicaFailback`:
|
||||
|
||||
```text
|
||||
frontend_fenced=true
|
||||
kind=SwBlockReplicaFailback
|
||||
plural=swblockreplicafailbacks
|
||||
scope=Namespaced
|
||||
status_subresource=true
|
||||
```
|
||||
|
||||
The spec records only the target identity and precondition facts:
|
||||
|
||||
```text
|
||||
volumeName
|
||||
volumeID
|
||||
pvcName
|
||||
replicaID
|
||||
ackEligible
|
||||
frontendFencedBeforeFailback
|
||||
durableFrontierCovered
|
||||
noCrossVolumeIdentityChange
|
||||
```
|
||||
|
||||
The status is reserved for a future executor:
|
||||
|
||||
```text
|
||||
state=planned|blocked|failed_back
|
||||
failbackMutationAllowed
|
||||
failbackStarted
|
||||
authorityEpochAdvanced
|
||||
singlePrimaryAfterFailback
|
||||
publishTargetSwappedAfterFailback
|
||||
noCrossVolumeIdentityChange
|
||||
```
|
||||
|
||||
### D2: Failback Target Owner
|
||||
|
||||
Added:
|
||||
|
||||
```text
|
||||
sw-block ops failback-target-owner
|
||||
```
|
||||
|
||||
The owner reads `SwBlockVolume` contracts and existing
|
||||
`SwBlockReplicaFailback` targets. It creates a target only when:
|
||||
|
||||
```text
|
||||
action=authority.failback_returned_replica
|
||||
contract decision=disabled
|
||||
executor policy=disabled
|
||||
allowed_mutation=failback
|
||||
ack_eligibility_known=true
|
||||
ack_eligible=true
|
||||
durable_frontier_covered=true
|
||||
frontend_fenced=true
|
||||
frontend_primary_ready=false
|
||||
durable_frontier >= required_frontier
|
||||
```
|
||||
|
||||
the managed-volume projection now surfaces:
|
||||
Dry-run is supported and is the Helm default.
|
||||
|
||||
### D3: Helm Packaging + RBAC
|
||||
|
||||
Added disabled-by-default packaging:
|
||||
|
||||
```text
|
||||
managed_volume_action=authority.failback_returned_replica
|
||||
mode=dry_run
|
||||
side_effect=authority_mutating
|
||||
executor=authority_recovery_executor
|
||||
decision=rejected
|
||||
reason=policy_disabled
|
||||
failbackTargetOwner.create=false
|
||||
failbackTargetOwner.dryRun=true
|
||||
```
|
||||
|
||||
The action is visible, but not executable.
|
||||
|
||||
### D2: Failback Preflight + Executor Contract
|
||||
|
||||
The returned-replica executor handoff now uses the ACK-after state to produce:
|
||||
The target owner RBAC is intentionally narrow:
|
||||
|
||||
```text
|
||||
managed_volume_executor_preflight=authority.failback_returned_replica
|
||||
decision=ready
|
||||
mutation_allowed=false
|
||||
swblockvolumes: get,list,watch
|
||||
swblockreplicafailbacks: get,list,watch,create
|
||||
```
|
||||
|
||||
and a disabled executor contract:
|
||||
|
||||
```text
|
||||
managed_volume_executor_contract=authority.failback_returned_replica
|
||||
decision=disabled
|
||||
reason=executor_policy_disabled
|
||||
execution_enabled=false
|
||||
mutation_allowed=false
|
||||
allowed_mutation=failback
|
||||
forbidden_mutation=ack_eligibility,frontend_publication,rebuild_traffic
|
||||
```
|
||||
|
||||
Required terminal evidence:
|
||||
|
||||
```text
|
||||
ack_eligible_true
|
||||
frontend_fenced_before_failback
|
||||
failback_authority_owner
|
||||
authority_epoch_advanced
|
||||
single_primary_after_failback
|
||||
publish_target_swapped_after_failback
|
||||
no_cross_volume_identity_change
|
||||
```
|
||||
|
||||
### D3: Preserve Existing Returned-Replica Contracts
|
||||
|
||||
Phase 74 preserves:
|
||||
|
||||
```text
|
||||
authority.reintegrate_returned_replica -> allowed_mutation=ack_eligibility
|
||||
authority.rebuild_returned_replica -> allowed_mutation=rebuild_traffic
|
||||
```
|
||||
|
||||
Failback is only surfaced after ACK eligibility is already true. It is not
|
||||
shown during the pre-ACK reintegration path.
|
||||
It has no status, finalizer, Event, pod, PVC, PV, StorageClass, Secret, or
|
||||
delete/update/patch permissions.
|
||||
|
||||
### D4: Gate
|
||||
|
||||
Added:
|
||||
|
||||
```text
|
||||
scripts/run-phase74-returned-replica-failback-contract-gate.sh
|
||||
testops/scenarios/returned-replica-failback-contract-chain.yaml
|
||||
scripts/run-phase75-failback-target-owner-gate.sh
|
||||
testops/scenarios/failback-target-owner-chain.yaml
|
||||
```
|
||||
|
||||
The gate proves:
|
||||
|
||||
```text
|
||||
failback action is policy-disabled
|
||||
failback preflight is ready after ACK eligibility
|
||||
failback executor contract is disabled
|
||||
allowed mutation class is failback only
|
||||
ACK and rebuild contracts are preserved
|
||||
frontend publication attempts = 0
|
||||
failback runtime invocations = 0
|
||||
target owner creates target when terminal evidence is present
|
||||
dry-run creates no target
|
||||
non-failback contracts are rejected
|
||||
missing terminal evidence blocks target creation
|
||||
target CRD schema is camelCase and bounded
|
||||
Helm/RBAC packaging is disabled and narrow
|
||||
failback_attempts=0
|
||||
storage_mutation_allowed=false
|
||||
frontend_publication_allowed=false
|
||||
```
|
||||
|
||||
## Non-Claims
|
||||
|
||||
Phase 74 does not implement:
|
||||
Phase 75 does not implement:
|
||||
|
||||
```text
|
||||
real failback execution
|
||||
authority epoch mutation
|
||||
primary reassignment
|
||||
publish target swap
|
||||
blockmaster failback endpoint
|
||||
blockvolume frontend switch
|
||||
publish-target swap
|
||||
frontend publication
|
||||
blockvolume frontend switching
|
||||
storage/workload mutation
|
||||
NVMe ANA behavior
|
||||
```
|
||||
@@ -127,35 +141,40 @@ NVMe ANA behavior
|
||||
## Verification
|
||||
|
||||
```text
|
||||
go test ./core/ops -run "TestEvaluateManagedVolumeAction|TestReturnedReplicaExecutor|TestManagedVolumeProjection_ReturnedReplica|TestOperatorStatusReconcilerWritesReturnedReplica|TestObservationReportSummary_IncludesReturnedReplica" -count=1
|
||||
go test ./core/ops -run "TestFailbackTargetOwner|TestPhase75|TestPhase57D1SwBlockReplicaRebuildTargetSchema|TestPhase69SwBlockFrontendPublicationTargetSchema" -count=1 -v
|
||||
go test ./cmd/sw-block -run "TestOpsFailbackTargetOwner|TestOpsRebuildTargetOwner|TestOpsFrontendPublicationTargetOwner" -count=1 -v
|
||||
go test ./core/ops ./cmd/sw-block
|
||||
C:\work\swblock.exe validate testops\scenarios\returned-replica-failback-contract-chain.yaml
|
||||
"C:\Program Files\Git\bin\bash.exe" scripts/run-phase74-returned-replica-failback-contract-gate.sh .
|
||||
helm lint charts/seaweed-block
|
||||
helm template sw-block charts/seaweed-block --set failbackTargetOwner.create=true
|
||||
```
|
||||
|
||||
Additional gate/scenario validation:
|
||||
|
||||
```text
|
||||
"C:\Program Files\Git\bin\bash.exe" scripts/run-phase75-failback-target-owner-gate.sh .
|
||||
C:\work\swblock.exe validate testops\scenarios\failback-target-owner-chain.yaml
|
||||
```
|
||||
|
||||
Terminal evidence:
|
||||
|
||||
```text
|
||||
phase74_returned_replica_failback_contract_status=ok
|
||||
core_ops_failback_contract_tests=pass
|
||||
failback_action_policy_disabled=true
|
||||
failback_preflight_ready_after_ack=true
|
||||
failback_contract_disabled=true
|
||||
failback_projection_visible_after_ack=true
|
||||
failback_crd_contract_surface=true
|
||||
failback_report_surface=true
|
||||
ack_eligibility_contract_preserved=true
|
||||
rebuild_contract_preserved=true
|
||||
failback_allowed_mutation_class=failback
|
||||
forbidden_mutation_classes=ack_eligibility,frontend_publication,rebuild_traffic
|
||||
failback_mutation_allowed=false
|
||||
failback_runtime_invocations=0
|
||||
frontend_publication_attempts=0
|
||||
phase75_failback_target_owner_status=ok
|
||||
core_ops_failback_target_owner_tests=pass
|
||||
cmd_failback_target_owner_tests=pass
|
||||
failback_target_owner_creates_target=true
|
||||
failback_target_owner_dry_run_no_create=true
|
||||
failback_target_owner_rejects_non_failback_contract=true
|
||||
failback_target_owner_requires_terminal_evidence=true
|
||||
failback_target_crd_schema=true
|
||||
failback_target_owner_chart_boundary=true
|
||||
failback_attempts=0
|
||||
storage_mutation_allowed=false
|
||||
frontend_publication_allowed=false
|
||||
```
|
||||
|
||||
## Next
|
||||
|
||||
The next implementation step is not NVMe. It is the real authority/failback
|
||||
owner: a bounded executor path that can advance authority, switch publish
|
||||
target, prove single-primary terminal evidence, and only then unblock returned
|
||||
replica frontend publication.
|
||||
The next implementation step is a failback executor boundary. It should consume
|
||||
`SwBlockReplicaFailback`, remain disabled until the real authority mutation can
|
||||
prove terminal evidence, and must not reuse the ACK-eligibility, rebuild, or
|
||||
generic frontend-publication paths as a shortcut.
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
# Phase 75 Finished Plan: Returned-Replica Failback Target Owner
|
||||
|
||||
Status: complete.
|
||||
|
||||
## Problem
|
||||
|
||||
Phase 74 exposed the post-ACK returned-replica state as a disabled failback
|
||||
contract:
|
||||
|
||||
```text
|
||||
authority.failback_returned_replica
|
||||
```
|
||||
|
||||
That made the missing operation visible, but it still had no Kubernetes target
|
||||
object or owner identity. Without that seam, a future failback executor would
|
||||
either have to read `SwBlockVolume` directly or risk reusing the wrong
|
||||
pipeline, such as ACK eligibility, rebuild traffic, or generic frontend
|
||||
publication.
|
||||
|
||||
## Implementation
|
||||
|
||||
Added a narrow failback target object:
|
||||
|
||||
```text
|
||||
SwBlockReplicaFailback
|
||||
```
|
||||
|
||||
The target spec carries only identity and precondition facts:
|
||||
|
||||
```text
|
||||
volumeName
|
||||
volumeID
|
||||
pvcName
|
||||
replicaID
|
||||
ackEligible
|
||||
frontendFencedBeforeFailback
|
||||
durableFrontierCovered
|
||||
noCrossVolumeIdentityChange
|
||||
```
|
||||
|
||||
Added:
|
||||
|
||||
```text
|
||||
sw-block ops failback-target-owner
|
||||
```
|
||||
|
||||
The target owner plans a failback handoff only when the visible
|
||||
`authority.failback_returned_replica` contract is ready and terminal evidence is
|
||||
present:
|
||||
|
||||
```text
|
||||
ack eligible
|
||||
frontend still fenced
|
||||
durable frontier covers required frontier
|
||||
no cross-volume identity change
|
||||
```
|
||||
|
||||
Packaging is disabled and dry-run by default:
|
||||
|
||||
```text
|
||||
failbackTargetOwner.create=false
|
||||
failbackTargetOwner.dryRun=true
|
||||
```
|
||||
|
||||
RBAC allows only:
|
||||
|
||||
```text
|
||||
swblockvolumes: get,list,watch
|
||||
swblockreplicafailbacks: get,list,watch,create
|
||||
```
|
||||
|
||||
No status, finalizer, Event, workload, storage, or delete/update/patch powers
|
||||
were added.
|
||||
|
||||
## Gate
|
||||
|
||||
Added:
|
||||
|
||||
```text
|
||||
scripts/run-phase75-failback-target-owner-gate.sh
|
||||
testops/scenarios/failback-target-owner-chain.yaml
|
||||
```
|
||||
|
||||
The gate checks:
|
||||
|
||||
```text
|
||||
target creation after terminal evidence
|
||||
dry-run creates no target
|
||||
non-failback contracts are rejected
|
||||
missing terminal evidence blocks target creation
|
||||
CRD schema is bounded and camelCase
|
||||
Helm/RBAC packaging is disabled and narrow
|
||||
failback attempts = 0
|
||||
storage mutation allowed = false
|
||||
frontend publication allowed = false
|
||||
```
|
||||
|
||||
## Verification
|
||||
|
||||
```text
|
||||
go test ./core/ops -run "TestFailbackTargetOwner|TestPhase75|TestPhase57D1SwBlockReplicaRebuildTargetSchema|TestPhase69SwBlockFrontendPublicationTargetSchema" -count=1 -v
|
||||
go test ./cmd/sw-block -run "TestOpsFailbackTargetOwner|TestOpsRebuildTargetOwner|TestOpsFrontendPublicationTargetOwner" -count=1 -v
|
||||
go test ./core/ops ./cmd/sw-block
|
||||
helm lint charts/seaweed-block
|
||||
helm template sw-block charts/seaweed-block --set failbackTargetOwner.create=true
|
||||
"C:\Program Files\Git\bin\bash.exe" scripts/run-phase75-failback-target-owner-gate.sh .
|
||||
C:\work\swblock.exe validate testops\scenarios\failback-target-owner-chain.yaml
|
||||
```
|
||||
|
||||
Terminal evidence:
|
||||
|
||||
```text
|
||||
phase75_failback_target_owner_status=ok
|
||||
core_ops_failback_target_owner_tests=pass
|
||||
cmd_failback_target_owner_tests=pass
|
||||
failback_target_owner_creates_target=true
|
||||
failback_target_owner_dry_run_no_create=true
|
||||
failback_target_owner_rejects_non_failback_contract=true
|
||||
failback_target_owner_requires_terminal_evidence=true
|
||||
failback_target_crd_schema=true
|
||||
failback_target_owner_chart_boundary=true
|
||||
failback_attempts=0
|
||||
storage_mutation_allowed=false
|
||||
frontend_publication_allowed=false
|
||||
```
|
||||
|
||||
## Non-Claims
|
||||
|
||||
Phase 75 does not implement:
|
||||
|
||||
```text
|
||||
failback execution
|
||||
authority epoch mutation
|
||||
primary reassignment
|
||||
publish-target swap
|
||||
frontend publication
|
||||
blockvolume frontend switching
|
||||
storage/workload mutation
|
||||
```
|
||||
|
||||
## Next
|
||||
|
||||
The next phase should add a failback executor boundary that consumes
|
||||
`SwBlockReplicaFailback` and remains disabled until the real authority mutation
|
||||
can prove epoch advance, single-primary state, publish-target swap, and
|
||||
cross-volume isolation.
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
# Phase 75 Returned-Replica Failback Target Owner QA Sign-off
|
||||
|
||||
Verdict: PASS.
|
||||
|
||||
## Scope
|
||||
|
||||
Phase 75 validates that the post-ACK returned-replica failback contract can be
|
||||
converted into a bounded handoff target:
|
||||
|
||||
```text
|
||||
SwBlockReplicaFailback
|
||||
```
|
||||
|
||||
This is a local/runner contract gate. It does not install Kubernetes resources
|
||||
or execute failback.
|
||||
|
||||
## Evidence
|
||||
|
||||
Local checks:
|
||||
|
||||
```text
|
||||
go test ./core/ops -run "TestFailbackTargetOwner|TestPhase75|TestPhase57D1SwBlockReplicaRebuildTargetSchema|TestPhase69SwBlockFrontendPublicationTargetSchema" -count=1 -v
|
||||
go test ./cmd/sw-block -run "TestOpsFailbackTargetOwner|TestOpsRebuildTargetOwner|TestOpsFrontendPublicationTargetOwner" -count=1 -v
|
||||
go test ./core/ops ./cmd/sw-block
|
||||
helm lint charts/seaweed-block
|
||||
helm template sw-block charts/seaweed-block --set failbackTargetOwner.create=true
|
||||
"C:\Program Files\Git\bin\bash.exe" scripts/run-phase75-failback-target-owner-gate.sh .
|
||||
C:\work\swblock.exe validate testops\scenarios\failback-target-owner-chain.yaml
|
||||
```
|
||||
|
||||
Gate summary:
|
||||
|
||||
```text
|
||||
phase75_failback_target_owner_status=ok
|
||||
phase75_scope=returned_replica_failback_target_owner
|
||||
failback_attempts=0
|
||||
storage_mutation_allowed=false
|
||||
frontend_publication_allowed=false
|
||||
core_ops_failback_target_owner_tests=pass
|
||||
cmd_failback_target_owner_tests=pass
|
||||
failback_target_owner_creates_target=true
|
||||
failback_target_owner_dry_run_no_create=true
|
||||
failback_target_owner_rejects_non_failback_contract=true
|
||||
failback_target_owner_requires_terminal_evidence=true
|
||||
failback_target_owner_skips_existing_target=true
|
||||
failback_target_crd_schema=true
|
||||
failback_target_owner_chart_boundary=true
|
||||
failback_target_owner_cli_creates_target=true
|
||||
failback_target_owner_cli_dry_run_no_create=true
|
||||
failback_target_kind=SwBlockReplicaFailback
|
||||
failback_target_owner_disabled_by_default=true
|
||||
failback_target_owner_dry_run_default=true
|
||||
failback_target_owner_rbac_create_only=true
|
||||
failback_target_owner_status_rbac=false
|
||||
failback_target_owner_finalizer_rbac=false
|
||||
failback_terminal_evidence_required=ack_eligible_true,frontend_fenced_before_failback,durable_frontier_covered,no_cross_volume_identity_change
|
||||
phase75_failback_target_owner_status=ok
|
||||
```
|
||||
|
||||
## Result
|
||||
|
||||
PASS:
|
||||
|
||||
- `SwBlockReplicaFailback` CRD exists with bounded spec/status fields.
|
||||
- `sw-block ops failback-target-owner` creates a target only after terminal
|
||||
evidence is present.
|
||||
- Dry-run creates no target.
|
||||
- Non-failback contracts and missing terminal evidence do not create targets.
|
||||
- Helm packaging is disabled and dry-run by default.
|
||||
- RBAC allows target creation only; no status/finalizer/workload/storage
|
||||
mutation powers are added.
|
||||
- No failback attempt, storage mutation, or frontend publication is attempted.
|
||||
|
||||
## Non-Claims
|
||||
|
||||
Phase 75 does not claim real failback, authority epoch mutation, primary
|
||||
reassignment, publish-target swap, blockvolume frontend switch, or NVMe ANA
|
||||
parity.
|
||||
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
PRODUCT_ROOT="${1:-$(pwd)}"
|
||||
ARTIFACT_DIR="${SW_BLOCK_ARTIFACT_DIR:-${PRODUCT_ROOT}/results/phase75-failback-target-owner-gate}"
|
||||
SUMMARY="${ARTIFACT_DIR}/phase75-failback-target-owner-summary.txt"
|
||||
OPS_LOG="${ARTIFACT_DIR}/core-ops-go-test.log"
|
||||
CMD_LOG="${ARTIFACT_DIR}/cmd-sw-block-go-test.log"
|
||||
|
||||
mkdir -p "${ARTIFACT_DIR}"
|
||||
: >"${SUMMARY}"
|
||||
|
||||
write_summary() {
|
||||
echo "$*" | tee -a "${SUMMARY}" >/dev/null
|
||||
}
|
||||
|
||||
require_log() {
|
||||
local name="$1"
|
||||
local pattern="$2"
|
||||
local file="$3"
|
||||
local found="false"
|
||||
if grep -Eq -- "${pattern}" "${file}"; then
|
||||
found="true"
|
||||
fi
|
||||
write_summary "${name}=${found}"
|
||||
if [ "${found}" != "true" ]; then
|
||||
echo "missing evidence ${name}: pattern ${pattern}" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
write_summary "phase75_failback_target_owner_status=running"
|
||||
write_summary "phase75_scope=returned_replica_failback_target_owner"
|
||||
write_summary "failback_attempts=0"
|
||||
write_summary "storage_mutation_allowed=false"
|
||||
write_summary "frontend_publication_allowed=false"
|
||||
|
||||
OPS_PATTERN="TestFailbackTargetOwner|TestPhase75SwBlockReplicaFailbackTargetSchema|TestPhase75FailbackTargetOwnerPackagingIsNarrow"
|
||||
CMD_PATTERN="TestOpsFailbackTargetOwner"
|
||||
|
||||
if (cd "${PRODUCT_ROOT}" && go test ./core/ops -run "${OPS_PATTERN}" -count=1 -v) >"${OPS_LOG}" 2>&1; then
|
||||
write_summary "core_ops_failback_target_owner_tests=pass"
|
||||
else
|
||||
write_summary "core_ops_failback_target_owner_tests=fail"
|
||||
cat "${OPS_LOG}" >&2 || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if (cd "${PRODUCT_ROOT}" && go test ./cmd/sw-block -run "${CMD_PATTERN}" -count=1 -v) >"${CMD_LOG}" 2>&1; then
|
||||
write_summary "cmd_failback_target_owner_tests=pass"
|
||||
else
|
||||
write_summary "cmd_failback_target_owner_tests=fail"
|
||||
cat "${CMD_LOG}" >&2 || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
require_log "failback_target_owner_creates_target" "^--- PASS: TestFailbackTargetOwnerCreatesTargetFromReadyContract" "${OPS_LOG}"
|
||||
require_log "failback_target_owner_dry_run_no_create" "^--- PASS: TestFailbackTargetOwnerDryRunDoesNotCreateTarget" "${OPS_LOG}"
|
||||
require_log "failback_target_owner_rejects_non_failback_contract" "^--- PASS: TestFailbackTargetOwnerRejectsNonFailbackContract" "${OPS_LOG}"
|
||||
require_log "failback_target_owner_requires_terminal_evidence" "^--- PASS: TestFailbackTargetOwnerRequiresTerminalEvidence" "${OPS_LOG}"
|
||||
require_log "failback_target_owner_skips_existing_target" "^--- PASS: TestFailbackTargetOwnerSkipsExistingTarget" "${OPS_LOG}"
|
||||
require_log "failback_target_crd_schema" "^--- PASS: TestPhase75SwBlockReplicaFailbackTargetSchema" "${OPS_LOG}"
|
||||
require_log "failback_target_owner_chart_boundary" "^--- PASS: TestPhase75FailbackTargetOwnerPackagingIsNarrow" "${OPS_LOG}"
|
||||
require_log "failback_target_owner_cli_creates_target" "^--- PASS: TestOpsFailbackTargetOwnerCreatesTarget" "${CMD_LOG}"
|
||||
require_log "failback_target_owner_cli_dry_run_no_create" "^--- PASS: TestOpsFailbackTargetOwnerDryRunDoesNotCreateTarget" "${CMD_LOG}"
|
||||
|
||||
write_summary "failback_target_kind=SwBlockReplicaFailback"
|
||||
write_summary "failback_target_owner_disabled_by_default=true"
|
||||
write_summary "failback_target_owner_dry_run_default=true"
|
||||
write_summary "failback_target_owner_rbac_create_only=true"
|
||||
write_summary "failback_target_owner_status_rbac=false"
|
||||
write_summary "failback_target_owner_finalizer_rbac=false"
|
||||
write_summary "failback_terminal_evidence_required=ack_eligible_true,frontend_fenced_before_failback,durable_frontier_covered,no_cross_volume_identity_change"
|
||||
write_summary "phase75_failback_target_owner_status=ok"
|
||||
@@ -0,0 +1,116 @@
|
||||
# Runner-native Phase 75 gate: returned-replica failback can create a
|
||||
# failback target handoff CR only after terminal evidence is present. The owner
|
||||
# remains disabled by default, dry-run by default, and has no status/finalizer,
|
||||
# storage, authority, or frontend publication mutation power.
|
||||
|
||||
name: failback-target-owner-chain
|
||||
timeout: 8m
|
||||
|
||||
env:
|
||||
product_root: "/tmp/seaweed_block"
|
||||
ssh_key: "C:\\work\\dev_server\\testdev_key"
|
||||
|
||||
topology:
|
||||
nodes:
|
||||
m02:
|
||||
host: 192.168.1.184
|
||||
user: testdev
|
||||
key: "{{ ssh_key }}"
|
||||
|
||||
phases:
|
||||
- name: failback_target_owner_gate
|
||||
actions:
|
||||
- action: exec
|
||||
node: m02
|
||||
timeout: 7m
|
||||
cmd: "rm -rf /mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase75-failback-target-owner && mkdir -p /mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase75-failback-target-owner && cd {{ product_root }} && SW_BLOCK_ARTIFACT_DIR=/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase75-failback-target-owner bash scripts/run-phase75-failback-target-owner-gate.sh {{ product_root }}"
|
||||
|
||||
- action: grep_log
|
||||
node: m02
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase75-failback-target-owner/phase75-failback-target-owner-summary.txt"
|
||||
pattern: "^phase75_failback_target_owner_status=ok$"
|
||||
save_as: phase75_ok
|
||||
- action: assert_greater
|
||||
actual: "{{ phase75_ok }}"
|
||||
threshold: "0"
|
||||
|
||||
- action: grep_log
|
||||
node: m02
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase75-failback-target-owner/phase75-failback-target-owner-summary.txt"
|
||||
pattern: "^failback_target_owner_creates_target=true$"
|
||||
save_as: creates_target
|
||||
- action: assert_greater
|
||||
actual: "{{ creates_target }}"
|
||||
threshold: "0"
|
||||
|
||||
- action: grep_log
|
||||
node: m02
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase75-failback-target-owner/phase75-failback-target-owner-summary.txt"
|
||||
pattern: "^failback_target_owner_dry_run_no_create=true$"
|
||||
save_as: dry_run_no_create
|
||||
- action: assert_greater
|
||||
actual: "{{ dry_run_no_create }}"
|
||||
threshold: "0"
|
||||
|
||||
- action: grep_log
|
||||
node: m02
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase75-failback-target-owner/phase75-failback-target-owner-summary.txt"
|
||||
pattern: "^failback_target_owner_requires_terminal_evidence=true$"
|
||||
save_as: terminal_evidence_required
|
||||
- action: assert_greater
|
||||
actual: "{{ terminal_evidence_required }}"
|
||||
threshold: "0"
|
||||
|
||||
- action: grep_log
|
||||
node: m02
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase75-failback-target-owner/phase75-failback-target-owner-summary.txt"
|
||||
pattern: "^failback_target_crd_schema=true$"
|
||||
save_as: target_crd_schema
|
||||
- action: assert_greater
|
||||
actual: "{{ target_crd_schema }}"
|
||||
threshold: "0"
|
||||
|
||||
- action: grep_log
|
||||
node: m02
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase75-failback-target-owner/phase75-failback-target-owner-summary.txt"
|
||||
pattern: "^failback_target_owner_chart_boundary=true$"
|
||||
save_as: chart_boundary
|
||||
- action: assert_greater
|
||||
actual: "{{ chart_boundary }}"
|
||||
threshold: "0"
|
||||
|
||||
- action: grep_log
|
||||
node: m02
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase75-failback-target-owner/phase75-failback-target-owner-summary.txt"
|
||||
pattern: "^failback_attempts=0$"
|
||||
save_as: no_failback_attempt
|
||||
- action: assert_greater
|
||||
actual: "{{ no_failback_attempt }}"
|
||||
threshold: "0"
|
||||
|
||||
- action: grep_log
|
||||
node: m02
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase75-failback-target-owner/phase75-failback-target-owner-summary.txt"
|
||||
pattern: "^storage_mutation_allowed=false$"
|
||||
save_as: no_storage_mutation
|
||||
- action: assert_greater
|
||||
actual: "{{ no_storage_mutation }}"
|
||||
threshold: "0"
|
||||
|
||||
- action: grep_log
|
||||
node: m02
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase75-failback-target-owner/phase75-failback-target-owner-summary.txt"
|
||||
pattern: "^frontend_publication_allowed=false$"
|
||||
save_as: no_frontend_publication
|
||||
- action: assert_greater
|
||||
actual: "{{ no_frontend_publication }}"
|
||||
threshold: "0"
|
||||
|
||||
- name: collect
|
||||
always: true
|
||||
actions:
|
||||
- action: collect_path
|
||||
node: m02
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase75-failback-target-owner"
|
||||
name: "remote-phases"
|
||||
ignore_error: true
|
||||
Reference in new issue
Block a user