48 lines
2.5 KiB
YAML
48 lines
2.5 KiB
YAML
name: Validate and deploy CoreDNS scheduling
|
|
on: [push, pull_request]
|
|
env:
|
|
KUBECTL_VERSION: v1.36.3
|
|
KUBERNETES_API: https://host.containers.internal:6443
|
|
KUBERNETES_TLS_SERVER_NAME: 192.168.0.2
|
|
jobs:
|
|
validate:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- run: bash test.sh
|
|
deploy:
|
|
if: gitea.ref == 'refs/heads/main'
|
|
needs: validate
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Install kubectl
|
|
run: |
|
|
curl -fsSL -o "${RUNNER_TEMP}/kubectl" "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl"
|
|
curl -fsSL -o "${RUNNER_TEMP}/kubectl.sha256" "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl.sha256"
|
|
printf '%s %s\n' "$(cat "${RUNNER_TEMP}/kubectl.sha256")" "${RUNNER_TEMP}/kubectl" | sha256sum -c
|
|
chmod 0700 "${RUNNER_TEMP}/kubectl"
|
|
- name: Configure Kubernetes access
|
|
env:
|
|
KUBE_CONFIG_BASE64: ${{ secrets.KUBE_CONFIG_BASE64 }}
|
|
run: |
|
|
test -n "${KUBE_CONFIG_BASE64}"
|
|
printf '%s' "${KUBE_CONFIG_BASE64}" | base64 -d > "${RUNNER_TEMP}/kubeconfig"
|
|
chmod 0600 "${RUNNER_TEMP}/kubeconfig"
|
|
export KUBECONFIG="${RUNNER_TEMP}/kubeconfig"
|
|
"${RUNNER_TEMP}/kubectl" config set-cluster cluster --server="${KUBERNETES_API}" --tls-server-name="${KUBERNETES_TLS_SERVER_NAME}"
|
|
- name: Apply and verify
|
|
run: |
|
|
export KUBECONFIG="${RUNNER_TEMP}/kubeconfig"
|
|
"${RUNNER_TEMP}/kubectl" -n kube-system patch deployment coredns --type=strategic --patch-file coredns-scheduling-patch.yaml --dry-run=server
|
|
"${RUNNER_TEMP}/kubectl" apply --server-side --force-conflicts --dry-run=server -f coredns-pdb.yaml
|
|
"${RUNNER_TEMP}/kubectl" -n kube-system patch deployment coredns --type=strategic --patch-file coredns-scheduling-patch.yaml
|
|
"${RUNNER_TEMP}/kubectl" apply --server-side --force-conflicts -f coredns-pdb.yaml
|
|
for attempt in {1..60}; do
|
|
state=$("${RUNNER_TEMP}/kubectl" -n kube-system get deployment coredns -o jsonpath='{.metadata.generation}|{.status.observedGeneration}|{.spec.replicas}|{.status.updatedReplicas}|{.status.readyReplicas}|{.status.availableReplicas}')
|
|
IFS='|' read -r generation observed desired updated ready available <<< "$state"
|
|
[[ "$generation" == "$observed" && "$desired" == "$updated" && "$desired" == "$ready" && "$desired" == "$available" ]] && exit 0
|
|
sleep 5
|
|
done
|
|
exit 1
|