#!/bin/bash set -e KO_VERSION="0.18.0" KIND_VERSION="0.30.0" ALPINE_VERSION="3.22" echo "Starting end-to-end tests for external-dns with local provider..." # Install kind echo "Installing kind..." curl -Lo ./kind https://kind.sigs.k8s.io/dl/v${KIND_VERSION}/kind-linux-amd64 chmod +x ./kind sudo mv ./kind /usr/local/bin/kind # Create kind cluster echo "Creating kind cluster..." kind create cluster # Install kubectl echo "Installing kubectl..." curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" chmod +x kubectl sudo mv kubectl /usr/local/bin/kubectl # Install ko echo "Installing ko..." curl -sSfL "https://github.com/ko-build/ko/releases/download/v${KO_VERSION}/ko_${KO_VERSION}_linux_x86_64.tar.gz" > ko.tar.gz tar xzf ko.tar.gz ko chmod +x ./ko sudo mv ko /usr/local/bin/ko # Build external-dns echo "Building external-dns..." # Use ko with --local to save the image to Docker daemon EXTERNAL_DNS_IMAGE_FULL=$(KO_DOCKER_REPO=ko.local VERSION=$(git describe --tags --always --dirty) \ ko build --tags "$(git describe --tags --always --dirty)" --bare --sbom none \ --platform=linux/amd64 --local .) echo "Built image: $EXTERNAL_DNS_IMAGE_FULL" # Extract image name and tag (strip the @sha256 digest for kind load and kustomize) EXTERNAL_DNS_IMAGE="${EXTERNAL_DNS_IMAGE_FULL%%@*}" echo "Using image reference: $EXTERNAL_DNS_IMAGE" # apply etcd deployment as provider echo "Applying etcd" kubectl apply -f e2e/provider/etcd.yaml # Build a DNS testing image with dig echo "Building DNS test image with dig..." docker build -t dns-test:v1 -f - . < "$TEMP_KUSTOMIZE_DIR/deployment-args-patch.yaml" apiVersion: apps/v1 kind: Deployment metadata: name: external-dns spec: template: spec: hostNetwork: true containers: - name: external-dns args: - --source=service - --provider=coredns - --txt-owner-id=external.dns - --policy=sync - --log-level=debug env: - name: ETCD_URLS value: http://etcd-0.etcd:2379 EOF # Update kustomization.yaml to include the patch cat < "$TEMP_KUSTOMIZE_DIR/kustomization.yaml" apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization images: - name: registry.k8s.io/external-dns/external-dns newName: ${EXTERNAL_DNS_IMAGE%%:*} newTag: ${EXTERNAL_DNS_IMAGE##*:} resources: - ./external-dns-deployment.yaml - ./external-dns-serviceaccount.yaml - ./external-dns-clusterrole.yaml - ./external-dns-clusterrolebinding.yaml patchesStrategicMerge: - ./deployment-args-patch.yaml EOF # Apply the kustomization kubectl kustomize "$TEMP_KUSTOMIZE_DIR" | kubectl apply -f - # add a wait for the deployment to be available kubectl wait --for=condition=available --timeout=60s deployment/external-dns || true kubectl describe pods -l app=external-dns kubectl describe deployment external-dns kubectl logs -l app=external-dns # Cleanup temporary directory rm -rf "$TEMP_KUSTOMIZE_DIR" # Apply kubernetes yaml with service echo "Applying Kubernetes service..." kubectl apply -f e2e # Wait for convergence echo "Waiting for convergence (90 seconds)..." sleep 90 # normal loop is 60 seconds, this is enough and should not cause flakes # Check that the records are present echo "Checking services again..." kubectl get svc -owide kubectl logs -l app=external-dns # Check that the DNS records are present using our DNS server echo "Testing DNS server functionality..." # Get the node IP where the pod is running (since we're using hostNetwork) NODE_IP=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}') echo "Node IP: $NODE_IP" # Test our DNS server with dig echo "Testing DNS server with dig..." # Create DNS test job that uses dig to query our DNS server cat </dev/null || true fi if [ ! -z "$LOCAL_PROVIDER_PID" ]; then kill $LOCAL_PROVIDER_PID 2>/dev/null || true fi kind delete cluster 2>/dev/null || true } # Set trap to cleanup on script exit trap cleanup EXIT