From 93be8d4c8f79c0ef446583f4615b354c52a08b77 Mon Sep 17 00:00:00 2001 From: linxin Date: Mon, 3 Jun 2024 12:10:25 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:TSG-21434=20=E7=A7=BB?= =?UTF-8?q?=E9=99=A4update-coredns=20=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../files/service_set_coredns_forwarding.conf | 2 - .../files/update-coredns-forwarding.sh | 60 ------------------- ansible/roles/k3s-install/tasks/main.yml | 10 ---- 3 files changed, 72 deletions(-) delete mode 100644 ansible/roles/k3s-install/files/service_set_coredns_forwarding.conf delete mode 100644 ansible/roles/k3s-install/files/update-coredns-forwarding.sh diff --git a/ansible/roles/k3s-install/files/service_set_coredns_forwarding.conf b/ansible/roles/k3s-install/files/service_set_coredns_forwarding.conf deleted file mode 100644 index 49a6751e..00000000 --- a/ansible/roles/k3s-install/files/service_set_coredns_forwarding.conf +++ /dev/null @@ -1,2 +0,0 @@ -[Service] -ExecStartPost=/usr/bin/timeout 30 /usr/libexec/k3s/update-coredns-forwarding.sh diff --git a/ansible/roles/k3s-install/files/update-coredns-forwarding.sh b/ansible/roles/k3s-install/files/update-coredns-forwarding.sh deleted file mode 100644 index 36a448b5..00000000 --- a/ansible/roles/k3s-install/files/update-coredns-forwarding.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash -set -eufo pipefail - -# The absolute path to the containerd socket. -readonly CONTAINERD_SOCK='/run/k3s/containerd/containerd.sock' - -# The absolute path to the CoreDNS manifest file. -readonly COREDNS_YAML='/var/lib/rancher/k3s/server/manifests/coredns-custom.yaml' - -get_file_mtime() { - # Get file "$1" mtime in Epoch seconds. - stat -c '%Y' "$1" -} - -wait_for_file() { - # Wait for file "$1" to exist. - until [[ -e "$1" ]]; do - sleep 1 - done -} - -get_nameservers() { - # Get a list of DNS nameservers defined in /etc/resolv.conf. - if [[ -e /etc/resolv.conf ]]; then - awk '($1=="nameserver"){print $2}' /etc/resolv.conf - fi -} - -restart_coredns_deployment() { - # Restart the CoreDNS deployment. - kubectl --kubeconfig /etc/rancher/k3s/k3s.yaml \ - apply -f $COREDNS_YAML - kubectl --kubeconfig /etc/rancher/k3s/k3s.yaml --namespace kube-system \ - rollout restart deployment coredns -} - -update_coredns_forwarding() { - # Comment out "forward" line in the CoreDNS manifest (i.e., Corefile) if - # there are no DNS nameservers configured on the host. If the manifest - # was updated, restart CoreDNS. - local nameservers - mapfile -t nameservers < <(get_nameservers) - if [[ "${#nameservers[@]}" -eq 0 ]]; then - echo 'Disabling CoreDNS host forwarding ...' - sed -i 's/\(^\s\+\)forward \. \/etc\/resolv\.conf/\1#forward \. \/etc\/resolv\.conf/' "$COREDNS_YAML" - restart_coredns_deployment - else - echo 'Enabling CoreDNS host forwarding ...' - sed -i 's/\(^\s\+\)#forward \. \/etc\/resolv\.conf/\1forward \. \/etc\/resolv\.conf/' "$COREDNS_YAML" - restart_coredns_deployment - fi -} - -main() { - wait_for_file "$CONTAINERD_SOCK" - wait_for_file "$COREDNS_YAML" - update_coredns_forwarding -} - -main \ No newline at end of file diff --git a/ansible/roles/k3s-install/tasks/main.yml b/ansible/roles/k3s-install/tasks/main.yml index 82c69b84..34663dc5 100644 --- a/ansible/roles/k3s-install/tasks/main.yml +++ b/ansible/roles/k3s-install/tasks/main.yml @@ -93,11 +93,6 @@ src: "{{ role_path }}/files/service_set_RuntimeMaxSec.conf" dest: /usr/lib/systemd/system/k3s.service.d/ -- name: "copy update-coredns-forwarding file to dest" - copy: - src: "{{ role_path }}/files/service_set_coredns_forwarding.conf" - dest: /usr/lib/systemd/system/k3s.service.d/ - - name: "Create /usr/libexec/k3s directory if it does not exist" file: path: "{{ item }}" @@ -106,11 +101,6 @@ with_items: - /usr/libexec/k3s -- name: "copy update-coredns-forwarding to dest" - copy: - src: "{{ role_path }}/files/update-coredns-forwarding.sh" - dest: /usr/libexec/k3s/update-coredns-forwarding.sh - mode: 0755 - name: "copy k3s-orphaned-pods-dir-clean.service to destination" copy: