-
Notifications
You must be signed in to change notification settings - Fork 0
Fix/end to end tests #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a651a02
5e7d2ad
d714c25
18774f0
ed3513a
7d978cf
3d841e3
458a8d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -40,13 +40,24 @@ eval $(make --no-print-directory -C ${projectdir} build.vars) | |||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # ------------------------------ | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Provide safe defaults for variables that may not be set by build.vars | ||||||||||||||||||||||||||||||||||||||||
| : "${KIND_VERSION:=unknown}" | ||||||||||||||||||||||||||||||||||||||||
| : "${KIND_NODE_IMAGE_TAG:=v1.23.4}" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| SAFEHOSTARCH="${SAFEHOSTARCH:-amd64}" | ||||||||||||||||||||||||||||||||||||||||
| CONTROLLER_IMAGE="${BUILD_REGISTRY}/${PROJECT_NAME}-${SAFEHOSTARCH}" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| version_tag="$(cat ${projectdir}/_output/version)" | ||||||||||||||||||||||||||||||||||||||||
| # tag as latest version to load into kind cluster | ||||||||||||||||||||||||||||||||||||||||
| K8S_CLUSTER="${K8S_CLUSTER:-${BUILD_REGISTRY}-inttests}" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Optional: set USE_OCI=true to use an in-cluster OCI registry for provider package delivery | ||||||||||||||||||||||||||||||||||||||||
| # Modes: | ||||||||||||||||||||||||||||||||||||||||
| # - USE_OCI=true => Push .xpkg into an in-cluster registry and install Provider from OCI (no host cache, no PVC) | ||||||||||||||||||||||||||||||||||||||||
| # - USE_OCI=false => Extract .xpkg to .gz on host and mount as cache for Crossplane (offline local cache) | ||||||||||||||||||||||||||||||||||||||||
| USE_OCI=${USE_OCI:-true} | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| PACKAGE_NAME="provider-sql" | ||||||||||||||||||||||||||||||||||||||||
| MARIADB_ROOT_PW=$(openssl rand -base64 32) | ||||||||||||||||||||||||||||||||||||||||
| MARIADB_TEST_PW=$(openssl rand -base64 32) | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -56,6 +67,12 @@ if [ "$skipcleanup" != true ]; then | |||||||||||||||||||||||||||||||||||||||
| function cleanup { | ||||||||||||||||||||||||||||||||||||||||
| echo_step "Cleaning up..." | ||||||||||||||||||||||||||||||||||||||||
| export KUBECONFIG= | ||||||||||||||||||||||||||||||||||||||||
| # stop port-forward if running | ||||||||||||||||||||||||||||||||||||||||
| if [ -f "${projectdir}/.work/registry-pf.pid" ]; then | ||||||||||||||||||||||||||||||||||||||||
| pfpid=$(cat "${projectdir}/.work/registry-pf.pid" || true) | ||||||||||||||||||||||||||||||||||||||||
| if [ -n "$pfpid" ]; then kill "$pfpid" 2>/dev/null || true; fi | ||||||||||||||||||||||||||||||||||||||||
| rm -f "${projectdir}/.work/registry-pf.pid" | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
| cleanup_cluster | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -77,18 +94,33 @@ integration_tests_end() { | |||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| setup_cluster() { | ||||||||||||||||||||||||||||||||||||||||
| echo_step "setting up local package cache" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if [ "${USE_OCI}" = true ]; then | ||||||||||||||||||||||||||||||||||||||||
| echo_sub_step "Mode: OCI (no host cache, no PVC)" | ||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||
| echo_sub_step "Mode: Local cache (.gz mounted via PV/PVC)" | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
| local cache_path="${projectdir}/.work/inttest-package-cache" | ||||||||||||||||||||||||||||||||||||||||
| mkdir -p "${cache_path}" | ||||||||||||||||||||||||||||||||||||||||
| echo "created cache dir at ${cache_path}" | ||||||||||||||||||||||||||||||||||||||||
| "${UP}" alpha xpkg xp-extract --from-xpkg "${OUTPUT_DIR}"/xpkg/linux_"${SAFEHOSTARCH}"/"${PACKAGE_NAME}"-"${VERSION}".xpkg -o "${cache_path}/${PACKAGE_NAME}.gz" | ||||||||||||||||||||||||||||||||||||||||
| chmod 644 "${cache_path}/${PACKAGE_NAME}.gz" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| local node_image="kindest/node:${KIND_NODE_IMAGE_TAG}" | ||||||||||||||||||||||||||||||||||||||||
| echo_step "creating k8s cluster using kind ${KIND_VERSION} and node image ${node_image}" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| local config="$( cat <<EOF | ||||||||||||||||||||||||||||||||||||||||
| if [ "${USE_OCI}" = true ]; then | ||||||||||||||||||||||||||||||||||||||||
| echo_step "creating k8s cluster (no cache mount) using kind ${KIND_VERSION} and ${node_image}" | ||||||||||||||||||||||||||||||||||||||||
| local config="$( cat <<EOF | ||||||||||||||||||||||||||||||||||||||||
| kind: Cluster | ||||||||||||||||||||||||||||||||||||||||
| apiVersion: kind.x-k8s.io/v1alpha4 | ||||||||||||||||||||||||||||||||||||||||
| nodes: | ||||||||||||||||||||||||||||||||||||||||
| - role: control-plane | ||||||||||||||||||||||||||||||||||||||||
| EOF | ||||||||||||||||||||||||||||||||||||||||
| )" | ||||||||||||||||||||||||||||||||||||||||
| echo "${config}" | "${KIND}" create cluster --name="${K8S_CLUSTER}" --wait=5m --image="${node_image}" --config=- | ||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||
| echo_step "setting up local package cache (.xpkg -> .gz)" | ||||||||||||||||||||||||||||||||||||||||
| mkdir -p "${cache_path}" | ||||||||||||||||||||||||||||||||||||||||
| echo "created cache dir at ${cache_path}" | ||||||||||||||||||||||||||||||||||||||||
| "${UP}" alpha xpkg xp-extract --from-xpkg "${OUTPUT_DIR}"/xpkg/linux_"${SAFEHOSTARCH}"/"${PACKAGE_NAME}"-"${VERSION}".xpkg -o "${cache_path}/${PACKAGE_NAME}-${VERSION}.gz" | ||||||||||||||||||||||||||||||||||||||||
| chmod 644 "${cache_path}/${PACKAGE_NAME}-${VERSION}.gz" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| echo_step "creating k8s cluster (with cache mount) using kind ${KIND_VERSION} and ${node_image}" | ||||||||||||||||||||||||||||||||||||||||
| local config="$( cat <<EOF | ||||||||||||||||||||||||||||||||||||||||
| kind: Cluster | ||||||||||||||||||||||||||||||||||||||||
| apiVersion: kind.x-k8s.io/v1alpha4 | ||||||||||||||||||||||||||||||||||||||||
| nodes: | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -97,21 +129,21 @@ nodes: | |||||||||||||||||||||||||||||||||||||||
| - hostPath: "${cache_path}/" | ||||||||||||||||||||||||||||||||||||||||
| containerPath: /cache | ||||||||||||||||||||||||||||||||||||||||
| EOF | ||||||||||||||||||||||||||||||||||||||||
| )" | ||||||||||||||||||||||||||||||||||||||||
| echo "${config}" | "${KIND}" create cluster --name="${K8S_CLUSTER}" --wait=5m --image="${node_image}" --config=- | ||||||||||||||||||||||||||||||||||||||||
| )" | ||||||||||||||||||||||||||||||||||||||||
| echo "${config}" | "${KIND}" create cluster --name="${K8S_CLUSTER}" --wait=5m --image="${node_image}" --config=- | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| echo_step "tag controller image and load it into kind cluster" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| docker tag "${CONTROLLER_IMAGE}" "xpkg.crossplane.io/${PACKAGE_NAME}:latest" | ||||||||||||||||||||||||||||||||||||||||
| "${KIND}" load docker-image "xpkg.crossplane.io/${PACKAGE_NAME}:latest" --name="${K8S_CLUSTER}" | ||||||||||||||||||||||||||||||||||||||||
| echo_step "load controller runtime image into kind cluster" | ||||||||||||||||||||||||||||||||||||||||
| "${KIND}" load docker-image "${CONTROLLER_IMAGE}" --name="${K8S_CLUSTER}" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| echo_step "create crossplane-system namespace" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| "${KUBECTL}" create ns crossplane-system | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| echo_step "create persistent volume for mounting package-cache" | ||||||||||||||||||||||||||||||||||||||||
| if [ "${USE_OCI}" != true ]; then | ||||||||||||||||||||||||||||||||||||||||
| echo_step "create persistent volume for mounting package-cache" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| local pv_yaml="$( cat <<EOF | ||||||||||||||||||||||||||||||||||||||||
| local pv_yaml="$( cat <<EOF | ||||||||||||||||||||||||||||||||||||||||
| apiVersion: v1 | ||||||||||||||||||||||||||||||||||||||||
| kind: PersistentVolume | ||||||||||||||||||||||||||||||||||||||||
| metadata: | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -127,13 +159,13 @@ spec: | |||||||||||||||||||||||||||||||||||||||
| hostPath: | ||||||||||||||||||||||||||||||||||||||||
| path: "/cache" | ||||||||||||||||||||||||||||||||||||||||
| EOF | ||||||||||||||||||||||||||||||||||||||||
| )" | ||||||||||||||||||||||||||||||||||||||||
| )" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| echo "${pv_yaml}" | "${KUBECTL}" create -f - | ||||||||||||||||||||||||||||||||||||||||
| echo "${pv_yaml}" | "${KUBECTL}" create -f - | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| echo_step "create persistent volume claim for mounting package-cache" | ||||||||||||||||||||||||||||||||||||||||
| echo_step "create persistent volume claim for mounting package-cache" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| local pvc_yaml="$( cat <<EOF | ||||||||||||||||||||||||||||||||||||||||
| local pvc_yaml="$( cat <<EOF | ||||||||||||||||||||||||||||||||||||||||
| apiVersion: v1 | ||||||||||||||||||||||||||||||||||||||||
| kind: PersistentVolumeClaim | ||||||||||||||||||||||||||||||||||||||||
| metadata: | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -148,9 +180,10 @@ spec: | |||||||||||||||||||||||||||||||||||||||
| requests: | ||||||||||||||||||||||||||||||||||||||||
| storage: 1Mi | ||||||||||||||||||||||||||||||||||||||||
| EOF | ||||||||||||||||||||||||||||||||||||||||
| )" | ||||||||||||||||||||||||||||||||||||||||
| )" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| echo "${pvc_yaml}" | "${KUBECTL}" create -f - | ||||||||||||||||||||||||||||||||||||||||
| echo "${pvc_yaml}" | "${KUBECTL}" create -f - | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| cleanup_cluster() { | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -164,15 +197,84 @@ setup_crossplane() { | |||||||||||||||||||||||||||||||||||||||
| local chart_version="$("${HELM}" search repo crossplane-stable/crossplane | awk 'FNR == 2 {print $2}')" | ||||||||||||||||||||||||||||||||||||||||
| echo_info "using crossplane version ${chart_version}" | ||||||||||||||||||||||||||||||||||||||||
| echo | ||||||||||||||||||||||||||||||||||||||||
| # we replace empty dir with our PVC so that the /cache dir in the kind node | ||||||||||||||||||||||||||||||||||||||||
| # container is exposed to the crossplane pod | ||||||||||||||||||||||||||||||||||||||||
| "${HELM}" install crossplane --namespace crossplane-system crossplane-stable/crossplane --version ${chart_version} --wait --set packageCache.pvc=package-cache | ||||||||||||||||||||||||||||||||||||||||
| if [ "${USE_OCI}" = true ]; then | ||||||||||||||||||||||||||||||||||||||||
| echo_sub_step "Crossplane cache: emptyDir (OCI mode)" | ||||||||||||||||||||||||||||||||||||||||
| "${HELM}" install crossplane --namespace crossplane-system crossplane-stable/crossplane --version ${chart_version} --wait | ||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||
| echo_sub_step "Crossplane cache: PVC 'package-cache' (local .gz mode)" | ||||||||||||||||||||||||||||||||||||||||
| "${HELM}" install crossplane --namespace crossplane-system crossplane-stable/crossplane --version ${chart_version} --wait --set packageCache.pvc=package-cache | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| setup_local_registry() { | ||||||||||||||||||||||||||||||||||||||||
| [ "${USE_OCI}" = true ] || return 0 | ||||||||||||||||||||||||||||||||||||||||
| echo_step "deploy in-cluster OCI registry" | ||||||||||||||||||||||||||||||||||||||||
| local reg_yaml="$( cat <<EOF | ||||||||||||||||||||||||||||||||||||||||
| apiVersion: apps/v1 | ||||||||||||||||||||||||||||||||||||||||
| kind: Deployment | ||||||||||||||||||||||||||||||||||||||||
| metadata: | ||||||||||||||||||||||||||||||||||||||||
| name: registry | ||||||||||||||||||||||||||||||||||||||||
| namespace: crossplane-system | ||||||||||||||||||||||||||||||||||||||||
| spec: | ||||||||||||||||||||||||||||||||||||||||
| replicas: 1 | ||||||||||||||||||||||||||||||||||||||||
| selector: | ||||||||||||||||||||||||||||||||||||||||
| matchLabels: | ||||||||||||||||||||||||||||||||||||||||
| app: registry | ||||||||||||||||||||||||||||||||||||||||
| template: | ||||||||||||||||||||||||||||||||||||||||
| metadata: | ||||||||||||||||||||||||||||||||||||||||
| labels: | ||||||||||||||||||||||||||||||||||||||||
| app: registry | ||||||||||||||||||||||||||||||||||||||||
| spec: | ||||||||||||||||||||||||||||||||||||||||
| containers: | ||||||||||||||||||||||||||||||||||||||||
| - name: registry | ||||||||||||||||||||||||||||||||||||||||
| image: registry:3.0.0 | ||||||||||||||||||||||||||||||||||||||||
| ports: | ||||||||||||||||||||||||||||||||||||||||
| - containerPort: 5000 | ||||||||||||||||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||||||||||||||||
| - name: REGISTRY_STORAGE_DELETE_ENABLED | ||||||||||||||||||||||||||||||||||||||||
| value: "true" | ||||||||||||||||||||||||||||||||||||||||
Damien-DAGORN marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||||||||||||
| apiVersion: v1 | ||||||||||||||||||||||||||||||||||||||||
| kind: Service | ||||||||||||||||||||||||||||||||||||||||
| metadata: | ||||||||||||||||||||||||||||||||||||||||
| name: registry | ||||||||||||||||||||||||||||||||||||||||
| namespace: crossplane-system | ||||||||||||||||||||||||||||||||||||||||
| spec: | ||||||||||||||||||||||||||||||||||||||||
| selector: | ||||||||||||||||||||||||||||||||||||||||
| app: registry | ||||||||||||||||||||||||||||||||||||||||
| ports: | ||||||||||||||||||||||||||||||||||||||||
| - name: http | ||||||||||||||||||||||||||||||||||||||||
| protocol: TCP | ||||||||||||||||||||||||||||||||||||||||
| port: 5000 | ||||||||||||||||||||||||||||||||||||||||
| targetPort: 5000 | ||||||||||||||||||||||||||||||||||||||||
| EOF | ||||||||||||||||||||||||||||||||||||||||
| )" | ||||||||||||||||||||||||||||||||||||||||
| echo "${reg_yaml}" | "${KUBECTL}" apply -f - | ||||||||||||||||||||||||||||||||||||||||
| "${KUBECTL}" -n crossplane-system rollout status deploy/registry --timeout=120s | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| echo_step "port-forward registry for pushing xpkg" | ||||||||||||||||||||||||||||||||||||||||
| mkdir -p "${projectdir}/.work" | ||||||||||||||||||||||||||||||||||||||||
| ( kubectl -n crossplane-system port-forward svc/registry 5000:5000 >/dev/null 2>&1 & echo $! >"${projectdir}/.work/registry-pf.pid" ) | ||||||||||||||||||||||||||||||||||||||||
| for i in {1..20}; do nc -z localhost 5000 && break || sleep 0.5; done | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
| } | |
| ( kubectl -n crossplane-system port-forward svc/registry 5000:5000 >"${projectdir}/.work/registry-pf.log" 2>&1 & echo $! >"${projectdir}/.work/registry-pf.pid" ) |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nc readiness check loop has no error handling or diagnostic output when it fails. If the port never becomes available after 20 iterations (10 seconds), the script continues silently without any indication that the registry may not be ready. This could lead to subsequent push failures that are harder to diagnose.
| local registry_ready=false | |
| for i in {1..20}; do | |
| if nc -z localhost 5000; then | |
| registry_ready=true | |
| break | |
| fi | |
| sleep 0.5 | |
| done | |
| if [ "${registry_ready}" != true ]; then | |
| printf "\n${RED}Failed to connect to local registry on port 5000 after waiting 10 seconds.${NOC}\n" >&2 | |
| return 1 | |
| fi |
Damien-DAGORN marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handling after kubectl wait fails attempts to get logs from a provider pod, but the variable POD_NAME assignment doesn't quote the command substitution properly for the subsequent check. If no pod is found, POD_NAME will be an empty string, and the '-n' test will correctly handle it. However, if multiple pods match, only the first will be captured. Consider adding error handling for the case where multiple pods exist or no pods are found before the timeout.
| echo "Logs for $POD_NAME:" | |
| "${KUBECTL}" logs -n crossplane-system "$POD_NAME" -c package-runtime | |
| else | |
| echo "No pod found for provider ${PACKAGE_NAME}" | |
| fi | |
| exit 1 | |
| PODS_OUTPUT="$("${KUBECTL}" get pods -n crossplane-system -l "pkg.crossplane.io/provider=${PACKAGE_NAME}" -o name || true)" | |
| if [ -z "$PODS_OUTPUT" ]; then | |
| echo "No pod found for provider ${PACKAGE_NAME}" | |
| else | |
| POD_COUNT="$(printf "%s\n" "$PODS_OUTPUT" | sed '/^[[:space:]]*$/d' | wc -l | tr -d '[:space:]')" | |
| if [ "$POD_COUNT" -gt 1 ]; then | |
| echo_error "Multiple pods found for provider ${PACKAGE_NAME}:" | |
| printf "%s\n" "$PODS_OUTPUT" | |
| else | |
| POD_NAME="$PODS_OUTPUT" | |
| echo "Logs for $POD_NAME:" | |
| "${KUBECTL}" logs -n crossplane-system "$POD_NAME" -c package-runtime | |
| fi |
Uh oh!
There was an error while loading. Please reload this page.