Files
cozystack/hack/e2e-apps/harbor.bats
Aleksei Sviridkin 63d14e7487 test(bucket,harbor): assert BucketClaim converges to bucketReady promptly
The bucket suite waited on '{.status.bucketReady}' without an expected value;
a bare jsonpath match is satisfied by the literal "false", so the wait passed
against an unready claim. Both suites also allowed 300s/600s, long enough to
tolerate the propagation race rather than catch it, so they stayed green
whether or not the BucketClaim ever converged.

Assert bucketReady=true on a 120s bound. Convergence is now controller-driven
(the controller requeues the claim until the backend Bucket's readiness
propagates) and completes within tens of seconds; a claim frozen by the
propagation race never converges and now fails the wait fast instead of being
masked.

Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-06-24 19:52:17 +03:00

94 lines
4.5 KiB
Bash

#!/usr/bin/env bats
@test "Create Harbor" {
name='test'
release="harbor-$name"
# Clean up stale resources from previous failed runs
kubectl -n tenant-test delete harbor.apps.cozystack.io $name 2>/dev/null || true
kubectl -n tenant-test wait hr $release --timeout=60s --for=delete 2>/dev/null || true
kubectl apply -f- <<EOF
apiVersion: apps.cozystack.io/v1alpha1
kind: Harbor
metadata:
name: $name
namespace: tenant-test
spec:
host: ""
storageClass: ""
core:
resources: {}
resourcesPreset: "nano"
registry:
resources: {}
resourcesPreset: "nano"
jobservice:
resources: {}
resourcesPreset: "nano"
trivy:
enabled: false
size: 2Gi
resources: {}
resourcesPreset: "nano"
database:
size: 2Gi
replicas: 1
redis:
size: 1Gi
replicas: 1
EOF
# Wait for the operator to materialise the HelmRelease before kubectl wait
# kicks in (kubectl wait errors immediately if the object does not exist yet).
timeout 60 sh -ec "until kubectl -n tenant-test get hr $release >/dev/null 2>&1; do sleep 2; done"
kubectl -n tenant-test wait hr $release --timeout=5m --for=condition=ready
# Wait for COSI to provision the bucket. The driver creates the backend Bucket
# and grants access; the central COSI controller requeues the BucketClaim until
# the Bucket's readiness has propagated, so it converges within tens of seconds.
# A frozen claim (the propagation race this guards against) never converges, so
# the tight bound surfaces that regression instead of masking it.
timeout 60 sh -ec "until kubectl -n tenant-test get bucketclaims.objectstorage.k8s.io $release-registry >/dev/null 2>&1; do sleep 2; done"
kubectl -n tenant-test wait bucketclaims.objectstorage.k8s.io $release-registry \
--timeout=120s --for=jsonpath='{.status.bucketReady}'=true || {
echo "=== BucketClaim did not converge to bucketReady=true ==="
kubectl -n tenant-test get bucketclaims.objectstorage.k8s.io $release-registry -o yaml 2>&1 || true
echo "=== backend Buckets (cluster-scoped) ==="
kubectl get buckets.objectstorage.k8s.io -o wide 2>&1 || true
echo "=== objectstorage-controller ==="
kubectl -n cozy-objectstorage-controller get pods 2>&1 || true
false
}
timeout 60 sh -ec "until kubectl -n tenant-test get bucketaccesses.objectstorage.k8s.io $release-registry >/dev/null 2>&1; do sleep 2; done"
kubectl -n tenant-test wait bucketaccesses.objectstorage.k8s.io $release-registry \
--timeout=60s --for=jsonpath='{.status.accessGranted}'=true
kubectl -n tenant-test wait hr $release-system --timeout=600s --for=condition=ready || {
echo "=== HelmRelease status ==="
kubectl -n tenant-test get hr $release-system -o yaml 2>&1 || true
echo "=== Pods ==="
kubectl -n tenant-test get pods 2>&1 || true
echo "=== Events ==="
kubectl -n tenant-test get events --sort-by='.lastTimestamp' 2>&1 | tail -30 || true
echo "=== ExternalArtifact ==="
kubectl -n cozy-system get externalartifact cozystack-harbor-application-default-harbor-system -o yaml 2>&1 || true
echo "=== BucketClaim status ==="
kubectl -n tenant-test get bucketclaims.objectstorage.k8s.io $release-registry -o yaml 2>&1 || true
echo "=== BucketAccess status ==="
kubectl -n tenant-test get bucketaccesses.objectstorage.k8s.io $release-registry -o yaml 2>&1 || true
echo "=== BucketAccess Secret ==="
kubectl -n tenant-test get secret $release-registry-bucket -o jsonpath='{.data.BucketInfo}' 2>&1 | base64 -d 2>&1 || true
false
}
timeout 60 sh -ec "until kubectl -n tenant-test get deploy $release-core >/dev/null 2>&1; do sleep 2; done"
kubectl -n tenant-test wait deploy $release-core --timeout=120s --for=condition=available
timeout 60 sh -ec "until kubectl -n tenant-test get deploy $release-registry >/dev/null 2>&1; do sleep 2; done"
kubectl -n tenant-test wait deploy $release-registry --timeout=120s --for=condition=available
timeout 60 sh -ec "until kubectl -n tenant-test get deploy $release-portal >/dev/null 2>&1; do sleep 2; done"
kubectl -n tenant-test wait deploy $release-portal --timeout=120s --for=condition=available
kubectl -n tenant-test get secret $release-credentials -o jsonpath='{.data.admin-password}' | base64 --decode | grep -q '.'
kubectl -n tenant-test get secret $release-credentials -o jsonpath='{.data.url}' | base64 --decode | grep -q 'https://'
kubectl -n tenant-test get svc $release -o jsonpath='{.spec.ports[0].port}' | grep -q '80'
kubectl -n tenant-test delete harbor.apps.cozystack.io $name
}