Merge pull request #40 from seaweedfs/k8s-alpha/ownerref-default

scripts: default alpha cleanup to PVC owner references
This commit is contained in:
Ping Qiu authored and GitHub committed 2026-05-04 22:20:55 -07:00
commit 56d7add809
8 files changed
+57 -4

No files matched your search

+3 -1
View File
@@ -139,7 +139,9 @@ kubectl apply -f examples/kubernetes/basic-app/writer-pod.yaml
`apply-k8s-alpha-blockvolumes.sh` is temporary. It applies the blockvolume
workload generated by blockmaster until a real operator owns that
reconciliation.
reconciliation. The default install path renders generated workloads with a
PVC owner reference, so Kubernetes garbage collection removes them after the
PVC is deleted.
## Repository layout
@@ -105,6 +105,40 @@ func TestAlphaScripts_OwnerRefModeInjectsBothLauncherAndCSILookupFlags(t *testin
}
}
func TestPublicAlphaWrappers_DefaultToPVCOwnerReferenceCleanup(t *testing.T) {
for _, script := range []string{"run-k8s-alpha.sh", "run-k8s-demo.sh"} {
t.Run(script, func(t *testing.T) {
body := g15dReadFile(t, "scripts", script)
if !strings.Contains(body, `SW_BLOCK_LAUNCHER_PVC_OWNER_REF="${SW_BLOCK_LAUNCHER_PVC_OWNER_REF:-1}"`) {
t.Fatalf("%s must default SW_BLOCK_LAUNCHER_PVC_OWNER_REF to 1", script)
}
})
}
}
func TestInstallAlpha_DefaultsToPVCOwnerReferenceCleanup(t *testing.T) {
body := g15dReadFile(t, "scripts", "install-k8s-alpha.sh")
for _, want := range []string{
`LAUNCHER_PVC_OWNER_REF="${SW_BLOCK_LAUNCHER_PVC_OWNER_REF:-1}"`,
"--launcher-pvc-owner-ref",
"--kubernetes-pvc-uid-lookup",
} {
if !strings.Contains(body, want) {
t.Fatalf("install script missing %q", want)
}
}
}
func TestApplyAlphaBlockvolumes_WaitsForGeneratedManifestInsteadOfKubeSystem(t *testing.T) {
body := g15dReadFile(t, "scripts", "apply-k8s-alpha-blockvolumes.sh")
if !strings.Contains(body, `kubectl wait -f "$ARTIFACT_DIR/generated-blockvolume.yaml" --for=condition=available`) {
t.Fatalf("apply script must wait using generated manifest:\n%s", body)
}
if strings.Contains(body, "kubectl -n kube-system wait --for=condition=available deploy -l app=sw-blockvolume") {
t.Fatalf("apply script must not hardcode kube-system generated workloads:\n%s", body)
}
}
func g15dReadFile(t *testing.T, parts ...string) string {
t.Helper()
root := g15bRepoRoot(t)
+3 -1
View File
@@ -166,6 +166,8 @@ For the copyable YAML, see
- The generated `blockvolume` workload is applied by the demo runner. A real
operator should own this reconciliation.
- By default, generated `blockvolume` Deployments carry a PVC owner reference,
so Kubernetes garbage collection removes them after the PVC is deleted.
- The demo uses single-node Kubernetes.
- The alpha manifest uses non-durable pod-local state for the generated
`blockvolume`.
@@ -183,7 +185,7 @@ If you need to clean up manually:
```bash
kubectl delete pod sw-block-demo-writer sw-block-demo-reader --ignore-not-found=true
kubectl delete pvc sw-block-demo-pvc --ignore-not-found=true
kubectl -n kube-system delete deploy -l app=sw-blockvolume --ignore-not-found=true
kubectl delete deploy -A -l app=sw-blockvolume --ignore-not-found=true
kubectl delete -f deploy/k8s/alpha/csi-driver.yaml --ignore-not-found=true
kubectl delete -f deploy/k8s/alpha/rbac.yaml --ignore-not-found=true
kubectl delete -f /tmp/sw-block-stack.yaml --ignore-not-found=true
+2 -1
View File
@@ -23,6 +23,7 @@ Current alpha constraints:
- `walstore` backend only
- launcher-generated blockvolume state uses `emptyDir`
- harness applies generated blockvolume manifests
- generated blockvolume Deployments can use PVC owner references for cleanup
- no production operator yet
## Near-Term MVP Hardening
@@ -43,7 +44,7 @@ Current alpha constraints:
- watch generated workload intent or lifecycle state
- apply/delete blockvolume Deployments
- stop requiring the harness to act as operator
- stop requiring the harness to apply generated workloads
4. Improve TestOps usability.
@@ -40,7 +40,7 @@ kubectl -n kube-system exec deploy/sw-blockmaster -c blockmaster -- sh -c 'cat /
log "apply generated blockvolume workloads"
kubectl apply -f "$ARTIFACT_DIR/generated-blockvolume.yaml" | tee "$ARTIFACT_DIR/apply-generated-blockvolume.log"
kubectl -n kube-system wait --for=condition=available deploy -l app=sw-blockvolume --timeout=120s
kubectl wait -f "$ARTIFACT_DIR/generated-blockvolume.yaml" --for=condition=available --timeout=120s
log "PASS: generated blockvolume workloads are available"
log "artifacts=$ARTIFACT_DIR"
@@ -5,6 +5,7 @@ ROOT="${1:-$(pwd)}"
ARTIFACT_DIR="${SW_BLOCK_ARTIFACT_DIR:-/tmp/sw-block-install-$(date -u +%Y%m%dT%H%M%SZ)}"
IMAGE="${SW_BLOCK_IMAGE:-ghcr.io/seaweedfs/seaweed-block:alpha}"
CSI_IMAGE="${SW_BLOCK_CSI_IMAGE:-ghcr.io/seaweedfs/seaweed-block-csi:alpha}"
LAUNCHER_PVC_OWNER_REF="${SW_BLOCK_LAUNCHER_PVC_OWNER_REF:-1}"
mkdir -p "$ARTIFACT_DIR"
@@ -40,9 +41,19 @@ sed -e "s/__NODE_NAME__/${NODE_NAME}/g" \
-e "s/sw-block:local/${IMAGE_SED}/g" \
-e "s/imagePullPolicy: Never/imagePullPolicy: IfNotPresent/g" \
"$ROOT/deploy/k8s/alpha/block-stack.yaml" >"$STACK_RENDERED"
if [[ "$LAUNCHER_PVC_OWNER_REF" == "1" || "$LAUNCHER_PVC_OWNER_REF" == "true" ]]; then
awk '/--launcher-namespace=/{print; print " - \"--launcher-pvc-owner-ref\""; next} {print}' "$STACK_RENDERED" >"$STACK_RENDERED.tmp"
mv "$STACK_RENDERED.tmp" "$STACK_RENDERED"
grep -q -- '--launcher-pvc-owner-ref' "$STACK_RENDERED" || { echo "failed to inject --launcher-pvc-owner-ref into $STACK_RENDERED" >&2; exit 1; }
fi
sed -e "s/sw-block-csi:local/${CSI_IMAGE_SED}/g" \
-e "s/imagePullPolicy: Never/imagePullPolicy: IfNotPresent/g" \
"$ROOT/deploy/k8s/alpha/csi-controller.yaml" >"$CSI_CONTROLLER_RENDERED"
if [[ "$LAUNCHER_PVC_OWNER_REF" == "1" || "$LAUNCHER_PVC_OWNER_REF" == "true" ]]; then
awk '/--node-id=\$\(NODE_NAME\)/{print; print " - \"--kubernetes-pvc-uid-lookup\""; next} {print}' "$CSI_CONTROLLER_RENDERED" >"$CSI_CONTROLLER_RENDERED.tmp"
mv "$CSI_CONTROLLER_RENDERED.tmp" "$CSI_CONTROLLER_RENDERED"
grep -q -- '--kubernetes-pvc-uid-lookup' "$CSI_CONTROLLER_RENDERED" || { echo "failed to inject --kubernetes-pvc-uid-lookup into $CSI_CONTROLLER_RENDERED" >&2; exit 1; }
fi
sed -e "s/sw-block-csi:local/${CSI_IMAGE_SED}/g" \
-e "s/imagePullPolicy: Never/imagePullPolicy: IfNotPresent/g" \
"$ROOT/deploy/k8s/alpha/csi-node.yaml" >"$CSI_NODE_RENDERED"
@@ -52,6 +63,7 @@ log "root=$ROOT"
log "node=$NODE_NAME"
log "image=$IMAGE"
log "csi_image=$CSI_IMAGE"
log "launcher_pvc_owner_ref=$LAUNCHER_PVC_OWNER_REF"
kubectl version --client=true >"$ARTIFACT_DIR/kubectl-version.txt" 2>&1 || true
kubectl get nodes -o wide >"$ARTIFACT_DIR/nodes.before.txt"
+1
View File
@@ -3,4 +3,5 @@ set -euo pipefail
ROOT="${1:-$(pwd)}"
export SW_BLOCK_LAUNCHER_PVC_OWNER_REF="${SW_BLOCK_LAUNCHER_PVC_OWNER_REF:-1}"
exec bash "$ROOT/scripts/run-alpha-k8s-dynamic.sh" "$ROOT"
+1
View File
@@ -3,4 +3,5 @@ set -euo pipefail
ROOT="${1:-$(pwd)}"
export SW_BLOCK_LAUNCHER_PVC_OWNER_REF="${SW_BLOCK_LAUNCHER_PVC_OWNER_REF:-1}"
exec bash "$ROOT/scripts/run-alpha-app-demo.sh" "$ROOT"