mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
phase38: surface action evaluation decisions
This commit is contained in:
1 parent
aff1d0c953
commit
ec3cb84076
8 files changed
+152
-57
No files matched your search
@@ -136,6 +136,17 @@ spec:
|
||||
type: string
|
||||
ownerExecutor:
|
||||
type: string
|
||||
decision:
|
||||
type: string
|
||||
enum:
|
||||
- allowed
|
||||
- rejected
|
||||
decisionReason:
|
||||
type: string
|
||||
missingFacts:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
mutationAllowed:
|
||||
type: boolean
|
||||
preconditions:
|
||||
@@ -146,6 +157,8 @@ spec:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
evidenceRequired:
|
||||
type: string
|
||||
evidenceRefs:
|
||||
type: array
|
||||
items:
|
||||
|
||||
@@ -149,6 +149,20 @@ func TestPhase36D1SwBlockClusterActionabilitySchema(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPhase38D3SwBlockVolumeAllowedActionEvaluationSchema(t *testing.T) {
|
||||
doc := readYAMLMap(t, "charts/seaweed-block/crds/swblockvolumes.block.seaweedfs.com.yaml")
|
||||
statusProperties := crdStatusProperties(t, doc)
|
||||
actionProperties := yamlMap(t, yamlMap(t, yamlMap(t, statusProperties, "allowedActions"), "items"), "properties")
|
||||
for _, want := range []string{"type", "mode", "sideEffectClass", "ownerExecutor", "decision", "decisionReason", "missingFacts", "mutationAllowed", "preconditions", "invariantRefs", "evidenceRequired", "evidenceRefs"} {
|
||||
if _, ok := actionProperties[want]; !ok {
|
||||
t.Fatalf("SwBlockVolume.status.allowedActions[] schema missing %s", want)
|
||||
}
|
||||
}
|
||||
if _, ok := actionProperties["evidence_required"]; ok {
|
||||
t.Fatalf("SwBlockVolume.status.allowedActions[] schema leaked snake_case evidence_required")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPhase35D1OperatorStatusRBACIsStatusOnly(t *testing.T) {
|
||||
raw := readRepoFile(t, "charts/seaweed-block/templates/operator-status-rbac.yaml")
|
||||
required := []string{
|
||||
|
||||
@@ -58,11 +58,14 @@ func TestKubernetesStatusClientPatchesOnlyStatusSubresources(t *testing.T) {
|
||||
ReasonCode: ReasonFirstVolumeVerified,
|
||||
ObservedAt: observedAt,
|
||||
AllowedActions: []SwBlockVolumeCRDAction{{
|
||||
Type: "observe.collect_bundle",
|
||||
Mode: "read_only",
|
||||
SideEffectClass: "none",
|
||||
OwnerExecutor: "ops",
|
||||
MutationAllowed: false,
|
||||
Type: "observe.collect_bundle",
|
||||
Mode: "read_only",
|
||||
SideEffectClass: "none",
|
||||
OwnerExecutor: "ops",
|
||||
Decision: ManagedVolumeActionDecisionAllowed,
|
||||
DecisionReason: "",
|
||||
MutationAllowed: false,
|
||||
EvidenceRequired: "projection_inputs_or_bundle",
|
||||
}},
|
||||
}); err != nil {
|
||||
t.Fatalf("write volume status: %v", err)
|
||||
@@ -101,9 +104,18 @@ func TestKubernetesStatusClientPatchesOnlyStatusSubresources(t *testing.T) {
|
||||
if _, ok := action["mutationAllowed"]; !ok {
|
||||
t.Fatalf("volume action missing camelCase mutationAllowed: %+v", action)
|
||||
}
|
||||
if _, ok := action["decision"]; !ok {
|
||||
t.Fatalf("volume action missing decision: %+v", action)
|
||||
}
|
||||
if _, ok := action["evidenceRequired"]; !ok {
|
||||
t.Fatalf("volume action missing camelCase evidenceRequired: %+v", action)
|
||||
}
|
||||
if _, ok := action["mutation_allowed"]; ok {
|
||||
t.Fatalf("volume action leaked snake_case mutation_allowed: %+v", action)
|
||||
}
|
||||
if _, ok := action["evidence_required"]; ok {
|
||||
t.Fatalf("volume action leaked snake_case evidence_required: %+v", action)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKubernetesStatusClientCreatesCoreEvents(t *testing.T) {
|
||||
|
||||
@@ -224,14 +224,18 @@ type ManagedVolumeStates struct {
|
||||
}
|
||||
|
||||
type ManagedVolumeAction struct {
|
||||
Type string `json:"type"`
|
||||
Target string `json:"target,omitempty"`
|
||||
Mode string `json:"mode"`
|
||||
SideEffectClass string `json:"side_effect_class"`
|
||||
OwnerExecutor string `json:"owner_executor,omitempty"`
|
||||
Preconditions []string `json:"preconditions,omitempty"`
|
||||
InvariantRefs []string `json:"invariant_refs,omitempty"`
|
||||
EvidenceRefs []string `json:"evidence_refs,omitempty"`
|
||||
Type string `json:"type"`
|
||||
Target string `json:"target,omitempty"`
|
||||
Mode string `json:"mode"`
|
||||
SideEffectClass string `json:"side_effect_class"`
|
||||
OwnerExecutor string `json:"owner_executor,omitempty"`
|
||||
Decision string `json:"decision,omitempty"`
|
||||
DecisionReason string `json:"decision_reason,omitempty"`
|
||||
MissingFacts []string `json:"missing_facts,omitempty"`
|
||||
Preconditions []string `json:"preconditions,omitempty"`
|
||||
InvariantRefs []string `json:"invariant_refs,omitempty"`
|
||||
EvidenceRequired string `json:"evidence_required,omitempty"`
|
||||
EvidenceRefs []string `json:"evidence_refs,omitempty"`
|
||||
}
|
||||
|
||||
type ManagedVolumeArtifactHints struct {
|
||||
@@ -277,11 +281,21 @@ func RenderManagedVolumeProjectionText(projection ManagedVolumeProjection) strin
|
||||
}
|
||||
}
|
||||
for _, action := range projection.Actions {
|
||||
fmt.Fprintf(&b, "managed_volume_action %s mode=%s side_effect=%s executor=%s\n",
|
||||
fmt.Fprintf(&b, "managed_volume_action %s mode=%s side_effect=%s executor=%s decision=%s",
|
||||
emptyAsDash(action.Type),
|
||||
emptyAsDash(action.Mode),
|
||||
emptyAsDash(action.SideEffectClass),
|
||||
emptyAsDash(action.OwnerExecutor))
|
||||
emptyAsDash(action.OwnerExecutor),
|
||||
emptyAsDash(action.Decision))
|
||||
if action.DecisionReason != "" {
|
||||
fmt.Fprintf(&b, " reason=%s", action.DecisionReason)
|
||||
}
|
||||
b.WriteByte('\n')
|
||||
if len(action.MissingFacts) > 0 {
|
||||
fmt.Fprintf(&b, "managed_volume_action_missing_facts %s %s\n",
|
||||
emptyAsDash(action.Type),
|
||||
strings.Join(action.MissingFacts, ","))
|
||||
}
|
||||
if len(action.Preconditions) > 0 {
|
||||
fmt.Fprintf(&b, "managed_volume_action_preconditions %s %s\n",
|
||||
emptyAsDash(action.Type),
|
||||
@@ -297,6 +311,11 @@ func RenderManagedVolumeProjectionText(projection ManagedVolumeProjection) strin
|
||||
emptyAsDash(action.Type),
|
||||
strings.Join(action.EvidenceRefs, ","))
|
||||
}
|
||||
if action.EvidenceRequired != "" {
|
||||
fmt.Fprintf(&b, "managed_volume_action_evidence_required %s %s\n",
|
||||
emptyAsDash(action.Type),
|
||||
action.EvidenceRequired)
|
||||
}
|
||||
}
|
||||
for _, nonClaim := range projection.NonClaims {
|
||||
fmt.Fprintf(&b, "managed_volume_non_claim %s\n", nonClaim)
|
||||
@@ -645,6 +664,16 @@ func managedVolumeActionsForProjection(p ManagedVolumeProjection, facts ManagedV
|
||||
EvidenceRefs: append([]string(nil), p.EvidenceRefs...),
|
||||
})
|
||||
}
|
||||
for i := range actions {
|
||||
evaluation := EvaluateManagedVolumeAction(actions[i].Type, facts)
|
||||
actions[i].Decision = evaluation.Decision
|
||||
actions[i].DecisionReason = evaluation.Reason
|
||||
actions[i].MissingFacts = append([]string(nil), evaluation.MissingFacts...)
|
||||
actions[i].EvidenceRequired = evaluation.EvidenceRequired
|
||||
if len(actions[i].InvariantRefs) == 0 {
|
||||
actions[i].InvariantRefs = append([]string(nil), evaluation.InvariantRefs...)
|
||||
}
|
||||
}
|
||||
return actions
|
||||
}
|
||||
|
||||
|
||||
@@ -373,6 +373,12 @@ func TestManagedVolumeProjection_ActionInvariantRefs(t *testing.T) {
|
||||
if action.OwnerExecutor != "installer_or_operator" || action.SideEffectClass != ManagedVolumeSideEffectSafeK8S || action.Mode != ManagedVolumeActionModeDryRun {
|
||||
t.Fatalf("action boundary=%+v", action)
|
||||
}
|
||||
if action.Decision != ManagedVolumeActionDecisionAllowed {
|
||||
t.Fatalf("action decision=%s reason=%s missing=%v", action.Decision, action.DecisionReason, action.MissingFacts)
|
||||
}
|
||||
if action.EvidenceRequired != "loopback_cross_node_evidence" {
|
||||
t.Fatalf("evidence_required=%q", action.EvidenceRequired)
|
||||
}
|
||||
}
|
||||
|
||||
func TestManagedVolumeProjection_NonClaimsDerivedFromFacts(t *testing.T) {
|
||||
|
||||
@@ -26,14 +26,18 @@ type ManagedVolumeOperatorEvent struct {
|
||||
}
|
||||
|
||||
type ManagedVolumeOperatorAction struct {
|
||||
Type string `json:"type"`
|
||||
Mode string `json:"mode"`
|
||||
SideEffectClass string `json:"side_effect_class"`
|
||||
OwnerExecutor string `json:"owner_executor,omitempty"`
|
||||
MutationAllowed bool `json:"mutation_allowed"`
|
||||
Preconditions []string `json:"preconditions,omitempty"`
|
||||
InvariantRefs []string `json:"invariant_refs,omitempty"`
|
||||
EvidenceRefs []string `json:"evidence_refs,omitempty"`
|
||||
Type string `json:"type"`
|
||||
Mode string `json:"mode"`
|
||||
SideEffectClass string `json:"side_effect_class"`
|
||||
OwnerExecutor string `json:"owner_executor,omitempty"`
|
||||
Decision string `json:"decision,omitempty"`
|
||||
DecisionReason string `json:"decision_reason,omitempty"`
|
||||
MissingFacts []string `json:"missing_facts,omitempty"`
|
||||
MutationAllowed bool `json:"mutation_allowed"`
|
||||
Preconditions []string `json:"preconditions,omitempty"`
|
||||
InvariantRefs []string `json:"invariant_refs,omitempty"`
|
||||
EvidenceRequired string `json:"evidence_required,omitempty"`
|
||||
EvidenceRefs []string `json:"evidence_refs,omitempty"`
|
||||
}
|
||||
|
||||
func ManagedVolumeOperatorContractFromProjection(projection ManagedVolumeProjection) ManagedVolumeOperatorContract {
|
||||
@@ -55,14 +59,18 @@ func ManagedVolumeOperatorContractFromProjection(projection ManagedVolumeProject
|
||||
}
|
||||
for _, action := range projection.Actions {
|
||||
contract.AllowedActions = append(contract.AllowedActions, ManagedVolumeOperatorAction{
|
||||
Type: action.Type,
|
||||
Mode: action.Mode,
|
||||
SideEffectClass: action.SideEffectClass,
|
||||
OwnerExecutor: action.OwnerExecutor,
|
||||
MutationAllowed: false,
|
||||
Preconditions: append([]string(nil), action.Preconditions...),
|
||||
InvariantRefs: append([]string(nil), action.InvariantRefs...),
|
||||
EvidenceRefs: append([]string(nil), action.EvidenceRefs...),
|
||||
Type: action.Type,
|
||||
Mode: action.Mode,
|
||||
SideEffectClass: action.SideEffectClass,
|
||||
OwnerExecutor: action.OwnerExecutor,
|
||||
Decision: action.Decision,
|
||||
DecisionReason: action.DecisionReason,
|
||||
MissingFacts: append([]string(nil), action.MissingFacts...),
|
||||
MutationAllowed: false,
|
||||
Preconditions: append([]string(nil), action.Preconditions...),
|
||||
InvariantRefs: append([]string(nil), action.InvariantRefs...),
|
||||
EvidenceRequired: action.EvidenceRequired,
|
||||
EvidenceRefs: append([]string(nil), action.EvidenceRefs...),
|
||||
})
|
||||
}
|
||||
return contract
|
||||
|
||||
@@ -228,14 +228,18 @@ type SwBlockVolumeCRDStatus struct {
|
||||
}
|
||||
|
||||
type SwBlockVolumeCRDAction struct {
|
||||
Type string `json:"type"`
|
||||
Mode string `json:"mode"`
|
||||
SideEffectClass string `json:"sideEffectClass,omitempty"`
|
||||
OwnerExecutor string `json:"ownerExecutor,omitempty"`
|
||||
MutationAllowed bool `json:"mutationAllowed"`
|
||||
Preconditions []string `json:"preconditions,omitempty"`
|
||||
InvariantRefs []string `json:"invariantRefs,omitempty"`
|
||||
EvidenceRefs []string `json:"evidenceRefs,omitempty"`
|
||||
Type string `json:"type"`
|
||||
Mode string `json:"mode"`
|
||||
SideEffectClass string `json:"sideEffectClass,omitempty"`
|
||||
OwnerExecutor string `json:"ownerExecutor,omitempty"`
|
||||
Decision string `json:"decision,omitempty"`
|
||||
DecisionReason string `json:"decisionReason,omitempty"`
|
||||
MissingFacts []string `json:"missingFacts,omitempty"`
|
||||
MutationAllowed bool `json:"mutationAllowed"`
|
||||
Preconditions []string `json:"preconditions,omitempty"`
|
||||
InvariantRefs []string `json:"invariantRefs,omitempty"`
|
||||
EvidenceRequired string `json:"evidenceRequired,omitempty"`
|
||||
EvidenceRefs []string `json:"evidenceRefs,omitempty"`
|
||||
}
|
||||
|
||||
type OperatorKubernetesEvent struct {
|
||||
@@ -360,14 +364,18 @@ func swBlockVolumeCRDActions(actions []ManagedVolumeOperatorAction) []SwBlockVol
|
||||
out := make([]SwBlockVolumeCRDAction, 0, len(actions))
|
||||
for _, action := range actions {
|
||||
out = append(out, SwBlockVolumeCRDAction{
|
||||
Type: action.Type,
|
||||
Mode: action.Mode,
|
||||
SideEffectClass: action.SideEffectClass,
|
||||
OwnerExecutor: action.OwnerExecutor,
|
||||
MutationAllowed: action.MutationAllowed,
|
||||
Preconditions: append([]string(nil), action.Preconditions...),
|
||||
InvariantRefs: append([]string(nil), action.InvariantRefs...),
|
||||
EvidenceRefs: append([]string(nil), action.EvidenceRefs...),
|
||||
Type: action.Type,
|
||||
Mode: action.Mode,
|
||||
SideEffectClass: action.SideEffectClass,
|
||||
OwnerExecutor: action.OwnerExecutor,
|
||||
Decision: action.Decision,
|
||||
DecisionReason: action.DecisionReason,
|
||||
MissingFacts: append([]string(nil), action.MissingFacts...),
|
||||
MutationAllowed: action.MutationAllowed,
|
||||
Preconditions: append([]string(nil), action.Preconditions...),
|
||||
InvariantRefs: append([]string(nil), action.InvariantRefs...),
|
||||
EvidenceRequired: action.EvidenceRequired,
|
||||
EvidenceRefs: append([]string(nil), action.EvidenceRefs...),
|
||||
})
|
||||
}
|
||||
return out
|
||||
|
||||
@@ -98,16 +98,16 @@ go test ./core/ops
|
||||
Goal: ensure report, operator-snapshot, CRD status, and dashboard do not diverge
|
||||
on the action contract.
|
||||
|
||||
Status: pending.
|
||||
Status: dev-complete; QA/internal review pending.
|
||||
|
||||
Acceptance:
|
||||
|
||||
```text
|
||||
[ ] operator-snapshot exposes the same action fields as the evaluator contract
|
||||
[ ] SwBlockVolume.status.allowedActions remains camelCase and schema-valid
|
||||
[ ] blocked path still has dry-run/read-only actions only
|
||||
[ ] no surface shows mutationAllowed=true
|
||||
[ ] action reasons/evidence refs survive from-bundle replay
|
||||
[x] operator-snapshot exposes the same action fields as the evaluator contract
|
||||
[x] SwBlockVolume.status.allowedActions remains camelCase and schema-valid
|
||||
[x] blocked path still has dry-run/read-only actions only
|
||||
[x] no surface shows mutationAllowed=true
|
||||
[x] action reasons/evidence refs survive from-bundle replay
|
||||
```
|
||||
|
||||
Verification:
|
||||
@@ -201,10 +201,15 @@ QA strict rerun or replay from clean bundle
|
||||
rejects disabled authority mutation with `policy_disabled`, and rejects
|
||||
unknown actions. Unit tests cover allowed dry-run, missing facts, disabled
|
||||
authority mutation, and unknown action rejection.
|
||||
- 42%: D3 dev-complete. ManagedVolume actions now carry evaluator decisions
|
||||
(`allowed`/`rejected`), rejection reasons, missing facts, invariant refs, and
|
||||
evidence requirements through projection text, operator-snapshot, and
|
||||
SwBlockVolume CRD status. The CRD schema and status DTO use camelCase fields
|
||||
(`decisionReason`, `missingFacts`, `evidenceRequired`) to avoid live schema
|
||||
rejection.
|
||||
|
||||
## Next Step
|
||||
|
||||
Wire the evaluator into one user-visible surface without making actions
|
||||
mutating. Recommended next slice: expose action evaluation decisions in
|
||||
operator-snapshot/report for the existing cross-node loopback dry-run action,
|
||||
then add a rejected-action replay gate for `authority.request_promotion`.
|
||||
Add D4 rejected-action evidence: surface a deliberately rejected
|
||||
`authority.request_promotion` decision in a replay/unit gate, prove it remains
|
||||
non-executable, and confirm the operator RBAC boundary stays status/events only.
|
||||
Reference in new issue
Block a user