Files
cozystack/hack/e2e-chainsaw/bucket/chainsaw-test.yaml
T
Myasnikov DaniilandClaude Fable 5 1f9555a3c6 test(e2e): resolve outstanding bot review findings
- redis: assert both StatefulSet-templated PVCs Bound (replicas: 2
  provisions two, only ordinal 0 was checked)
- gateway: || true each delete inside the three cleanup() traps — they
  run under set -eu, so one transient delete failure skipped the
  remaining cleanup commands
- bucket, backup(.disabled): guard the trap's kill against an unset
  pf_pid (script can exit before the port-forward starts)

Not addressed on purpose: the sort(ports[*].port) suggestions on
clickhouse/kafka — sort() is among the JMESPath forms chainsaw v0.2.15
(still the latest release) mis-evaluates, which is why the suites use
the ordered (ports[*].port) projection; services keep spec order.

Assisted-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
2026-07-08 19:13:01 +05:00

136 lines
5.5 KiB
YAML

# Chainsaw port of hack/e2e-apps/bucket.bats ("Create and Verify Seeweedfs Bucket").
#
# The declarative half (resource readiness) becomes assert operations; the
# imperative half (S3 access checks with mc through a port-forward) stays a
# single script step, since a port-forward cannot span chainsaw operations.
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: bucket
spec:
catch:
- events: {}
- describe:
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
name: bucket-test
- describe:
apiVersion: objectstorage.k8s.io/v1alpha1
kind: BucketClaim
name: bucket-test
# The backend view: cluster-scoped Buckets plus the COSI controller pods,
# where a frozen-claim readiness propagation failure actually surfaces.
- get:
apiVersion: objectstorage.k8s.io/v1alpha1
kind: Bucket
- script:
content: kubectl -n cozy-objectstorage-controller get pods
steps:
- name: create-bucket
try:
- apply:
file: bucket.yaml
- name: wait-bucket-ready
try:
- assert:
timeout: 6m
resource:
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: bucket-test
status:
(conditions[?type == 'Ready']):
- status: "True"
# Replaces `until kubectl get ...` + `kubectl wait --for=jsonpath=...`
# pairs: one assert handles both existence and the status field.
# 2m, not the default 5m: the objectstorage-controller requeues the
# BucketClaim until the backend Bucket is ready, so readiness converges
# within tens of seconds; a claim still not ready after 2m is frozen
# (readiness-propagation regression), and the tight bound surfaces that
# instead of masking it (mirrors the bats 120s budget from 63d14e748).
- assert:
timeout: 2m
resource:
apiVersion: objectstorage.k8s.io/v1alpha1
kind: BucketClaim
metadata:
name: bucket-test
status:
bucketReady: true
- assert:
resource:
apiVersion: objectstorage.k8s.io/v1alpha1
kind: BucketAccess
metadata:
name: bucket-test-admin
status:
accessGranted: true
- assert:
resource:
apiVersion: objectstorage.k8s.io/v1alpha1
kind: BucketAccess
metadata:
name: bucket-test-viewer
status:
accessGranted: true
- name: verify-s3-access
try:
- script:
timeout: 5m
content: |
set -eu
workdir=$(mktemp -d)
trap '[ -n "${pf_pid:-}" ] && kill "$pf_pid" 2>/dev/null || true; rm -rf "$workdir"' EXIT
# Extract credentials for both users
kubectl -n "$NAMESPACE" get secret bucket-test-admin \
-o jsonpath='{.data.BucketInfo}' | base64 -d > "$workdir/admin.json"
kubectl -n "$NAMESPACE" get secret bucket-test-viewer \
-o jsonpath='{.data.BucketInfo}' | base64 -d > "$workdir/viewer.json"
ADMIN_ACCESS_KEY=$(jq -r '.spec.secretS3.accessKeyID' "$workdir/admin.json")
ADMIN_SECRET_KEY=$(jq -r '.spec.secretS3.accessSecretKey' "$workdir/admin.json")
VIEWER_ACCESS_KEY=$(jq -r '.spec.secretS3.accessKeyID' "$workdir/viewer.json")
VIEWER_SECRET_KEY=$(jq -r '.spec.secretS3.accessSecretKey' "$workdir/viewer.json")
BUCKET_NAME=$(jq -r '.spec.bucketName' "$workdir/admin.json")
# Port-forward to the S3 endpoint; cleaned up by the trap
kubectl port-forward service/seaweedfs-s3 -n tenant-root 8333:8333 >/dev/null 2>&1 &
pf_pid=$!
timeout 30 sh -ec 'until nc -z localhost 8333; do sleep 1; done'
mc alias set rw-user https://localhost:8333 "$ADMIN_ACCESS_KEY" "$ADMIN_SECRET_KEY" --insecure
mc alias set ro-user https://localhost:8333 "$VIEWER_ACCESS_KEY" "$VIEWER_SECRET_KEY" --insecure
# Admin (readwrite) can upload, list, download
echo "readwrite test" > "$workdir/rw-test.txt"
mc cp --insecure "$workdir/rw-test.txt" "rw-user/$BUCKET_NAME/rw-test.txt"
mc ls --insecure "rw-user/$BUCKET_NAME/rw-test.txt"
mc cp --insecure "rw-user/$BUCKET_NAME/rw-test.txt" "$workdir/rw-test-download.txt"
# Viewer (readonly) can list and download
mc ls --insecure "ro-user/$BUCKET_NAME/rw-test.txt"
mc cp --insecure "ro-user/$BUCKET_NAME/rw-test.txt" "$workdir/ro-test-download.txt"
# Viewer (readonly) upload must be DENIED. accessPolicy=readonly
# enforcement landed with seaweedfs-cosi-driver v0.3.1 (#1921,
# eab9b034f), so a successful upload is a regression, not a known
# gap — fail hard.
echo "readonly test" > "$workdir/ro-test.txt"
if mc cp --insecure "$workdir/ro-test.txt" "ro-user/$BUCKET_NAME/ro-test.txt"; then
echo "FAIL: read-only user must NOT be able to upload (accessPolicy=readonly regression; enforced since cosi-driver v0.3.1, #1921)" >&2
# Drop the object the viewer should not have been able to create
# (via the admin user, which is unambiguously allowed to delete).
mc rm --insecure "rw-user/$BUCKET_NAME/ro-test.txt" || true
exit 1
fi
# Remove the test object so bucket cleanup is not blocked
mc rm --insecure "rw-user/$BUCKET_NAME/rw-test.txt"
check:
($error == null): true
# The Bucket CR was applied by chainsaw and is deleted automatically during
# cleanup — no explicit teardown step needed.