diff --git a/terraform/provider/.gitignore b/terraform/provider/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/terraform/provider/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/terraform/provider/README.md b/terraform/provider/README.md index de0da9e374..c165b626aa 100644 --- a/terraform/provider/README.md +++ b/terraform/provider/README.md @@ -50,7 +50,7 @@ and configuration you intend to use before relying on IAM resources. ```bash cd terraform/provider -go build -o terraform-provider-seaweedfs +go build -o bin/terraform-provider-seaweedfs . ``` ## Generate Docs @@ -68,7 +68,7 @@ Create `~/.terraformrc`: ```hcl provider_installation { dev_overrides { - "seaweedfs/seaweedfs" = "/absolute/path/to/terraform-provider-seaweedfs" + "seaweedfs/seaweedfs" = "/absolute/path/to/seaweedfs/terraform/provider/bin" } direct {} } @@ -124,8 +124,10 @@ tofu fmt -check -recursive ./scripts/minikube-smoke.sh ``` -The script requires the existing `seaweedfs-kvm-smoke` Minikube profile (or a -profile selected with `MINIKUBE_PROFILE`). It creates the namespace and Helm +The script requires a running Minikube profile, `seaweedfs-podman-smoke` by +default (set `MINIKUBE_PROFILE` to use another). It installs the chart from +`k8s/charts/seaweedfs` unless `SEAWEEDFS_CHART` points elsewhere, and forwards +the S3 port to `127.0.0.1:${SEAWEEDFS_LOCAL_PORT:-8333}`. It creates the namespace and Helm resources if needed, but does not delete the cluster, release, or Terraform resources. It applies the example automatically; use only a disposable test cluster and review the local example state before any manual cleanup. diff --git a/terraform/provider/scripts/minikube-smoke.sh b/terraform/provider/scripts/minikube-smoke.sh index 17bab74077..2ea8f6c867 100755 --- a/terraform/provider/scripts/minikube-smoke.sh +++ b/terraform/provider/scripts/minikube-smoke.sh @@ -2,10 +2,12 @@ set -euo pipefail ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) -CHART=${SEAWEEDFS_CHART:-/home/lcosta/work/k8s/seaweedfs/charts/seaweedfs-4.51.0.tgz} +CHART=${SEAWEEDFS_CHART:-$ROOT/../../k8s/charts/seaweedfs} NAMESPACE=${SEAWEEDFS_NAMESPACE:-seaweedfs} RELEASE=${SEAWEEDFS_RELEASE:-seaweedfs} PROFILE=${MINIKUBE_PROFILE:-seaweedfs-podman-smoke} +LOCAL_PORT=${SEAWEEDFS_LOCAL_PORT:-8333} +ENDPOINT="http://127.0.0.1:$LOCAL_PORT" for tool in minikube kubectl helm tofu curl python3; do command -v "$tool" >/dev/null || { @@ -14,6 +16,12 @@ for tool in minikube kubectl helm tofu curl python3; do } done +if [ ! -e "$CHART" ]; then + echo "SeaweedFS chart not found: $CHART (set SEAWEEDFS_CHART)" >&2 + exit 1 +fi +helm show chart "$CHART" >/dev/null + MINIKUBE_ROOTLESS=true minikube -p "$PROFILE" status >/dev/null 2>&1 || { echo "Minikube profile $PROFILE is unavailable. Start it with the host-compatible driver." >&2 exit 2 @@ -57,7 +65,7 @@ helm upgrade --install "$RELEASE" "$CHART" \ kubectl -n "$NAMESPACE" rollout status deployment/"$RELEASE"-all-in-one --timeout=5m PORT_FORWARD_LOG=$(mktemp) -kubectl -n "$NAMESPACE" port-forward service/"$RELEASE"-all-in-one 8333:8333 >"$PORT_FORWARD_LOG" 2>&1 & +kubectl -n "$NAMESPACE" port-forward --address 127.0.0.1 service/"$RELEASE"-all-in-one "$LOCAL_PORT":8333 >"$PORT_FORWARD_LOG" 2>&1 & PF_PID=$! cleanup() { kill "$PF_PID" 2>/dev/null || true @@ -72,19 +80,26 @@ trap 'exit 143' TERM attempt=1 while [ "$attempt" -le 30 ]; do - if curl -sS --max-time 1 -o /dev/null http://127.0.0.1:8333/ 2>/dev/null; then + if ! kill -0 "$PF_PID" 2>/dev/null; then + echo "kubectl port-forward exited:" >&2 + cat "$PORT_FORWARD_LOG" >&2 + exit 1 + fi + if grep -q "Forwarding from 127.0.0.1:$LOCAL_PORT" "$PORT_FORWARD_LOG" && + curl -sS --max-time 1 -o /dev/null "$ENDPOINT/" 2>/dev/null; then break fi attempt=$((attempt + 1)) sleep 1 done if [ "$attempt" -gt 30 ]; then - echo "SeaweedFS S3 gateway did not become ready on 127.0.0.1:8333" >&2 + echo "SeaweedFS S3 gateway did not become ready on $ENDPOINT" >&2 + cat "$PORT_FORWARD_LOG" >&2 exit 1 fi mkdir -p "$ROOT/bin" -go build -o "$ROOT/bin/terraform-provider-seaweedfs" "$ROOT/main.go" +(cd "$ROOT" && go build -o bin/terraform-provider-seaweedfs .) TMP_CONFIG=$(mktemp) cat >"$TMP_CONFIG" <