|
| 1 | +name: "Set up KinD" |
| 2 | +description: "Step to start and configure KinD cluster" |
| 3 | + |
| 4 | +inputs: |
| 5 | + node-hostname: |
| 6 | + description: "Hostname of the main kind node" |
| 7 | + required: false |
| 8 | + default: kind |
| 9 | + cluster-name: |
| 10 | + description: "Name of the KinD cluster" |
| 11 | + required: false |
| 12 | + default: cluster |
| 13 | + worker-nodes: |
| 14 | + description: "Number of worker nodes" |
| 15 | + required: false |
| 16 | + default: 0 |
| 17 | + label-prefix: |
| 18 | + description: "Prefix to add to worker node labels" |
| 19 | + required: false |
| 20 | + default: worker |
| 21 | + |
| 22 | +runs: |
| 23 | + using: "composite" |
| 24 | + steps: |
| 25 | + - name: Init directories |
| 26 | + shell: bash |
| 27 | + run: | |
| 28 | + TEMP_DIR="$(pwd)/tmp" |
| 29 | + mkdir -p "${TEMP_DIR}" |
| 30 | + echo "TEMP_DIR=${TEMP_DIR}" >> $GITHUB_ENV |
| 31 | +
|
| 32 | + mkdir -p "$(pwd)/bin" |
| 33 | + echo "$(pwd)/bin" >> $GITHUB_PATH |
| 34 | +
|
| 35 | + - name: Container image registry |
| 36 | + shell: bash |
| 37 | + run: | |
| 38 | + podman run -d -p 5000:5000 --name registry registry:2.8.1 |
| 39 | +
|
| 40 | + export NODE_IMAGE="kindest/node:v1.26.0@sha256:691e24bd2417609db7e589e1a479b902d2e209892a10ce375fab60a8407c7352" |
| 41 | +
|
| 42 | + export REGISTRY_ADDRESS=$(hostname -i):5000 |
| 43 | + echo "REGISTRY_ADDRESS=${REGISTRY_ADDRESS}" >> $GITHUB_ENV |
| 44 | + echo "Container image registry started at ${REGISTRY_ADDRESS}" |
| 45 | +
|
| 46 | + KIND_CONFIG_FILE=${{ env.TEMP_DIR }}/kind.yaml |
| 47 | +
|
| 48 | + WORKER_NODES=${{ inputs.worker-nodes }} |
| 49 | + LABEL_PREFIX=${{ inputs.label-prefix }} |
| 50 | +
|
| 51 | + if [ "$WORKER_NODES" -gt 0 ]; then |
| 52 | + for i in $(seq 1 $WORKER_NODES); do |
| 53 | + sed -i "/^nodes:/a \ \ - role: worker\n image: ${NODE_IMAGE}\n labels:\n ${LABEL_PREFIX}-${i}: true\n extraMounts:\n - hostPath: /dev/null\n containerPath: /var/run/nvidia-container-devices/all" ${GITHUB_ACTION_PATH}/resources/kind.yaml |
| 54 | + done |
| 55 | + fi |
| 56 | +
|
| 57 | + echo "KIND_CONFIG_FILE=${KIND_CONFIG_FILE}" >> $GITHUB_ENV |
| 58 | + envsubst < ${GITHUB_ACTION_PATH}/resources/kind.yaml > ${KIND_CONFIG_FILE} |
| 59 | +
|
| 60 | + sudo --preserve-env=REGISTRY_ADDRESS sh -c 'cat > /etc/containers/registries.conf.d/local.conf <<EOF |
| 61 | + [[registry]] |
| 62 | + prefix = "$REGISTRY_ADDRESS" |
| 63 | + insecure = true |
| 64 | + location = "$REGISTRY_ADDRESS" |
| 65 | + EOF' |
| 66 | +
|
| 67 | + - name: Setup KinD cluster |
| 68 | + |
| 69 | + with: |
| 70 | + cluster_name: ${{ inputs.cluster-name }} |
| 71 | + version: v0.17.0 |
| 72 | + config: ${{ env.KIND_CONFIG_FILE }} |
| 73 | + |
| 74 | + - name: Print cluster info |
| 75 | + shell: bash |
| 76 | + run: | |
| 77 | + echo "KinD cluster:" |
| 78 | + kubectl cluster-info |
| 79 | + kubectl describe nodes |
| 80 | +
|
| 81 | + - name: Install Ingress controller |
| 82 | + shell: bash |
| 83 | + run: | |
| 84 | + VERSION=controller-v1.9.6 |
| 85 | + echo "Deploying Ingress controller into KinD cluster" |
| 86 | + curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/"${VERSION}"/deploy/static/provider/kind/deploy.yaml | sed "s/--publish-status-address=localhost/--report-node-internal-ip-address\\n - --status-update-interval=10/g" | kubectl apply -f - |
| 87 | + kubectl annotate ingressclass nginx "ingressclass.kubernetes.io/is-default-class=true" |
| 88 | + # Turn on SSL Passthrough |
| 89 | + kubectl patch deploy --type json --patch '[{"op":"add","path": "/spec/template/spec/containers/0/args/-","value":"--enable-ssl-passthrough"}]' ingress-nginx-controller -n ingress-nginx |
| 90 | +
|
| 91 | + kubectl -n ingress-nginx wait --timeout=300s --for=condition=Available deployments --all |
| 92 | +
|
| 93 | + - name: Setup Dnsmasq to resolve hostnames with domain name ${{ inputs.node-hostname }} |
| 94 | + shell: bash |
| 95 | + run: | |
| 96 | + # Based on https://sixfeetup.com/blog/local-development-with-wildcard-dns-on-linux |
| 97 | + sudo apt-get -y install dnsmasq |
| 98 | +
|
| 99 | + sudo sed -i -E "s/#DNS=/DNS=127.0.0.2/" /etc/systemd/resolved.conf |
| 100 | + sudo sed -i -E "s/#Domains=/Domains=~${{ inputs.node-hostname }}/" /etc/systemd/resolved.conf |
| 101 | + sudo systemctl restart systemd-resolved |
| 102 | +
|
| 103 | + sudo sed -i -E "s/#IGNORE_RESOLVCONF=yes/IGNORE_RESOLVCONF=yes/" /etc/default/dnsmasq |
| 104 | + sudo sed -i -E "s/#listen-address=/listen-address=127.0.0.2/" /etc/dnsmasq.conf |
| 105 | + sudo sed -i -E "s/#bind-interfaces/bind-interfaces/" /etc/dnsmasq.conf |
| 106 | + sudo sed -i -E "s|#(address=).*|\1/${{ inputs.node-hostname }}/127.0.0.1|" /etc/dnsmasq.conf |
| 107 | + sudo systemctl restart dnsmasq |
| 108 | + systemctl status dnsmasq |
| 109 | +
|
| 110 | + - name: Set env variables for tests to properly leverage KinD cluster |
| 111 | + shell: bash |
| 112 | + run: | |
| 113 | + echo "CLUSTER_TYPE=KIND" >> $GITHUB_ENV |
| 114 | + echo "CLUSTER_HOSTNAME=${{ inputs.node-hostname }}" >> $GITHUB_ENV |
0 commit comments