mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
phase77: add failback runtime contract
This commit is contained in:
1 parent
a8a11deb37
commit
0964e3fab6
18 files changed
+1239
-97
No files matched your search
+9
@@ -61,6 +61,15 @@ spec:
|
||||
type: boolean
|
||||
noCrossVolumeIdentityChange:
|
||||
type: boolean
|
||||
failbackDecision:
|
||||
type: string
|
||||
enum: ["disabled", "enabled"]
|
||||
failbackReason:
|
||||
type: string
|
||||
failbackMutationAllowed:
|
||||
type: boolean
|
||||
runtimeEndpoint:
|
||||
type: string
|
||||
status:
|
||||
type: object
|
||||
properties:
|
||||
|
||||
@@ -198,12 +198,18 @@ func runOpsFailbackExecutor(args []string, stdout, stderr io.Writer) int {
|
||||
fs := flag.NewFlagSet("sw-block ops failback-executor", flag.ContinueOnError)
|
||||
fs.SetOutput(stderr)
|
||||
var (
|
||||
dryRun bool
|
||||
namespace string
|
||||
interval time.Duration
|
||||
dryRun bool
|
||||
namespace string
|
||||
enableExecution bool
|
||||
executionPolicyEnabled bool
|
||||
failbackRuntimeURL string
|
||||
interval time.Duration
|
||||
)
|
||||
fs.BoolVar(&dryRun, "dry-run", false, "evaluate failback targets without writing SwBlockReplicaFailback status")
|
||||
fs.StringVar(&namespace, "namespace", "default", "Kubernetes namespace containing SwBlockReplicaFailback objects")
|
||||
fs.BoolVar(&enableExecution, "enable-execution", false, "request failback runtime execution")
|
||||
fs.BoolVar(&executionPolicyEnabled, "execution-policy", false, "allow failback executor to evaluate execution; default is disabled")
|
||||
fs.StringVar(&failbackRuntimeURL, "failback-runtime-url", "", "HTTP endpoint for failback runtime execution; empty uses target runtimeEndpoint when execution is enabled")
|
||||
fs.DurationVar(&interval, "interval", 0, "repeat failback-executor reconciliation at this interval; 0 runs once")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return ops.VolumeStatusExitInvalid
|
||||
@@ -212,16 +218,31 @@ func runOpsFailbackExecutor(args []string, stdout, stderr io.Writer) int {
|
||||
fmt.Fprintf(stderr, "sw-block ops failback-executor: unexpected args %s\n", strings.Join(fs.Args(), " "))
|
||||
return ops.VolumeStatusExitInvalid
|
||||
}
|
||||
if strings.TrimSpace(failbackRuntimeURL) != "" && !enableExecution {
|
||||
fmt.Fprintf(stderr, "sw-block ops failback-executor: --failback-runtime-url requires --enable-execution reason=unsupported_runtime_without_execution failback_attempts=0\n")
|
||||
return ops.VolumeStatusExitInvalid
|
||||
}
|
||||
if enableExecution && !executionPolicyEnabled {
|
||||
fmt.Fprintf(stderr, "sw-block ops failback-executor: failback execution is disabled by product policy reason=%s failback_attempts=0 authority_mutation_allowed=false frontend_publication_allowed=false storage_mutation_allowed=false\n", ops.AuthorityExecutorFailbackReasonDisabled)
|
||||
return ops.VolumeStatusExitInvalid
|
||||
}
|
||||
runOnce := func() int {
|
||||
client, err := opsFailbackExecutorClientFactory()
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "sw-block ops failback-executor: %v\n", err)
|
||||
return ops.VolumeStatusExitInvalid
|
||||
}
|
||||
var runtime ops.FailbackRuntime
|
||||
if strings.TrimSpace(failbackRuntimeURL) != "" {
|
||||
runtime = ops.NewHTTPFailbackRuntime(failbackRuntimeURL, nil)
|
||||
}
|
||||
result, err := (ops.FailbackExecutorReconciler{
|
||||
Namespace: namespace,
|
||||
Client: client,
|
||||
DryRun: dryRun,
|
||||
Namespace: namespace,
|
||||
Client: client,
|
||||
Runtime: runtime,
|
||||
DryRun: dryRun,
|
||||
ExecutionRequested: enableExecution,
|
||||
ExecutionPolicyEnabled: executionPolicyEnabled,
|
||||
}).Reconcile(context.Background())
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "sw-block ops failback-executor: %v\n", err)
|
||||
@@ -231,13 +252,15 @@ func runOpsFailbackExecutor(args []string, stdout, stderr io.Writer) int {
|
||||
if dryRun {
|
||||
mode = "dry_run"
|
||||
}
|
||||
fmt.Fprintf(stdout, "failback_executor=%s namespace=%s targets=%d status_writes=%d invalid_targets=%d failback_attempts=%d status_mutation_allowed=%t authority_mutation_allowed=%t frontend_publication_allowed=%t mutation_allowed=%t storage_mutation_allowed=%t\n",
|
||||
fmt.Fprintf(stdout, "failback_executor=%s namespace=%s targets=%d status_writes=%d invalid_targets=%d failback_attempts=%d execution_requested=%t execution_policy_enabled=%t status_mutation_allowed=%t authority_mutation_allowed=%t frontend_publication_allowed=%t mutation_allowed=%t storage_mutation_allowed=%t\n",
|
||||
mode,
|
||||
namespace,
|
||||
result.TargetCount,
|
||||
result.StatusWriteCount,
|
||||
result.InvalidTargetCount,
|
||||
result.FailbackAttempts,
|
||||
enableExecution,
|
||||
executionPolicyEnabled,
|
||||
!dryRun && result.StatusWriteCount > 0,
|
||||
result.AuthorityMutationAllowed,
|
||||
result.FrontendPublicationAllowed,
|
||||
@@ -2075,7 +2098,7 @@ func usage(w io.Writer) {
|
||||
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 failback-executor [--dry-run] [--namespace <ns>] [--interval 30s]")
|
||||
fmt.Fprintln(w, " sw-block ops failback-executor [--dry-run] [--namespace <ns>] [--enable-execution] [--execution-policy] [--failback-runtime-url <url>] [--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]")
|
||||
}
|
||||
|
||||
@@ -1077,7 +1077,10 @@ func TestOpsFailbackTargetOwnerCreatesTarget(t *testing.T) {
|
||||
!created.Spec.AckEligible ||
|
||||
!created.Spec.FrontendFencedBeforeFailback ||
|
||||
!created.Spec.DurableFrontierCovered ||
|
||||
!created.Spec.NoCrossVolumeIdentityChange {
|
||||
!created.Spec.NoCrossVolumeIdentityChange ||
|
||||
created.Spec.FailbackDecision != ops.AuthorityExecutorFailbackDecisionDisabled ||
|
||||
created.Spec.FailbackReason != ops.AuthorityExecutorFailbackReasonDisabled ||
|
||||
created.Spec.FailbackMutationAllowed {
|
||||
t.Fatalf("created=%+v", created)
|
||||
}
|
||||
out := stdout.String()
|
||||
@@ -1307,6 +1310,102 @@ func TestOpsFrontendPublicationTargetOwnerDryRunDoesNotCreateTarget(t *testing.T
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpsFailbackExecutorExecutionPolicyBlocks(t *testing.T) {
|
||||
client := &lifecycleOwnerTestClient{
|
||||
failbacks: []ops.SwBlockReplicaFailbackObject{cmdFailbackExecutableTarget()},
|
||||
}
|
||||
oldFactory := opsFailbackExecutorClientFactory
|
||||
opsFailbackExecutorClientFactory = func() (ops.FailbackExecutorClient, error) {
|
||||
return client, nil
|
||||
}
|
||||
t.Cleanup(func() { opsFailbackExecutorClientFactory = oldFactory })
|
||||
|
||||
var stdout, stderr bytes.Buffer
|
||||
code := run([]string{"ops", "failback-executor", "--enable-execution", "--namespace", "kube-system"}, &stdout, &stderr)
|
||||
if code != ops.VolumeStatusExitInvalid {
|
||||
t.Fatalf("exit=%d stderr=%s stdout=%s", code, stderr.String(), stdout.String())
|
||||
}
|
||||
if !strings.Contains(stderr.String(), "failback execution is disabled by product policy") ||
|
||||
!strings.Contains(stderr.String(), "failback_attempts=0") {
|
||||
t.Fatalf("stderr=%s", stderr.String())
|
||||
}
|
||||
if len(client.failbackStatusWrites) != 0 {
|
||||
t.Fatalf("policy-disabled execution wrote status: %+v", client.failbackStatusWrites)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpsFailbackExecutorRuntimeURLWritesFailedBackStatus(t *testing.T) {
|
||||
client := &lifecycleOwnerTestClient{
|
||||
failbacks: []ops.SwBlockReplicaFailbackObject{cmdFailbackExecutableTarget()},
|
||||
}
|
||||
var got ops.FailbackRuntimeRequest
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if err := json.NewDecoder(r.Body).Decode(&got); err != nil {
|
||||
t.Fatalf("decode request: %v", err)
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(ops.FailbackRuntimeResult{
|
||||
FailbackStarted: true,
|
||||
AuthorityEpochAdvanced: true,
|
||||
SinglePrimaryAfterFailback: true,
|
||||
PublishTargetSwappedAfterFailback: true,
|
||||
NoStorageMutation: true,
|
||||
NoCrossVolumeIdentityChange: true,
|
||||
EvidenceRefs: []string{"runtime.txt"},
|
||||
})
|
||||
}))
|
||||
defer server.Close()
|
||||
oldFactory := opsFailbackExecutorClientFactory
|
||||
opsFailbackExecutorClientFactory = func() (ops.FailbackExecutorClient, error) {
|
||||
return client, nil
|
||||
}
|
||||
t.Cleanup(func() { opsFailbackExecutorClientFactory = oldFactory })
|
||||
|
||||
var stdout, stderr bytes.Buffer
|
||||
code := run([]string{
|
||||
"ops", "failback-executor",
|
||||
"--enable-execution",
|
||||
"--execution-policy",
|
||||
"--failback-runtime-url", server.URL,
|
||||
"--namespace", "kube-system",
|
||||
}, &stdout, &stderr)
|
||||
if code != ops.VolumeStatusExitOK {
|
||||
t.Fatalf("exit=%d stderr=%s stdout=%s", code, stderr.String(), stdout.String())
|
||||
}
|
||||
if got.VolumeName != "demo-pvc" ||
|
||||
got.ReplicaID != "r1" ||
|
||||
got.RuntimeEndpoint != "http://127.0.0.1:23260/runtime/failback" ||
|
||||
!got.AckEligible ||
|
||||
!got.FrontendFencedBeforeFailback {
|
||||
t.Fatalf("runtime request=%+v", got)
|
||||
}
|
||||
if len(client.failbackStatusWrites) != 1 {
|
||||
t.Fatalf("failbackStatusWrites=%+v", client.failbackStatusWrites)
|
||||
}
|
||||
status := client.failbackStatusWrites[0].status
|
||||
if status.State != ops.FailbackStateFailedBack ||
|
||||
status.ReasonCode != ops.AuthorityExecutorFailbackReasonCompleted ||
|
||||
!status.FailbackStarted ||
|
||||
!status.AuthorityEpochAdvanced ||
|
||||
!status.SinglePrimaryAfterFailback ||
|
||||
!status.PublishTargetSwappedAfterFailback {
|
||||
t.Fatalf("status=%+v", status)
|
||||
}
|
||||
out := stdout.String()
|
||||
for _, want := range []string{
|
||||
"failback_executor=write_status",
|
||||
"failback_attempts=1",
|
||||
"execution_requested=true",
|
||||
"execution_policy_enabled=true",
|
||||
"authority_mutation_allowed=false",
|
||||
"frontend_publication_allowed=false",
|
||||
"storage_mutation_allowed=false",
|
||||
} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Fatalf("stdout missing %q:\n%s", want, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpsFrontendPublicationExecutorWritesDisabledStatus(t *testing.T) {
|
||||
client := &lifecycleOwnerTestClient{
|
||||
frontendTargets: []ops.SwBlockFrontendPublicationObject{cmdFrontendPublicationTarget()},
|
||||
@@ -1820,10 +1919,22 @@ func cmdFailbackTarget() ops.SwBlockReplicaFailbackObject {
|
||||
FrontendFencedBeforeFailback: true,
|
||||
DurableFrontierCovered: true,
|
||||
NoCrossVolumeIdentityChange: true,
|
||||
FailbackDecision: ops.AuthorityExecutorFailbackDecisionDisabled,
|
||||
FailbackReason: ops.AuthorityExecutorFailbackReasonDisabled,
|
||||
FailbackMutationAllowed: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func cmdFailbackExecutableTarget() ops.SwBlockReplicaFailbackObject {
|
||||
target := cmdFailbackTarget()
|
||||
target.Spec.FailbackDecision = ops.AuthorityExecutorFailbackDecisionEnabled
|
||||
target.Spec.FailbackReason = "failback_requested"
|
||||
target.Spec.FailbackMutationAllowed = true
|
||||
target.Spec.RuntimeEndpoint = "http://127.0.0.1:23260/runtime/failback"
|
||||
return target
|
||||
}
|
||||
|
||||
func cmdFailbackTargetVolume() ops.SwBlockVolumeObject {
|
||||
return ops.SwBlockVolumeObject{
|
||||
Ref: ops.OperatorObjectRef{
|
||||
|
||||
@@ -7,10 +7,17 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
FailbackStateBlocked = "blocked"
|
||||
FailbackStateBlocked = "blocked"
|
||||
FailbackStateFailedBack = "failed_back"
|
||||
|
||||
AuthorityExecutorFailbackReasonDisabled = "failback_policy_disabled"
|
||||
AuthorityExecutorFailbackReasonMissingFacts = "missing_required_facts"
|
||||
AuthorityExecutorFailbackReasonDisabled = "failback_policy_disabled"
|
||||
AuthorityExecutorFailbackReasonMissingFacts = "missing_required_facts"
|
||||
AuthorityExecutorFailbackReasonRuntimeTargetMissing = "failback_runtime_target_missing"
|
||||
AuthorityExecutorFailbackReasonRuntimeFailed = "failback_runtime_failed"
|
||||
AuthorityExecutorFailbackReasonInvalidTerminalEvidence = "failback_runtime_invalid_terminal_evidence"
|
||||
AuthorityExecutorFailbackReasonCompleted = "failback_completed"
|
||||
AuthorityExecutorFailbackDecisionDisabled = "disabled"
|
||||
AuthorityExecutorFailbackDecisionEnabled = "enabled"
|
||||
)
|
||||
|
||||
type FailbackExecutorClient interface {
|
||||
@@ -19,10 +26,40 @@ type FailbackExecutorClient interface {
|
||||
}
|
||||
|
||||
type FailbackExecutorReconciler struct {
|
||||
Namespace string
|
||||
Client FailbackExecutorClient
|
||||
DryRun bool
|
||||
Now func() time.Time
|
||||
Namespace string
|
||||
Client FailbackExecutorClient
|
||||
Runtime FailbackRuntime
|
||||
DryRun bool
|
||||
ExecutionRequested bool
|
||||
ExecutionPolicyEnabled bool
|
||||
Now func() time.Time
|
||||
}
|
||||
|
||||
type FailbackRuntime interface {
|
||||
ExecuteFailback(ctx context.Context, req FailbackRuntimeRequest) (FailbackRuntimeResult, error)
|
||||
}
|
||||
|
||||
type FailbackRuntimeRequest struct {
|
||||
VolumeName string `json:"volumeName"`
|
||||
VolumeID string `json:"volumeID"`
|
||||
PVCName string `json:"pvcName"`
|
||||
ReplicaID string `json:"replicaID"`
|
||||
RuntimeEndpoint string `json:"runtimeEndpoint,omitempty"`
|
||||
AckEligible bool `json:"ackEligible"`
|
||||
FrontendFencedBeforeFailback bool `json:"frontendFencedBeforeFailback"`
|
||||
DurableFrontierCovered bool `json:"durableFrontierCovered"`
|
||||
NoCrossVolumeIdentityChange bool `json:"noCrossVolumeIdentityChange"`
|
||||
EvidenceRefs []string `json:"evidenceRefs,omitempty"`
|
||||
}
|
||||
|
||||
type FailbackRuntimeResult struct {
|
||||
FailbackStarted bool `json:"failbackStarted"`
|
||||
AuthorityEpochAdvanced bool `json:"authorityEpochAdvanced"`
|
||||
SinglePrimaryAfterFailback bool `json:"singlePrimaryAfterFailback"`
|
||||
PublishTargetSwappedAfterFailback bool `json:"publishTargetSwappedAfterFailback"`
|
||||
NoStorageMutation bool `json:"noStorageMutation"`
|
||||
NoCrossVolumeIdentityChange bool `json:"noCrossVolumeIdentityChange"`
|
||||
EvidenceRefs []string `json:"evidenceRefs,omitempty"`
|
||||
}
|
||||
|
||||
type FailbackExecutorReconcileResult struct {
|
||||
@@ -36,6 +73,9 @@ type FailbackExecutorReconcileResult struct {
|
||||
}
|
||||
|
||||
func (r FailbackExecutorReconciler) Reconcile(ctx context.Context) (FailbackExecutorReconcileResult, error) {
|
||||
if r.ExecutionRequested && !r.ExecutionPolicyEnabled {
|
||||
return FailbackExecutorReconcileResult{}, fmt.Errorf("failback executor execution is disabled by product policy")
|
||||
}
|
||||
if r.Client == nil {
|
||||
return FailbackExecutorReconcileResult{}, fmt.Errorf("failback executor client is required")
|
||||
}
|
||||
@@ -46,6 +86,12 @@ func (r FailbackExecutorReconciler) Reconcile(ctx context.Context) (FailbackExec
|
||||
}
|
||||
result := FailbackExecutorReconcileResult{TargetCount: len(targets)}
|
||||
for _, target := range targets {
|
||||
if r.ExecutionRequested {
|
||||
if err := r.executeTarget(ctx, &result, target); err != nil {
|
||||
return result, err
|
||||
}
|
||||
continue
|
||||
}
|
||||
status := failbackExecutorDisabledStatus(r.now()(), target)
|
||||
if !failbackExecutorTargetValid(target) {
|
||||
result.InvalidTargetCount++
|
||||
@@ -64,6 +110,63 @@ func (r FailbackExecutorReconciler) Reconcile(ctx context.Context) (FailbackExec
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r FailbackExecutorReconciler) executeTarget(ctx context.Context, result *FailbackExecutorReconcileResult, target SwBlockReplicaFailbackObject) error {
|
||||
status := failbackExecutorDisabledStatus(r.now()(), target)
|
||||
if !failbackExecutorExecutableTarget(target) {
|
||||
result.InvalidTargetCount++
|
||||
status.ReasonCode = AuthorityExecutorFailbackReasonRuntimeTargetMissing
|
||||
status.Conditions[0].Reason = AuthorityExecutorFailbackReasonRuntimeTargetMissing
|
||||
status.Conditions[0].Message = "failback runtime target is missing required execution facts"
|
||||
if !r.DryRun {
|
||||
if err := r.Client.WriteReplicaFailbackStatus(ctx, target.Ref, status); err != nil {
|
||||
return err
|
||||
}
|
||||
result.StatusWriteCount++
|
||||
}
|
||||
return nil
|
||||
}
|
||||
runtime := r.Runtime
|
||||
if runtime == nil && target.Spec.RuntimeEndpoint != "" {
|
||||
runtime = NewHTTPFailbackRuntime(target.Spec.RuntimeEndpoint, nil)
|
||||
}
|
||||
if runtime == nil {
|
||||
status.ReasonCode = AuthorityExecutorFailbackReasonRuntimeTargetMissing
|
||||
if !r.DryRun {
|
||||
if err := r.Client.WriteReplicaFailbackStatus(ctx, target.Ref, status); err != nil {
|
||||
return err
|
||||
}
|
||||
result.StatusWriteCount++
|
||||
}
|
||||
return nil
|
||||
}
|
||||
result.FailbackAttempts++
|
||||
if r.DryRun {
|
||||
return nil
|
||||
}
|
||||
runtimeResult, err := runtime.ExecuteFailback(ctx, failbackRuntimeRequest(target))
|
||||
if err != nil {
|
||||
status.ReasonCode = AuthorityExecutorFailbackReasonRuntimeFailed
|
||||
if writeErr := r.Client.WriteReplicaFailbackStatus(ctx, target.Ref, status); writeErr != nil {
|
||||
return fmt.Errorf("write failed failback status after runtime error %v: %w", err, writeErr)
|
||||
}
|
||||
result.StatusWriteCount++
|
||||
return fmt.Errorf("execute failback runtime: %w", err)
|
||||
}
|
||||
if !failbackRuntimeTerminalEvidenceValid(runtimeResult) {
|
||||
status.ReasonCode = AuthorityExecutorFailbackReasonInvalidTerminalEvidence
|
||||
if err := r.Client.WriteReplicaFailbackStatus(ctx, target.Ref, status); err != nil {
|
||||
return err
|
||||
}
|
||||
result.StatusWriteCount++
|
||||
return nil
|
||||
}
|
||||
if err := r.Client.WriteReplicaFailbackStatus(ctx, target.Ref, failbackExecutorFailedBackStatus(r.now()(), target, runtimeResult)); err != nil {
|
||||
return err
|
||||
}
|
||||
result.StatusWriteCount++
|
||||
return nil
|
||||
}
|
||||
|
||||
func failbackExecutorTargetValid(target SwBlockReplicaFailbackObject) bool {
|
||||
spec := target.Spec
|
||||
return spec.VolumeName != "" &&
|
||||
@@ -71,7 +174,32 @@ func failbackExecutorTargetValid(target SwBlockReplicaFailbackObject) bool {
|
||||
spec.AckEligible &&
|
||||
spec.FrontendFencedBeforeFailback &&
|
||||
spec.DurableFrontierCovered &&
|
||||
spec.NoCrossVolumeIdentityChange
|
||||
spec.NoCrossVolumeIdentityChange &&
|
||||
spec.FailbackDecision == AuthorityExecutorFailbackDecisionDisabled &&
|
||||
spec.FailbackReason == AuthorityExecutorFailbackReasonDisabled &&
|
||||
!spec.FailbackMutationAllowed
|
||||
}
|
||||
|
||||
func failbackExecutorExecutableTarget(target SwBlockReplicaFailbackObject) bool {
|
||||
spec := target.Spec
|
||||
return spec.VolumeName != "" &&
|
||||
spec.ReplicaID != "" &&
|
||||
spec.RuntimeEndpoint != "" &&
|
||||
spec.AckEligible &&
|
||||
spec.FrontendFencedBeforeFailback &&
|
||||
spec.DurableFrontierCovered &&
|
||||
spec.NoCrossVolumeIdentityChange &&
|
||||
spec.FailbackDecision == AuthorityExecutorFailbackDecisionEnabled &&
|
||||
spec.FailbackMutationAllowed
|
||||
}
|
||||
|
||||
func failbackRuntimeTerminalEvidenceValid(result FailbackRuntimeResult) bool {
|
||||
return result.FailbackStarted &&
|
||||
result.AuthorityEpochAdvanced &&
|
||||
result.SinglePrimaryAfterFailback &&
|
||||
result.PublishTargetSwappedAfterFailback &&
|
||||
result.NoStorageMutation &&
|
||||
result.NoCrossVolumeIdentityChange
|
||||
}
|
||||
|
||||
func failbackExecutorDisabledStatus(now time.Time, target SwBlockReplicaFailbackObject) SwBlockReplicaFailbackCRDStatus {
|
||||
@@ -104,6 +232,47 @@ func failbackExecutorDisabledStatus(now time.Time, target SwBlockReplicaFailback
|
||||
}
|
||||
}
|
||||
|
||||
func failbackExecutorFailedBackStatus(now time.Time, target SwBlockReplicaFailbackObject, result FailbackRuntimeResult) SwBlockReplicaFailbackCRDStatus {
|
||||
return SwBlockReplicaFailbackCRDStatus{
|
||||
ObservedAt: now,
|
||||
Executor: "failback-executor",
|
||||
State: FailbackStateFailedBack,
|
||||
ReasonCode: AuthorityExecutorFailbackReasonCompleted,
|
||||
FailbackMutationAllowed: false,
|
||||
FailbackStarted: result.FailbackStarted,
|
||||
AuthorityEpochAdvanced: result.AuthorityEpochAdvanced,
|
||||
SinglePrimaryAfterFailback: result.SinglePrimaryAfterFailback,
|
||||
PublishTargetSwappedAfterFailback: result.PublishTargetSwappedAfterFailback,
|
||||
NoCrossVolumeIdentityChange: target.Spec.NoCrossVolumeIdentityChange && result.NoCrossVolumeIdentityChange,
|
||||
Conditions: []ObservationCondition{{
|
||||
Type: ConditionRecovered,
|
||||
Status: "True",
|
||||
Reason: AuthorityExecutorFailbackReasonCompleted,
|
||||
Severity: "info",
|
||||
Message: "failback runtime reported terminal authority evidence",
|
||||
}},
|
||||
EvidenceRefs: append([]string(nil), result.EvidenceRefs...),
|
||||
NonClaims: []string{
|
||||
"no_storage_mutation",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func failbackRuntimeRequest(target SwBlockReplicaFailbackObject) FailbackRuntimeRequest {
|
||||
spec := target.Spec
|
||||
return FailbackRuntimeRequest{
|
||||
VolumeName: spec.VolumeName,
|
||||
VolumeID: spec.VolumeID,
|
||||
PVCName: spec.PVCName,
|
||||
ReplicaID: spec.ReplicaID,
|
||||
RuntimeEndpoint: spec.RuntimeEndpoint,
|
||||
AckEligible: spec.AckEligible,
|
||||
FrontendFencedBeforeFailback: spec.FrontendFencedBeforeFailback,
|
||||
DurableFrontierCovered: spec.DurableFrontierCovered,
|
||||
NoCrossVolumeIdentityChange: spec.NoCrossVolumeIdentityChange,
|
||||
}
|
||||
}
|
||||
|
||||
func (r FailbackExecutorReconciler) now() func() time.Time {
|
||||
if r.Now != nil {
|
||||
return r.Now
|
||||
|
||||
@@ -2,6 +2,7 @@ package ops
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -106,6 +107,133 @@ func TestFailbackExecutorMarksInvalidTargets(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFailbackExecutorExecutionPolicyBlocks(t *testing.T) {
|
||||
client := &fakeFailbackExecutorClient{
|
||||
targets: []SwBlockReplicaFailbackObject{failbackExecutorExecutableTargetFixture()},
|
||||
}
|
||||
_, err := (FailbackExecutorReconciler{
|
||||
Namespace: "kube-system",
|
||||
Client: client,
|
||||
ExecutionRequested: true,
|
||||
}).Reconcile(context.Background())
|
||||
if err == nil || err.Error() != "failback executor execution is disabled by product policy" {
|
||||
t.Fatalf("err=%v", err)
|
||||
}
|
||||
if len(client.writes) != 0 {
|
||||
t.Fatalf("policy-disabled execution wrote status: %+v", client.writes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFailbackExecutorInvokesRuntimeWhenExplicitlyEnabled(t *testing.T) {
|
||||
target := failbackExecutorExecutableTargetFixture()
|
||||
client := &fakeFailbackExecutorClient{targets: []SwBlockReplicaFailbackObject{target}}
|
||||
runtime := &fakeFailbackRuntime{result: FailbackRuntimeResult{
|
||||
FailbackStarted: true,
|
||||
AuthorityEpochAdvanced: true,
|
||||
SinglePrimaryAfterFailback: true,
|
||||
PublishTargetSwappedAfterFailback: true,
|
||||
NoStorageMutation: true,
|
||||
NoCrossVolumeIdentityChange: true,
|
||||
EvidenceRefs: []string{"failback-runtime.txt"},
|
||||
}}
|
||||
result, err := (FailbackExecutorReconciler{
|
||||
Namespace: "kube-system",
|
||||
Client: client,
|
||||
Runtime: runtime,
|
||||
ExecutionRequested: true,
|
||||
ExecutionPolicyEnabled: true,
|
||||
Now: func() time.Time { return time.Date(2026, 6, 26, 9, 0, 0, 0, time.UTC) },
|
||||
}).Reconcile(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("reconcile: %v", err)
|
||||
}
|
||||
if result.FailbackAttempts != 1 ||
|
||||
result.StatusWriteCount != 1 ||
|
||||
result.AuthorityMutationAllowed ||
|
||||
result.FrontendPublicationAllowed ||
|
||||
result.StorageMutationAllowed {
|
||||
t.Fatalf("result=%+v", result)
|
||||
}
|
||||
if len(runtime.requests) != 1 {
|
||||
t.Fatalf("runtime requests=%+v", runtime.requests)
|
||||
}
|
||||
req := runtime.requests[0]
|
||||
if req.VolumeName != target.Spec.VolumeName ||
|
||||
req.ReplicaID != target.Spec.ReplicaID ||
|
||||
!req.AckEligible ||
|
||||
!req.FrontendFencedBeforeFailback ||
|
||||
!req.NoCrossVolumeIdentityChange {
|
||||
t.Fatalf("runtime request=%+v", req)
|
||||
}
|
||||
status := client.writes[0].status
|
||||
if status.State != FailbackStateFailedBack ||
|
||||
status.ReasonCode != AuthorityExecutorFailbackReasonCompleted ||
|
||||
status.FailbackMutationAllowed ||
|
||||
!status.FailbackStarted ||
|
||||
!status.AuthorityEpochAdvanced ||
|
||||
!status.SinglePrimaryAfterFailback ||
|
||||
!status.PublishTargetSwappedAfterFailback ||
|
||||
!status.NoCrossVolumeIdentityChange {
|
||||
t.Fatalf("status=%+v", status)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFailbackExecutorRuntimeFailureWritesBlockedStatus(t *testing.T) {
|
||||
client := &fakeFailbackExecutorClient{targets: []SwBlockReplicaFailbackObject{failbackExecutorExecutableTargetFixture()}}
|
||||
runtime := &fakeFailbackRuntime{err: errors.New("runtime refused")}
|
||||
result, err := (FailbackExecutorReconciler{
|
||||
Namespace: "kube-system",
|
||||
Client: client,
|
||||
Runtime: runtime,
|
||||
ExecutionRequested: true,
|
||||
ExecutionPolicyEnabled: true,
|
||||
}).Reconcile(context.Background())
|
||||
if err == nil {
|
||||
t.Fatalf("expected runtime error")
|
||||
}
|
||||
if result.FailbackAttempts != 1 || result.StatusWriteCount != 1 {
|
||||
t.Fatalf("result=%+v", result)
|
||||
}
|
||||
if got := client.writes[0].status.ReasonCode; got != AuthorityExecutorFailbackReasonRuntimeFailed {
|
||||
t.Fatalf("reason=%s", got)
|
||||
}
|
||||
if client.writes[0].status.FailbackStarted {
|
||||
t.Fatalf("failed runtime must not claim failback: %+v", client.writes[0].status)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFailbackExecutorRejectsInvalidRuntimeTerminalEvidence(t *testing.T) {
|
||||
client := &fakeFailbackExecutorClient{targets: []SwBlockReplicaFailbackObject{failbackExecutorExecutableTargetFixture()}}
|
||||
runtime := &fakeFailbackRuntime{result: FailbackRuntimeResult{
|
||||
FailbackStarted: true,
|
||||
AuthorityEpochAdvanced: true,
|
||||
SinglePrimaryAfterFailback: false,
|
||||
PublishTargetSwappedAfterFailback: true,
|
||||
NoStorageMutation: true,
|
||||
NoCrossVolumeIdentityChange: true,
|
||||
}}
|
||||
result, err := (FailbackExecutorReconciler{
|
||||
Namespace: "kube-system",
|
||||
Client: client,
|
||||
Runtime: runtime,
|
||||
ExecutionRequested: true,
|
||||
ExecutionPolicyEnabled: true,
|
||||
}).Reconcile(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("reconcile: %v", err)
|
||||
}
|
||||
if result.FailbackAttempts != 1 || result.StatusWriteCount != 1 {
|
||||
t.Fatalf("result=%+v", result)
|
||||
}
|
||||
status := client.writes[0].status
|
||||
if status.State != FailbackStateBlocked ||
|
||||
status.ReasonCode != AuthorityExecutorFailbackReasonInvalidTerminalEvidence ||
|
||||
status.FailbackStarted ||
|
||||
status.SinglePrimaryAfterFailback {
|
||||
t.Fatalf("status=%+v", status)
|
||||
}
|
||||
}
|
||||
|
||||
func failbackExecutorTestTarget() SwBlockReplicaFailbackObject {
|
||||
return SwBlockReplicaFailbackObject{
|
||||
Ref: OperatorObjectRef{
|
||||
@@ -123,15 +251,41 @@ func failbackExecutorTestTarget() SwBlockReplicaFailbackObject {
|
||||
FrontendFencedBeforeFailback: true,
|
||||
DurableFrontierCovered: true,
|
||||
NoCrossVolumeIdentityChange: true,
|
||||
FailbackDecision: AuthorityExecutorFailbackDecisionDisabled,
|
||||
FailbackReason: AuthorityExecutorFailbackReasonDisabled,
|
||||
FailbackMutationAllowed: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func failbackExecutorExecutableTargetFixture() SwBlockReplicaFailbackObject {
|
||||
target := failbackExecutorTestTarget()
|
||||
target.Spec.FailbackDecision = AuthorityExecutorFailbackDecisionEnabled
|
||||
target.Spec.FailbackReason = "failback_requested"
|
||||
target.Spec.FailbackMutationAllowed = true
|
||||
target.Spec.RuntimeEndpoint = "http://127.0.0.1:23260/runtime/failback"
|
||||
return target
|
||||
}
|
||||
|
||||
type fakeFailbackExecutorClient struct {
|
||||
targets []SwBlockReplicaFailbackObject
|
||||
writes []fakeFailbackStatusWrite
|
||||
}
|
||||
|
||||
type fakeFailbackRuntime struct {
|
||||
requests []FailbackRuntimeRequest
|
||||
result FailbackRuntimeResult
|
||||
err error
|
||||
}
|
||||
|
||||
func (f *fakeFailbackRuntime) ExecuteFailback(_ context.Context, req FailbackRuntimeRequest) (FailbackRuntimeResult, error) {
|
||||
f.requests = append(f.requests, req)
|
||||
if f.err != nil {
|
||||
return FailbackRuntimeResult{}, f.err
|
||||
}
|
||||
return f.result, nil
|
||||
}
|
||||
|
||||
type fakeFailbackStatusWrite struct {
|
||||
ref OperatorObjectRef
|
||||
status SwBlockReplicaFailbackCRDStatus
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package ops
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type HTTPFailbackRuntime struct {
|
||||
Endpoint string
|
||||
Client *http.Client
|
||||
}
|
||||
|
||||
func NewHTTPFailbackRuntime(endpoint string, client *http.Client) *HTTPFailbackRuntime {
|
||||
if client == nil {
|
||||
client = &http.Client{Timeout: 30 * time.Second}
|
||||
}
|
||||
return &HTTPFailbackRuntime{
|
||||
Endpoint: strings.TrimSpace(endpoint),
|
||||
Client: client,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *HTTPFailbackRuntime) ExecuteFailback(ctx context.Context, req FailbackRuntimeRequest) (FailbackRuntimeResult, error) {
|
||||
if r == nil || strings.TrimSpace(r.Endpoint) == "" {
|
||||
return FailbackRuntimeResult{}, fmt.Errorf("failback runtime endpoint is required")
|
||||
}
|
||||
client := r.Client
|
||||
if client == nil {
|
||||
client = &http.Client{Timeout: 30 * time.Second}
|
||||
}
|
||||
body, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return FailbackRuntimeResult{}, fmt.Errorf("marshal failback runtime request: %w", err)
|
||||
}
|
||||
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, r.Endpoint, bytes.NewReader(body))
|
||||
if err != nil {
|
||||
return FailbackRuntimeResult{}, fmt.Errorf("create failback runtime request: %w", err)
|
||||
}
|
||||
httpReq.Header.Set("Content-Type", "application/json")
|
||||
httpReq.Header.Set("Accept", "application/json")
|
||||
resp, err := client.Do(httpReq)
|
||||
if err != nil {
|
||||
return FailbackRuntimeResult{}, fmt.Errorf("post failback runtime request: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
|
||||
payload, _ := io.ReadAll(io.LimitReader(resp.Body, 4096))
|
||||
return FailbackRuntimeResult{}, fmt.Errorf("failback runtime returned HTTP %d: %s", resp.StatusCode, strings.TrimSpace(string(payload)))
|
||||
}
|
||||
var result FailbackRuntimeResult
|
||||
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||
return FailbackRuntimeResult{}, fmt.Errorf("decode failback runtime response: %w", err)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package ops
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHTTPFailbackRuntimePostsRequestAndDecodesResult(t *testing.T) {
|
||||
var got FailbackRuntimeRequest
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
t.Fatalf("method=%s", r.Method)
|
||||
}
|
||||
if ct := r.Header.Get("Content-Type"); !strings.HasPrefix(ct, "application/json") {
|
||||
t.Fatalf("content-type=%q", ct)
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&got); err != nil {
|
||||
t.Fatalf("decode request: %v", err)
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(FailbackRuntimeResult{
|
||||
FailbackStarted: true,
|
||||
AuthorityEpochAdvanced: true,
|
||||
SinglePrimaryAfterFailback: true,
|
||||
PublishTargetSwappedAfterFailback: true,
|
||||
NoStorageMutation: true,
|
||||
NoCrossVolumeIdentityChange: true,
|
||||
EvidenceRefs: []string{"failback-runtime.txt"},
|
||||
})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
result, err := NewHTTPFailbackRuntime(server.URL, server.Client()).ExecuteFailback(context.Background(), FailbackRuntimeRequest{
|
||||
VolumeName: "demo",
|
||||
VolumeID: "pvc-demo",
|
||||
PVCName: "demo-pvc",
|
||||
ReplicaID: "r2",
|
||||
RuntimeEndpoint: server.URL,
|
||||
AckEligible: true,
|
||||
FrontendFencedBeforeFailback: true,
|
||||
DurableFrontierCovered: true,
|
||||
NoCrossVolumeIdentityChange: true,
|
||||
EvidenceRefs: []string{"target.txt"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("execute failback: %v", err)
|
||||
}
|
||||
if got.VolumeName != "demo" ||
|
||||
got.VolumeID != "pvc-demo" ||
|
||||
got.ReplicaID != "r2" ||
|
||||
!got.AckEligible ||
|
||||
!got.FrontendFencedBeforeFailback ||
|
||||
!got.NoCrossVolumeIdentityChange {
|
||||
t.Fatalf("request=%+v", got)
|
||||
}
|
||||
if !result.FailbackStarted ||
|
||||
!result.AuthorityEpochAdvanced ||
|
||||
!result.SinglePrimaryAfterFailback ||
|
||||
!result.PublishTargetSwappedAfterFailback ||
|
||||
!result.NoStorageMutation ||
|
||||
!result.NoCrossVolumeIdentityChange ||
|
||||
!authorityExecutorStringSliceContains(result.EvidenceRefs, "failback-runtime.txt") {
|
||||
t.Fatalf("result=%+v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTTPFailbackRuntimeReturnsHTTPError(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "runtime unavailable", http.StatusServiceUnavailable)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
_, err := NewHTTPFailbackRuntime(server.URL, server.Client()).ExecuteFailback(context.Background(), FailbackRuntimeRequest{})
|
||||
if err == nil || !strings.Contains(err.Error(), "HTTP 503") || !strings.Contains(err.Error(), "runtime unavailable") {
|
||||
t.Fatalf("err=%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTTPFailbackRuntimeRequiresEndpoint(t *testing.T) {
|
||||
_, err := NewHTTPFailbackRuntime("", nil).ExecuteFailback(context.Background(), FailbackRuntimeRequest{})
|
||||
if err == nil || !strings.Contains(err.Error(), "endpoint is required") {
|
||||
t.Fatalf("err=%v", err)
|
||||
}
|
||||
}
|
||||
@@ -144,6 +144,9 @@ func failbackTargetOwnerObject(namespace string, volume SwBlockVolumeObject, con
|
||||
FrontendFencedBeforeFailback: returned.FrontendFenced && !returned.FrontendPrimaryReady,
|
||||
DurableFrontierCovered: returned.DurableFrontierKnown && returned.RequiredFrontierKnown && returned.DurableFrontierLSN >= returned.RequiredFrontierLSN,
|
||||
NoCrossVolumeIdentityChange: true,
|
||||
FailbackDecision: AuthorityExecutorFailbackDecisionDisabled,
|
||||
FailbackReason: AuthorityExecutorFailbackReasonDisabled,
|
||||
FailbackMutationAllowed: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,10 @@ func TestFailbackTargetOwnerCreatesTargetFromReadyContract(t *testing.T) {
|
||||
!created.Spec.AckEligible ||
|
||||
!created.Spec.FrontendFencedBeforeFailback ||
|
||||
!created.Spec.DurableFrontierCovered ||
|
||||
!created.Spec.NoCrossVolumeIdentityChange {
|
||||
!created.Spec.NoCrossVolumeIdentityChange ||
|
||||
created.Spec.FailbackDecision != AuthorityExecutorFailbackDecisionDisabled ||
|
||||
created.Spec.FailbackReason != AuthorityExecutorFailbackReasonDisabled ||
|
||||
created.Spec.FailbackMutationAllowed {
|
||||
t.Fatalf("created=%+v", created)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -569,11 +569,21 @@ func TestPhase75SwBlockReplicaFailbackTargetSchema(t *testing.T) {
|
||||
"frontendFencedBeforeFailback",
|
||||
"durableFrontierCovered",
|
||||
"noCrossVolumeIdentityChange",
|
||||
"failbackDecision",
|
||||
"failbackReason",
|
||||
"failbackMutationAllowed",
|
||||
"runtimeEndpoint",
|
||||
} {
|
||||
if _, ok := specProperties[want]; !ok {
|
||||
t.Fatalf("%s.spec schema missing %s", SwBlockReplicaFailbackKind, want)
|
||||
}
|
||||
}
|
||||
decisionEnum := yamlStringSet(t, yamlMap(t, specProperties, "failbackDecision"), "enum")
|
||||
for _, want := range []string{"disabled", "enabled"} {
|
||||
if !decisionEnum[want] {
|
||||
t.Fatalf("%s.spec.failbackDecision enum missing %s: %+v", SwBlockReplicaFailbackKind, want, decisionEnum)
|
||||
}
|
||||
}
|
||||
required := yamlStringSet(t, yamlMap(t, rootProperties, "spec"), "required")
|
||||
for _, want := range []string{"volumeName", "replicaID"} {
|
||||
if !required[want] {
|
||||
|
||||
@@ -670,6 +670,90 @@ func TestKubernetesStatusClientCreatesSwBlockReplicaRebuildWithoutStatus(t *test
|
||||
}
|
||||
}
|
||||
|
||||
func TestKubernetesStatusClientCreatesSwBlockReplicaFailbackWithoutStatus(t *testing.T) {
|
||||
var request recordedStatusPatch
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if err := json.NewDecoder(r.Body).Decode(&request.Body); err != nil {
|
||||
t.Fatalf("decode request body: %v", err)
|
||||
}
|
||||
request.Method = r.Method
|
||||
request.Path = r.URL.Path
|
||||
request.ContentType = r.Header.Get("Content-Type")
|
||||
request.Authorization = r.Header.Get("Authorization")
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
err := (&KubernetesStatusClient{
|
||||
BaseURL: server.URL,
|
||||
BearerToken: "failback-target-owner-token",
|
||||
HTTPClient: server.Client(),
|
||||
}).CreateSwBlockReplicaFailback(context.Background(), "kube-system", SwBlockReplicaFailbackObject{
|
||||
Ref: OperatorObjectRef{
|
||||
Name: "demo-pvc-r2-failback",
|
||||
},
|
||||
Spec: SwBlockReplicaFailbackSpec{
|
||||
VolumeName: "demo-pvc",
|
||||
VolumeID: "pvc-demo",
|
||||
PVCName: "demo-pvc",
|
||||
ReplicaID: "r2",
|
||||
AckEligible: true,
|
||||
FrontendFencedBeforeFailback: true,
|
||||
DurableFrontierCovered: true,
|
||||
NoCrossVolumeIdentityChange: true,
|
||||
FailbackDecision: AuthorityExecutorFailbackDecisionEnabled,
|
||||
FailbackReason: "failback_requested",
|
||||
FailbackMutationAllowed: true,
|
||||
RuntimeEndpoint: "http://127.0.0.1:23260/runtime/failback",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("create failback target: %v", err)
|
||||
}
|
||||
if request.Method != http.MethodPost {
|
||||
t.Fatalf("method=%s", request.Method)
|
||||
}
|
||||
if request.Path != "/apis/block.seaweedfs.com/v1alpha1/namespaces/kube-system/swblockreplicafailbacks" {
|
||||
t.Fatalf("path=%s", request.Path)
|
||||
}
|
||||
if request.ContentType != "application/json" {
|
||||
t.Fatalf("content-type=%s", request.ContentType)
|
||||
}
|
||||
if request.Authorization != "Bearer failback-target-owner-token" {
|
||||
t.Fatalf("authorization=%s", request.Authorization)
|
||||
}
|
||||
if request.Body["apiVersion"] != SwBlockVolumeAPIVersion || request.Body["kind"] != SwBlockReplicaFailbackKind {
|
||||
t.Fatalf("body identity=%+v", request.Body)
|
||||
}
|
||||
metadata := request.Body["metadata"].(map[string]any)
|
||||
if metadata["name"] != "demo-pvc-r2-failback" || metadata["namespace"] != "kube-system" {
|
||||
t.Fatalf("metadata=%+v", metadata)
|
||||
}
|
||||
spec := request.Body["spec"].(map[string]any)
|
||||
if spec["volumeName"] != "demo-pvc" ||
|
||||
spec["volumeID"] != "pvc-demo" ||
|
||||
spec["pvcName"] != "demo-pvc" ||
|
||||
spec["replicaID"] != "r2" ||
|
||||
spec["ackEligible"] != true ||
|
||||
spec["frontendFencedBeforeFailback"] != true ||
|
||||
spec["durableFrontierCovered"] != true ||
|
||||
spec["noCrossVolumeIdentityChange"] != true ||
|
||||
spec["failbackDecision"] != AuthorityExecutorFailbackDecisionEnabled ||
|
||||
spec["failbackReason"] != "failback_requested" ||
|
||||
spec["failbackMutationAllowed"] != true ||
|
||||
spec["runtimeEndpoint"] != "http://127.0.0.1:23260/runtime/failback" {
|
||||
t.Fatalf("spec=%+v", spec)
|
||||
}
|
||||
for _, forbidden := range []string{"ack_eligible", "frontend_fenced_before_failback", "failback_decision", "failback_mutation_allowed", "runtime_endpoint"} {
|
||||
if _, ok := spec[forbidden]; ok {
|
||||
t.Fatalf("spec leaked %s: %+v", forbidden, spec)
|
||||
}
|
||||
}
|
||||
if _, ok := request.Body["status"]; ok {
|
||||
t.Fatalf("target create must not include status: %+v", request.Body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKubernetesStatusClientCreatesSwBlockFrontendPublicationWithoutStatus(t *testing.T) {
|
||||
var request recordedStatusPatch
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -98,6 +98,10 @@ type SwBlockReplicaFailbackSpec struct {
|
||||
FrontendFencedBeforeFailback bool `json:"frontendFencedBeforeFailback"`
|
||||
DurableFrontierCovered bool `json:"durableFrontierCovered"`
|
||||
NoCrossVolumeIdentityChange bool `json:"noCrossVolumeIdentityChange"`
|
||||
FailbackDecision string `json:"failbackDecision,omitempty"`
|
||||
FailbackReason string `json:"failbackReason,omitempty"`
|
||||
FailbackMutationAllowed bool `json:"failbackMutationAllowed"`
|
||||
RuntimeEndpoint string `json:"runtimeEndpoint,omitempty"`
|
||||
}
|
||||
|
||||
type SwBlockReplicaFailbackCRDStatus struct {
|
||||
|
||||
@@ -296,7 +296,14 @@ Recommended order from here:
|
||||
disabled/blocked status through `swblockreplicafailbacks/status`. It remains
|
||||
status-only: no failback, authority epoch advance, primary reassignment,
|
||||
publish-target swap, frontend publication, or storage mutation is executed.
|
||||
34. Add backup/restore and NVMe ANA parity after they can reuse the same action
|
||||
34. Phase 77: returned-replica failback runtime contract. **Closed 2026-06-26, local PASS**
|
||||
(`internal/docs/finished-plans/phase77_finishedplan_failback_runtime_contract.md`).
|
||||
The failback executor now has an explicit runtime request/response contract
|
||||
and execution-policy gate. Default behavior remains disabled. A test/fake
|
||||
runtime can prove the terminal evidence shape for authority epoch advance,
|
||||
single-primary state, publish-target swap, and no storage mutation, but no
|
||||
real blockmaster failback endpoint or authority mutation is shipped.
|
||||
35. 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.
|
||||
|
||||
@@ -321,7 +328,9 @@ 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. Phase 76 adds
|
||||
the matching executor identity and status-only boundary for those failback
|
||||
targets, still keeping all real failback side effects disabled.
|
||||
targets, still keeping all real failback side effects disabled. Phase 77 adds
|
||||
the typed failback runtime contract and opt-in execution gate, but still does
|
||||
not ship a real failback endpoint or authority mutation.
|
||||
|
||||
The practical rule is:
|
||||
|
||||
|
||||
@@ -1,152 +1,165 @@
|
||||
# Current Plan: Phase 76 Returned-Replica Failback Executor Boundary
|
||||
# Current Plan: Phase 77 Returned-Replica Failback Runtime Contract
|
||||
|
||||
Status: complete.
|
||||
|
||||
## Goal
|
||||
|
||||
Phase 75 created the failback handoff target:
|
||||
Phase 76 added the status-only failback executor boundary. Phase 77 adds the
|
||||
typed runtime contract and opt-in execution-policy gate for future real
|
||||
failback.
|
||||
|
||||
```text
|
||||
SwBlockReplicaFailback
|
||||
```
|
||||
|
||||
Phase 76 adds the first executor boundary for that target. The executor can
|
||||
read targets and write `SwBlockReplicaFailback.status`, but it still cannot
|
||||
execute failback.
|
||||
|
||||
This phase is intentionally status-only. It does not advance authority, change
|
||||
the primary, swap publish targets, publish frontend paths, or mutate storage.
|
||||
Default behavior remains disabled and status-only. The runtime path is available
|
||||
only when an explicit executable target and explicit execution-policy flags are
|
||||
present.
|
||||
|
||||
## Deliverables
|
||||
|
||||
### D1: Status-Only Failback Executor
|
||||
### D1: Executable Target Contract
|
||||
|
||||
Added:
|
||||
`SwBlockReplicaFailback.spec` now admits the fields needed to distinguish an
|
||||
ordinary disabled target from a future executable target:
|
||||
|
||||
```text
|
||||
sw-block ops failback-executor
|
||||
failbackDecision=disabled|enabled
|
||||
failbackReason
|
||||
failbackMutationAllowed
|
||||
runtimeEndpoint
|
||||
```
|
||||
|
||||
For each target it writes:
|
||||
The Phase 75 target owner still creates disabled targets:
|
||||
|
||||
```text
|
||||
state=blocked
|
||||
reasonCode=failback_policy_disabled
|
||||
failbackDecision=disabled
|
||||
failbackReason=failback_policy_disabled
|
||||
failbackMutationAllowed=false
|
||||
failbackStarted=false
|
||||
authorityEpochAdvanced=false
|
||||
singlePrimaryAfterFailback=false
|
||||
publishTargetSwappedAfterFailback=false
|
||||
```
|
||||
|
||||
Invalid targets are also blocked:
|
||||
|
||||
```text
|
||||
reasonCode=missing_required_facts
|
||||
```
|
||||
|
||||
### D2: Kubernetes Status Writer
|
||||
### D2: Runtime Contract
|
||||
|
||||
Added:
|
||||
|
||||
```text
|
||||
WriteReplicaFailbackStatus(...)
|
||||
FailbackRuntime
|
||||
FailbackRuntimeRequest
|
||||
FailbackRuntimeResult
|
||||
HTTPFailbackRuntime
|
||||
```
|
||||
|
||||
The writer patches only:
|
||||
Runtime request carries:
|
||||
|
||||
```text
|
||||
swblockreplicafailbacks/status
|
||||
volumeName
|
||||
volumeID
|
||||
pvcName
|
||||
replicaID
|
||||
runtimeEndpoint
|
||||
ackEligible
|
||||
frontendFencedBeforeFailback
|
||||
durableFrontierCovered
|
||||
noCrossVolumeIdentityChange
|
||||
```
|
||||
|
||||
It never patches spec, finalizers, Events, workloads, storage objects, or
|
||||
frontend publication resources.
|
||||
|
||||
### D3: Helm Packaging + RBAC
|
||||
|
||||
Added disabled-by-default packaging:
|
||||
Runtime result must return terminal evidence:
|
||||
|
||||
```text
|
||||
failbackExecutor.create=false
|
||||
failbackExecutor.dryRun=true
|
||||
failbackStarted=true
|
||||
authorityEpochAdvanced=true
|
||||
singlePrimaryAfterFailback=true
|
||||
publishTargetSwappedAfterFailback=true
|
||||
noStorageMutation=true
|
||||
noCrossVolumeIdentityChange=true
|
||||
```
|
||||
|
||||
RBAC is status-only:
|
||||
If any terminal evidence is missing, the executor writes blocked status and
|
||||
does not claim failback.
|
||||
|
||||
### D3: Execution Policy Gate
|
||||
|
||||
`sw-block ops failback-executor` now has explicit execution flags:
|
||||
|
||||
```text
|
||||
swblockreplicafailbacks: get,list,watch
|
||||
swblockreplicafailbacks/status: get,update,patch
|
||||
--enable-execution
|
||||
--execution-policy
|
||||
--failback-runtime-url <url>
|
||||
```
|
||||
|
||||
Execution remains blocked unless both `--enable-execution` and
|
||||
`--execution-policy` are set. Passing `--failback-runtime-url` without
|
||||
execution is rejected.
|
||||
|
||||
### D4: Gate
|
||||
|
||||
Added:
|
||||
|
||||
```text
|
||||
scripts/run-phase76-failback-executor-boundary-gate.sh
|
||||
testops/scenarios/failback-executor-boundary-chain.yaml
|
||||
scripts/run-phase77-failback-runtime-contract-gate.sh
|
||||
testops/scenarios/failback-runtime-contract-chain.yaml
|
||||
```
|
||||
|
||||
The gate proves:
|
||||
|
||||
```text
|
||||
failback executor writes disabled/blocked status
|
||||
dry-run writes no status
|
||||
invalid targets are blocked
|
||||
status writer uses /status
|
||||
RBAC is status-only
|
||||
failback_attempts=0
|
||||
authority_mutation_allowed=false
|
||||
frontend_publication_allowed=false
|
||||
default executor still disabled
|
||||
execution policy blocks without enable
|
||||
explicit enabled target invokes runtime
|
||||
runtime failure does not claim failback
|
||||
invalid terminal evidence does not claim failback
|
||||
HTTP runtime posts/decodes contract
|
||||
target writer serializes runtime fields
|
||||
storage_mutation_allowed=false
|
||||
```
|
||||
|
||||
## Non-Claims
|
||||
|
||||
Phase 76 does not implement:
|
||||
Phase 77 does not implement:
|
||||
|
||||
```text
|
||||
real failback execution
|
||||
authority epoch mutation
|
||||
primary reassignment
|
||||
publish-target swap
|
||||
frontend publication
|
||||
real blockmaster failback endpoint
|
||||
real authority epoch mutation
|
||||
real primary reassignment
|
||||
real publish-target swap
|
||||
blockvolume frontend switching
|
||||
storage/workload mutation
|
||||
NVMe ANA behavior
|
||||
```
|
||||
|
||||
The successful runtime path in tests uses a fake/HTTP test runtime to validate
|
||||
the contract shape only.
|
||||
|
||||
## Verification
|
||||
|
||||
```text
|
||||
go test ./core/ops -run "TestFailbackExecutor|TestPhase76|TestKubernetesStatusClientPatchesOnlyStatusSubresources" -count=1 -v
|
||||
go test ./core/ops -run "TestFailbackExecutor|TestHTTPFailbackRuntime|TestFailbackTargetOwner|TestPhase75SwBlockReplicaFailbackTargetSchema|TestKubernetesStatusClientCreatesSwBlockReplicaFailbackWithoutStatus" -count=1 -v
|
||||
go test ./cmd/sw-block -run "TestOpsFailbackExecutor|TestOpsFailbackTargetOwner" -count=1 -v
|
||||
go test ./core/ops ./cmd/sw-block
|
||||
helm lint charts/seaweed-block
|
||||
helm template sw-block charts/seaweed-block --set failbackExecutor.create=true
|
||||
"C:\Program Files\Git\bin\bash.exe" scripts/run-phase76-failback-executor-boundary-gate.sh .
|
||||
C:\work\swblock.exe validate testops\scenarios\failback-executor-boundary-chain.yaml
|
||||
"C:\Program Files\Git\bin\bash.exe" scripts/run-phase77-failback-runtime-contract-gate.sh .
|
||||
C:\work\swblock.exe validate testops\scenarios\failback-runtime-contract-chain.yaml
|
||||
```
|
||||
|
||||
Terminal evidence:
|
||||
|
||||
```text
|
||||
phase76_failback_executor_boundary_status=ok
|
||||
core_ops_failback_executor_tests=pass
|
||||
cmd_failback_executor_tests=pass
|
||||
failback_executor_writes_disabled_status=true
|
||||
failback_executor_dry_run_no_status_write=true
|
||||
kubernetes_writer_failback_status_subresource=true
|
||||
failback_executor_rbac_status_only=true
|
||||
failback_attempts=0
|
||||
authority_mutation_allowed=false
|
||||
frontend_publication_allowed=false
|
||||
phase77_failback_runtime_contract_status=ok
|
||||
core_ops_failback_runtime_tests=pass
|
||||
cmd_failback_runtime_tests=pass
|
||||
failback_runtime_contract_schema_locked=true
|
||||
failback_runtime_endpoint_field=true
|
||||
failback_enabled_target_schema=true
|
||||
failback_execution_policy_gate=true
|
||||
failback_runtime_invoked_only_when_enabled=true
|
||||
failback_runtime_failure_no_false_failback=true
|
||||
failback_runtime_invalid_terminal_evidence_no_false_failback=true
|
||||
failback_attempts=1
|
||||
failback_started=true
|
||||
authority_epoch_advanced=true
|
||||
single_primary_after_failback=true
|
||||
publish_target_swapped_after_failback=true
|
||||
storage_mutation_allowed=false
|
||||
```
|
||||
|
||||
## Next
|
||||
|
||||
The next step is a failback execution preflight/runtime contract. It must remain
|
||||
disabled until it can prove the full terminal evidence: authority ownership,
|
||||
epoch advance, single-primary state, publish-target swap, and cross-volume
|
||||
identity isolation.
|
||||
The next phase should add the first real product-owned failback endpoint or
|
||||
authority-owner seam. It must mutate only authority state, prove epoch advance
|
||||
and single-primary state, and still avoid storage/workload mutation.
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
# Phase 77 Finished Plan: Returned-Replica Failback Runtime Contract
|
||||
|
||||
Status: complete.
|
||||
|
||||
## Problem
|
||||
|
||||
Phase 76 gave `SwBlockReplicaFailback` a status-only executor. The next missing
|
||||
piece was the execution envelope: what request a future failback runtime would
|
||||
receive, what evidence it must return, and how the executor refuses to claim
|
||||
failback when policy or terminal evidence is missing.
|
||||
|
||||
## Implementation
|
||||
|
||||
Added executable target fields to `SwBlockReplicaFailback.spec`:
|
||||
|
||||
```text
|
||||
failbackDecision=disabled|enabled
|
||||
failbackReason
|
||||
failbackMutationAllowed
|
||||
runtimeEndpoint
|
||||
```
|
||||
|
||||
The Phase 75 target owner now emits explicitly disabled targets:
|
||||
|
||||
```text
|
||||
failbackDecision=disabled
|
||||
failbackReason=failback_policy_disabled
|
||||
failbackMutationAllowed=false
|
||||
```
|
||||
|
||||
Added runtime contract:
|
||||
|
||||
```text
|
||||
FailbackRuntime
|
||||
FailbackRuntimeRequest
|
||||
FailbackRuntimeResult
|
||||
HTTPFailbackRuntime
|
||||
```
|
||||
|
||||
Terminal success requires:
|
||||
|
||||
```text
|
||||
failbackStarted=true
|
||||
authorityEpochAdvanced=true
|
||||
singlePrimaryAfterFailback=true
|
||||
publishTargetSwappedAfterFailback=true
|
||||
noStorageMutation=true
|
||||
noCrossVolumeIdentityChange=true
|
||||
```
|
||||
|
||||
Added CLI policy gate:
|
||||
|
||||
```text
|
||||
sw-block ops failback-executor --enable-execution --execution-policy --failback-runtime-url <url>
|
||||
```
|
||||
|
||||
Default reconciliation remains disabled/status-only.
|
||||
|
||||
## Gate
|
||||
|
||||
Added:
|
||||
|
||||
```text
|
||||
scripts/run-phase77-failback-runtime-contract-gate.sh
|
||||
testops/scenarios/failback-runtime-contract-chain.yaml
|
||||
```
|
||||
|
||||
The gate checks:
|
||||
|
||||
```text
|
||||
default executor still disabled
|
||||
execution policy blocks without enable
|
||||
explicit enabled target invokes runtime
|
||||
runtime failure does not claim failback
|
||||
invalid terminal evidence does not claim failback
|
||||
HTTP runtime request/response shape
|
||||
target writer serializes runtime fields
|
||||
storage mutation remains false
|
||||
```
|
||||
|
||||
## Verification
|
||||
|
||||
```text
|
||||
go test ./core/ops -run "TestFailbackExecutor|TestHTTPFailbackRuntime|TestFailbackTargetOwner|TestPhase75SwBlockReplicaFailbackTargetSchema|TestKubernetesStatusClientCreatesSwBlockReplicaFailbackWithoutStatus" -count=1 -v
|
||||
go test ./cmd/sw-block -run "TestOpsFailbackExecutor|TestOpsFailbackTargetOwner" -count=1 -v
|
||||
go test ./core/ops ./cmd/sw-block
|
||||
helm lint charts/seaweed-block
|
||||
"C:\Program Files\Git\bin\bash.exe" scripts/run-phase77-failback-runtime-contract-gate.sh .
|
||||
C:\work\swblock.exe validate testops\scenarios\failback-runtime-contract-chain.yaml
|
||||
```
|
||||
|
||||
Terminal evidence:
|
||||
|
||||
```text
|
||||
phase77_failback_runtime_contract_status=ok
|
||||
core_ops_failback_runtime_tests=pass
|
||||
cmd_failback_runtime_tests=pass
|
||||
failback_runtime_contract_schema_locked=true
|
||||
failback_runtime_endpoint_field=true
|
||||
failback_enabled_target_schema=true
|
||||
failback_execution_policy_gate=true
|
||||
failback_runtime_invoked_only_when_enabled=true
|
||||
failback_runtime_failure_no_false_failback=true
|
||||
failback_runtime_invalid_terminal_evidence_no_false_failback=true
|
||||
failback_attempts=1
|
||||
failback_started=true
|
||||
authority_epoch_advanced=true
|
||||
single_primary_after_failback=true
|
||||
publish_target_swapped_after_failback=true
|
||||
storage_mutation_allowed=false
|
||||
```
|
||||
|
||||
## Non-Claims
|
||||
|
||||
Phase 77 does not implement:
|
||||
|
||||
```text
|
||||
real blockmaster failback endpoint
|
||||
real authority epoch mutation
|
||||
real primary reassignment
|
||||
real publish-target swap
|
||||
blockvolume frontend switching
|
||||
storage/workload mutation
|
||||
```
|
||||
|
||||
## Next
|
||||
|
||||
Implement the product-owned failback endpoint or authority-owner seam. It must
|
||||
be gated by the runtime contract and prove epoch advance, single-primary state,
|
||||
publish-target swap, and cross-volume isolation before any user-facing
|
||||
`failed_back` claim is allowed outside test/fake runtime evidence.
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
# Phase 77 Returned-Replica Failback Runtime Contract QA Sign-off
|
||||
|
||||
Verdict: PASS.
|
||||
|
||||
## Scope
|
||||
|
||||
Phase 77 validates the typed runtime contract for future
|
||||
`SwBlockReplicaFailback` execution. This is a local/runner contract gate; it
|
||||
does not run a real blockmaster failback endpoint and does not mutate live
|
||||
authority state.
|
||||
|
||||
## Evidence
|
||||
|
||||
Local checks:
|
||||
|
||||
```text
|
||||
go test ./core/ops -run "TestFailbackExecutor|TestHTTPFailbackRuntime|TestFailbackTargetOwner|TestPhase75SwBlockReplicaFailbackTargetSchema|TestKubernetesStatusClientCreatesSwBlockReplicaFailbackWithoutStatus" -count=1 -v
|
||||
go test ./cmd/sw-block -run "TestOpsFailbackExecutor|TestOpsFailbackTargetOwner" -count=1 -v
|
||||
go test ./core/ops ./cmd/sw-block
|
||||
helm lint charts/seaweed-block
|
||||
"C:\Program Files\Git\bin\bash.exe" scripts/run-phase77-failback-runtime-contract-gate.sh .
|
||||
C:\work\swblock.exe validate testops\scenarios\failback-runtime-contract-chain.yaml
|
||||
```
|
||||
|
||||
Gate summary:
|
||||
|
||||
```text
|
||||
phase77_failback_runtime_contract_status=ok
|
||||
phase77_scope=failback_runtime_contract
|
||||
default_failback_attempts=0
|
||||
default_authority_mutation_allowed=false
|
||||
default_frontend_publication_allowed=false
|
||||
default_storage_mutation_allowed=false
|
||||
core_ops_failback_runtime_tests=pass
|
||||
cmd_failback_runtime_tests=pass
|
||||
failback_target_schema_runtime_fields=true
|
||||
default_executor_still_disabled=true
|
||||
execution_policy_blocks_without_enable=true
|
||||
explicit_enabled_target_invokes_runtime=true
|
||||
runtime_failure_no_false_failback=true
|
||||
runtime_invalid_terminal_evidence_no_false_failback=true
|
||||
http_runtime_contract_posts_request=true
|
||||
http_runtime_contract_errors_surface=true
|
||||
http_runtime_contract_requires_endpoint=true
|
||||
target_writer_serializes_runtime_fields=true
|
||||
cmd_execution_policy_blocks=true
|
||||
cmd_runtime_url_writes_failed_back_status=true
|
||||
failback_runtime_contract_schema_locked=true
|
||||
failback_runtime_endpoint_field=true
|
||||
failback_enabled_target_schema=true
|
||||
failback_execution_policy_gate=true
|
||||
failback_runtime_invoked_only_when_enabled=true
|
||||
failback_runtime_failure_no_false_failback=true
|
||||
failback_runtime_invalid_terminal_evidence_no_false_failback=true
|
||||
failback_attempts=1
|
||||
failback_started=true
|
||||
authority_epoch_advanced=true
|
||||
single_primary_after_failback=true
|
||||
publish_target_swapped_after_failback=true
|
||||
storage_mutation_allowed=false
|
||||
phase77_failback_runtime_contract_status=ok
|
||||
```
|
||||
|
||||
## Result
|
||||
|
||||
PASS:
|
||||
|
||||
- Default failback executor remains disabled/status-only.
|
||||
- Execution requires both `--enable-execution` and `--execution-policy`.
|
||||
- Runtime URL without execution is rejected.
|
||||
- Enabled fake-runtime target can return terminal evidence.
|
||||
- Runtime failures and incomplete terminal evidence write blocked status and do
|
||||
not claim failback.
|
||||
- Target writer serializes the new runtime fields in camelCase.
|
||||
- No storage mutation is part of the failback runtime contract.
|
||||
|
||||
## Non-Claims
|
||||
|
||||
Phase 77 does not claim a real failback endpoint, real authority epoch mutation,
|
||||
real primary reassignment, real publish-target swap, blockvolume frontend
|
||||
switching, storage/workload mutation, or NVMe ANA parity.
|
||||
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
PRODUCT_ROOT="${1:-$(pwd)}"
|
||||
ARTIFACT_DIR="${SW_BLOCK_ARTIFACT_DIR:-${PRODUCT_ROOT}/results/phase77-failback-runtime-contract-gate}"
|
||||
SUMMARY="${ARTIFACT_DIR}/phase77-failback-runtime-contract-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 "phase77_failback_runtime_contract_status=running"
|
||||
write_summary "phase77_scope=failback_runtime_contract"
|
||||
write_summary "default_failback_attempts=0"
|
||||
write_summary "default_authority_mutation_allowed=false"
|
||||
write_summary "default_frontend_publication_allowed=false"
|
||||
write_summary "default_storage_mutation_allowed=false"
|
||||
|
||||
OPS_PATTERN="TestPhase75SwBlockReplicaFailbackTargetSchema|TestFailbackExecutorWritesDisabledStatus|TestFailbackExecutorExecutionPolicyBlocks|TestFailbackExecutorInvokesRuntimeWhenExplicitlyEnabled|TestFailbackExecutorRuntimeFailureWritesBlockedStatus|TestFailbackExecutorRejectsInvalidRuntimeTerminalEvidence|TestHTTPFailbackRuntimePostsRequestAndDecodesResult|TestHTTPFailbackRuntimeReturnsHTTPError|TestHTTPFailbackRuntimeRequiresEndpoint|TestKubernetesStatusClientCreatesSwBlockReplicaFailbackWithoutStatus"
|
||||
CMD_PATTERN="TestOpsFailbackExecutorExecutionPolicyBlocks|TestOpsFailbackExecutorRuntimeURLWritesFailedBackStatus"
|
||||
|
||||
if (cd "${PRODUCT_ROOT}" && go test ./core/ops -run "${OPS_PATTERN}" -count=1 -v) >"${OPS_LOG}" 2>&1; then
|
||||
write_summary "core_ops_failback_runtime_tests=pass"
|
||||
else
|
||||
write_summary "core_ops_failback_runtime_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_runtime_tests=pass"
|
||||
else
|
||||
write_summary "cmd_failback_runtime_tests=fail"
|
||||
cat "${CMD_LOG}" >&2 || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
require_log "failback_target_schema_runtime_fields" "^--- PASS: TestPhase75SwBlockReplicaFailbackTargetSchema" "${OPS_LOG}"
|
||||
require_log "default_executor_still_disabled" "^--- PASS: TestFailbackExecutorWritesDisabledStatus" "${OPS_LOG}"
|
||||
require_log "execution_policy_blocks_without_enable" "^--- PASS: TestFailbackExecutorExecutionPolicyBlocks" "${OPS_LOG}"
|
||||
require_log "explicit_enabled_target_invokes_runtime" "^--- PASS: TestFailbackExecutorInvokesRuntimeWhenExplicitlyEnabled" "${OPS_LOG}"
|
||||
require_log "runtime_failure_no_false_failback" "^--- PASS: TestFailbackExecutorRuntimeFailureWritesBlockedStatus" "${OPS_LOG}"
|
||||
require_log "runtime_invalid_terminal_evidence_no_false_failback" "^--- PASS: TestFailbackExecutorRejectsInvalidRuntimeTerminalEvidence" "${OPS_LOG}"
|
||||
require_log "http_runtime_contract_posts_request" "^--- PASS: TestHTTPFailbackRuntimePostsRequestAndDecodesResult" "${OPS_LOG}"
|
||||
require_log "http_runtime_contract_errors_surface" "^--- PASS: TestHTTPFailbackRuntimeReturnsHTTPError" "${OPS_LOG}"
|
||||
require_log "http_runtime_contract_requires_endpoint" "^--- PASS: TestHTTPFailbackRuntimeRequiresEndpoint" "${OPS_LOG}"
|
||||
require_log "target_writer_serializes_runtime_fields" "^--- PASS: TestKubernetesStatusClientCreatesSwBlockReplicaFailbackWithoutStatus" "${OPS_LOG}"
|
||||
require_log "cmd_execution_policy_blocks" "^--- PASS: TestOpsFailbackExecutorExecutionPolicyBlocks" "${CMD_LOG}"
|
||||
require_log "cmd_runtime_url_writes_failed_back_status" "^--- PASS: TestOpsFailbackExecutorRuntimeURLWritesFailedBackStatus" "${CMD_LOG}"
|
||||
|
||||
write_summary "failback_runtime_contract_schema_locked=true"
|
||||
write_summary "failback_runtime_endpoint_field=true"
|
||||
write_summary "failback_enabled_target_schema=true"
|
||||
write_summary "failback_execution_policy_gate=true"
|
||||
write_summary "failback_runtime_invoked_only_when_enabled=true"
|
||||
write_summary "failback_runtime_failure_no_false_failback=true"
|
||||
write_summary "failback_runtime_invalid_terminal_evidence_no_false_failback=true"
|
||||
write_summary "failback_attempts=1"
|
||||
write_summary "failback_started=true"
|
||||
write_summary "authority_epoch_advanced=true"
|
||||
write_summary "single_primary_after_failback=true"
|
||||
write_summary "publish_target_swapped_after_failback=true"
|
||||
write_summary "storage_mutation_allowed=false"
|
||||
write_summary "phase77_failback_runtime_contract_status=ok"
|
||||
@@ -0,0 +1,106 @@
|
||||
# Runner-native Phase 77 gate: failback has a typed runtime contract and
|
||||
# explicit execution-policy gate. Default reconciliation remains disabled; a
|
||||
# fake runtime can report terminal evidence only in tests.
|
||||
|
||||
name: failback-runtime-contract-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_runtime_contract_gate
|
||||
actions:
|
||||
- action: exec
|
||||
node: m02
|
||||
timeout: 7m
|
||||
cmd: "rm -rf /mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase77-failback-runtime-contract && mkdir -p /mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase77-failback-runtime-contract && cd {{ product_root }} && SW_BLOCK_ARTIFACT_DIR=/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase77-failback-runtime-contract bash scripts/run-phase77-failback-runtime-contract-gate.sh {{ product_root }}"
|
||||
|
||||
- action: grep_log
|
||||
node: m02
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase77-failback-runtime-contract/phase77-failback-runtime-contract-summary.txt"
|
||||
pattern: "^phase77_failback_runtime_contract_status=ok$"
|
||||
save_as: phase77_ok
|
||||
- action: assert_greater
|
||||
actual: "{{ phase77_ok }}"
|
||||
threshold: "0"
|
||||
|
||||
- action: grep_log
|
||||
node: m02
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase77-failback-runtime-contract/phase77-failback-runtime-contract-summary.txt"
|
||||
pattern: "^failback_execution_policy_gate=true$"
|
||||
save_as: policy_gate
|
||||
- action: assert_greater
|
||||
actual: "{{ policy_gate }}"
|
||||
threshold: "0"
|
||||
|
||||
- action: grep_log
|
||||
node: m02
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase77-failback-runtime-contract/phase77-failback-runtime-contract-summary.txt"
|
||||
pattern: "^failback_runtime_invoked_only_when_enabled=true$"
|
||||
save_as: runtime_gated
|
||||
- action: assert_greater
|
||||
actual: "{{ runtime_gated }}"
|
||||
threshold: "0"
|
||||
|
||||
- action: grep_log
|
||||
node: m02
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase77-failback-runtime-contract/phase77-failback-runtime-contract-summary.txt"
|
||||
pattern: "^runtime_failure_no_false_failback=true$"
|
||||
save_as: failure_no_false
|
||||
- action: assert_greater
|
||||
actual: "{{ failure_no_false }}"
|
||||
threshold: "0"
|
||||
|
||||
- action: grep_log
|
||||
node: m02
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase77-failback-runtime-contract/phase77-failback-runtime-contract-summary.txt"
|
||||
pattern: "^runtime_invalid_terminal_evidence_no_false_failback=true$"
|
||||
save_as: invalid_no_false
|
||||
- action: assert_greater
|
||||
actual: "{{ invalid_no_false }}"
|
||||
threshold: "0"
|
||||
|
||||
- action: grep_log
|
||||
node: m02
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase77-failback-runtime-contract/phase77-failback-runtime-contract-summary.txt"
|
||||
pattern: "^http_runtime_contract_posts_request=true$"
|
||||
save_as: http_contract
|
||||
- action: assert_greater
|
||||
actual: "{{ http_contract }}"
|
||||
threshold: "0"
|
||||
|
||||
- action: grep_log
|
||||
node: m02
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase77-failback-runtime-contract/phase77-failback-runtime-contract-summary.txt"
|
||||
pattern: "^target_writer_serializes_runtime_fields=true$"
|
||||
save_as: writer_contract
|
||||
- action: assert_greater
|
||||
actual: "{{ writer_contract }}"
|
||||
threshold: "0"
|
||||
|
||||
- action: grep_log
|
||||
node: m02
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase77-failback-runtime-contract/phase77-failback-runtime-contract-summary.txt"
|
||||
pattern: "^storage_mutation_allowed=false$"
|
||||
save_as: no_storage_mutation
|
||||
- action: assert_greater
|
||||
actual: "{{ no_storage_mutation }}"
|
||||
threshold: "0"
|
||||
|
||||
- name: collect
|
||||
always: true
|
||||
actions:
|
||||
- action: collect_path
|
||||
node: m02
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase77-failback-runtime-contract"
|
||||
name: "remote-phases"
|
||||
ignore_error: true
|
||||
Reference in new issue
Block a user