From 52e8521781d8d0b4df6c73137a25476b072cfd57 Mon Sep 17 00:00:00 2001 From: sanjujunnuthula Date: Wed, 29 Jul 2026 13:37:13 +0000 Subject: [PATCH 1/7] chore: autoupdating CoreDNS host config while installing pre-requisites Signed-off-by: sanjujunnuthula --- scripts/device-agent.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/device-agent.sh b/scripts/device-agent.sh index 31f4621e..b54c94f8 100644 --- a/scripts/device-agent.sh +++ b/scripts/device-agent.sh @@ -115,6 +115,8 @@ source "${SCRIPT_DIR}/modules/harbor.sh" source "${SCRIPT_DIR}/modules/certificates.sh" source "${SCRIPT_DIR}/modules/agent.sh" source "${SCRIPT_DIR}/modules/observability.sh" +source "${SCRIPT_DIR}/modules/dns-host-config.sh" + export GOINSECURE='github.com/margo/*' @@ -178,6 +180,8 @@ install_prerequisites() { if [ "$DEVICE_TYPE" = "k3s" ]; then setup_k3s configure_harbor_trust_for_k3s + sleep 5 + configure_coredns_hosts fi echo 'prerequisites installation completed.' From fe33ecc7c613a7f37947b28987769b19dcfeaaba Mon Sep 17 00:00:00 2001 From: sanjujunnuthula Date: Wed, 29 Jul 2026 14:06:42 +0000 Subject: [PATCH 2/7] chore: added dns-host-config file Signed-off-by: sanjujunnuthula --- scripts/modules/dns-host-config.sh | 154 +++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100755 scripts/modules/dns-host-config.sh diff --git a/scripts/modules/dns-host-config.sh b/scripts/modules/dns-host-config.sh new file mode 100755 index 00000000..cf807037 --- /dev/null +++ b/scripts/modules/dns-host-config.sh @@ -0,0 +1,154 @@ +#!/bin/bash + +#------------------------------------------------------------------------------ +# Returns the IPv4 address of the specified hostname from /etc/hosts. +#------------------------------------------------------------------------------ +get_ip_from_hosts() { + local hostname="$1" + local hosts_file="/etc/hosts" + local ip + + if [[ ! -r "$hosts_file" ]]; then + echo "[ERROR] Unable to read ${hosts_file}." >&2 + return 1 + fi + + ip=$( + awk -v host="$hostname" ' + /^[[:space:]]*#/ { next } + NF >= 2 && $2 == host { + print $1 + exit + } + ' "$hosts_file" + ) + + if [[ -z "$ip" ]]; then + echo "[ERROR] Host '${hostname}' not found in ${hosts_file}." >&2 + return 1 + fi + + if [[ ! "$ip" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then + echo "[ERROR] Invalid IPv4 address '${ip}' for '${hostname}'." >&2 + return 1 + fi + + printf '%s\n' "$ip" +} + +#------------------------------------------------------------------------------ +# Adds or updates NodeHosts entries in the CoreDNS ConfigMap. +#------------------------------------------------------------------------------ +configure_coredns_hosts() { + set -euo pipefail + + local namespace="kube-system" + local configmap="coredns" + + local harbor_host="harbor.machine" + local symphony_host="symphony.machine" + + local harbor_ip + local symphony_ip + + local nodehosts + local updated + + echo "[INFO] Validating dependencies..." + + for cmd in kubectl jq awk sed; do + if ! command -v "$cmd" >/dev/null 2>&1; then + echo "[ERROR] Required command '$cmd' is not installed." >&2 + return 1 + fi + done + + echo "[INFO] Reading IP addresses from /etc/hosts..." + + harbor_ip=$(get_ip_from_hosts "$harbor_host") + symphony_ip=$(get_ip_from_hosts "$symphony_host") + + echo "[INFO] Verifying CoreDNS ConfigMap..." + + if ! kubectl -n "$namespace" get configmap "$configmap" >/dev/null 2>&1; then + echo "[ERROR] ConfigMap '${configmap}' not found in namespace '${namespace}'." >&2 + return 1 + fi + + nodehosts=$( + kubectl -n "$namespace" get configmap "$configmap" \ + -o jsonpath='{.data.NodeHosts}' 2>/dev/null || true + ) + + updated="$nodehosts" + + add_or_update_host() { + local ip="$1" + local host="$2" + + if awk -v host="$host" ' + /^[[:space:]]*#/ { next } + $2 == host { found=1 } + END { exit !found } + ' <<<"$updated"; then + + updated=$( + awk -v ip="$ip" -v host="$host" ' + /^[[:space:]]*#/ { + print + next + } + + $2 == host { + print ip " " host + next + } + + { + print + } + ' <<<"$updated" + ) + + else + if [[ -n "$updated" ]]; then + updated+=$'\n' + fi + updated+="${ip} ${host}" + fi + } + + add_or_update_host "$harbor_ip" "$harbor_host" + add_or_update_host "$symphony_ip" "$symphony_host" + + updated=$(sed '/^[[:space:]]*$/d' <<<"$updated") + + if [[ "$updated" == "$nodehosts" ]]; then + echo "[INFO] CoreDNS NodeHosts already up to date." + return 0 + fi + + echo "[INFO] Updating CoreDNS ConfigMap..." + + kubectl -n "$namespace" patch configmap "$configmap" \ + --type merge \ + --patch "$(cat < Date: Thu, 30 Jul 2026 11:58:53 +0000 Subject: [PATCH 3/7] chore: updated dns-host-config file Signed-off-by: sanjujunnuthula --- .github/workflows/sandbox-sanity-test.yml | 110 +++++++++++----------- scripts/device-agent.sh | 1 + scripts/modules/dns-host-config.sh | 77 +++++++-------- 3 files changed, 95 insertions(+), 93 deletions(-) diff --git a/.github/workflows/sandbox-sanity-test.yml b/.github/workflows/sandbox-sanity-test.yml index 3cc26fac..2da6f9a1 100644 --- a/.github/workflows/sandbox-sanity-test.yml +++ b/.github/workflows/sandbox-sanity-test.yml @@ -296,61 +296,61 @@ jobs: sudo -E bash ./device-agent.sh k3s create-rsa-certs sudo -E bash ./device-agent.sh k3s create-ecdsa-certs - - name: Configure CoreDNS for k3s - run: | - RUNNER_IP=${RUNNER_IP} - echo "📡 Configuring CoreDNS with custom DNS entries..." - - # Retry logic for ConfigMap update - for RETRY in {1..3}; do - echo "Attempt $RETRY to configure CoreDNS..." - - # Get the full ConfigMap YAML - sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml \ - kubectl -n kube-system get configmap coredns -o yaml > config.yaml - - # Update the Corefile section - awk -v ip="$RUNNER_IP" ' - /NodeHosts: \|/ { - print - getline - print " " ip " harbor.machine" - print " " ip " symphony.machine" - print - next - } - { print } - ' config.yaml > config-new.yaml - - # Verify the change was made - if grep -q "harbor.machine" config-new.yaml && grep -q "symphony.machine" config-new.yaml; then - echo "✅ DNS entries added to ConfigMap" - - # Apply the updated ConfigMap - sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml kubectl apply -f config-new.yaml - - # Restart CoreDNS - sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml kubectl rollout restart deployment coredns -n kube-system - sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml kubectl rollout status deployment/coredns -n kube-system --timeout=60s - - # Wait longer for DNS propagation - echo "⏳ Waiting for DNS propagation..." - sleep 15 - - echo "✅ CoreDNS configured successfully" - break - else - echo "⚠️ DNS entries not found in updated ConfigMap, retrying..." - sleep 5 - fi - - if [ $RETRY -eq 3 ]; then - echo "❌ Failed to configure CoreDNS after 3 attempts" - echo "ConfigMap contents:" - cat config-new.yaml - exit 1 - fi - done + # - name: Configure CoreDNS for k3s + # run: | + # RUNNER_IP=${RUNNER_IP} + # echo "📡 Configuring CoreDNS with custom DNS entries..." + + # # Retry logic for ConfigMap update + # for RETRY in {1..3}; do + # echo "Attempt $RETRY to configure CoreDNS..." + + # # Get the full ConfigMap YAML + # sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml \ + # kubectl -n kube-system get configmap coredns -o yaml > config.yaml + + # # Update the Corefile section + # awk -v ip="$RUNNER_IP" ' + # /NodeHosts: \|/ { + # print + # getline + # print " " ip " harbor.machine" + # print " " ip " symphony.machine" + # print + # next + # } + # { print } + # ' config.yaml > config-new.yaml + + # # Verify the change was made + # if grep -q "harbor.machine" config-new.yaml && grep -q "symphony.machine" config-new.yaml; then + # echo "✅ DNS entries added to ConfigMap" + + # # Apply the updated ConfigMap + # sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml kubectl apply -f config-new.yaml + + # # Restart CoreDNS + # sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml kubectl rollout restart deployment coredns -n kube-system + # sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml kubectl rollout status deployment/coredns -n kube-system --timeout=60s + + # # Wait longer for DNS propagation + # echo "⏳ Waiting for DNS propagation..." + # sleep 15 + + # echo "✅ CoreDNS configured successfully" + # break + # else + # echo "⚠️ DNS entries not found in updated ConfigMap, retrying..." + # sleep 5 + # fi + + # if [ $RETRY -eq 3 ]; then + # echo "❌ Failed to configure CoreDNS after 3 attempts" + # echo "ConfigMap contents:" + # cat config-new.yaml + # exit 1 + # fi + # done - name: WFM-Client (Standalone Cluster) – Start diff --git a/scripts/device-agent.sh b/scripts/device-agent.sh index b54c94f8..c0bb907c 100644 --- a/scripts/device-agent.sh +++ b/scripts/device-agent.sh @@ -180,6 +180,7 @@ install_prerequisites() { if [ "$DEVICE_TYPE" = "k3s" ]; then setup_k3s configure_harbor_trust_for_k3s + echo "Waiting for k3s to stabilize..." sleep 5 configure_coredns_hosts fi diff --git a/scripts/modules/dns-host-config.sh b/scripts/modules/dns-host-config.sh index cf807037..a7e23cb1 100755 --- a/scripts/modules/dns-host-config.sh +++ b/scripts/modules/dns-host-config.sh @@ -39,14 +39,51 @@ get_ip_from_hosts() { #------------------------------------------------------------------------------ # Adds or updates NodeHosts entries in the CoreDNS ConfigMap. #------------------------------------------------------------------------------ + +add_or_update_host() { + local ip="$1" + local host="$2" + + if awk -v host="$host" ' + /^[[:space:]]*#/ { next } + $2 == host { found=1 } + END { exit !found } + ' <<<"$updated"; then + + updated=$( + awk -v ip="$ip" -v host="$host" ' + /^[[:space:]]*#/ { + print + next + } + + $2 == host { + print ip " " host + next + } + + { + print + } + ' <<<"$updated" + ) + + else + if [[ -n "$updated" ]]; then + updated+=$'\n' + fi + updated+="${ip} ${host}" + fi +} + configure_coredns_hosts() { set -euo pipefail local namespace="kube-system" local configmap="coredns" - local harbor_host="harbor.machine" - local symphony_host="symphony.machine" + local harbor_host="${EXPOSED_HARBOR_HOST}" + local symphony_host="${WFM_HOST}" local harbor_ip local symphony_ip @@ -82,42 +119,6 @@ configure_coredns_hosts() { updated="$nodehosts" - add_or_update_host() { - local ip="$1" - local host="$2" - - if awk -v host="$host" ' - /^[[:space:]]*#/ { next } - $2 == host { found=1 } - END { exit !found } - ' <<<"$updated"; then - - updated=$( - awk -v ip="$ip" -v host="$host" ' - /^[[:space:]]*#/ { - print - next - } - - $2 == host { - print ip " " host - next - } - - { - print - } - ' <<<"$updated" - ) - - else - if [[ -n "$updated" ]]; then - updated+=$'\n' - fi - updated+="${ip} ${host}" - fi - } - add_or_update_host "$harbor_ip" "$harbor_host" add_or_update_host "$symphony_ip" "$symphony_host" From 0b4de38358cc7e3e2eb209df1e95c213f97bbc8e Mon Sep 17 00:00:00 2001 From: sanjujunnuthula Date: Thu, 30 Jul 2026 13:32:15 +0000 Subject: [PATCH 4/7] chore: removed Configure CoreDNS for k3s step from github sanity action Signed-off-by: sanjujunnuthula --- .github/workflows/sandbox-sanity-test.yml | 57 ----------------------- 1 file changed, 57 deletions(-) diff --git a/.github/workflows/sandbox-sanity-test.yml b/.github/workflows/sandbox-sanity-test.yml index 2da6f9a1..4dea2f4b 100644 --- a/.github/workflows/sandbox-sanity-test.yml +++ b/.github/workflows/sandbox-sanity-test.yml @@ -296,63 +296,6 @@ jobs: sudo -E bash ./device-agent.sh k3s create-rsa-certs sudo -E bash ./device-agent.sh k3s create-ecdsa-certs - # - name: Configure CoreDNS for k3s - # run: | - # RUNNER_IP=${RUNNER_IP} - # echo "📡 Configuring CoreDNS with custom DNS entries..." - - # # Retry logic for ConfigMap update - # for RETRY in {1..3}; do - # echo "Attempt $RETRY to configure CoreDNS..." - - # # Get the full ConfigMap YAML - # sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml \ - # kubectl -n kube-system get configmap coredns -o yaml > config.yaml - - # # Update the Corefile section - # awk -v ip="$RUNNER_IP" ' - # /NodeHosts: \|/ { - # print - # getline - # print " " ip " harbor.machine" - # print " " ip " symphony.machine" - # print - # next - # } - # { print } - # ' config.yaml > config-new.yaml - - # # Verify the change was made - # if grep -q "harbor.machine" config-new.yaml && grep -q "symphony.machine" config-new.yaml; then - # echo "✅ DNS entries added to ConfigMap" - - # # Apply the updated ConfigMap - # sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml kubectl apply -f config-new.yaml - - # # Restart CoreDNS - # sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml kubectl rollout restart deployment coredns -n kube-system - # sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml kubectl rollout status deployment/coredns -n kube-system --timeout=60s - - # # Wait longer for DNS propagation - # echo "⏳ Waiting for DNS propagation..." - # sleep 15 - - # echo "✅ CoreDNS configured successfully" - # break - # else - # echo "⚠️ DNS entries not found in updated ConfigMap, retrying..." - # sleep 5 - # fi - - # if [ $RETRY -eq 3 ]; then - # echo "❌ Failed to configure CoreDNS after 3 attempts" - # echo "ConfigMap contents:" - # cat config-new.yaml - # exit 1 - # fi - # done - - - name: WFM-Client (Standalone Cluster) – Start working-directory: scripts run: | From c64cff4614b72a5b806b6bc6c643f710b9a15f05 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 3 Aug 2026 07:24:31 +0000 Subject: [PATCH 5/7] chore: update setupguide by removing CoreDNS configuration Signed-off-by: Ubuntu --- docs/setup-guide.md | 59 +++------------------------------------------ 1 file changed, 3 insertions(+), 56 deletions(-) diff --git a/docs/setup-guide.md b/docs/setup-guide.md index a240aff9..6e4c4b06 100644 --- a/docs/setup-guide.md +++ b/docs/setup-guide.md @@ -254,75 +254,22 @@ On each VM, you need to configure environment variables (settings that tell the ``` You should see log messages indicating the service is running. Press `Ctrl+C` to exit the logs. -**On K3s Device VM:** -1. **Navigate to the scripts folder** - ```bash - cd $HOME/workspace/sandbox/scripts - ``` - -2. **Configure the domain/host(name) resolution in coredns** - - The k3s based setups don't pick the changes from `/etc/hosts` system file, hence it is better to add hostname details in the the coredns config itself. - - 2.1. Fetch the coredns config first: - ```bash - sudo kubectl -n kube-system edit configmap coredns - ``` - - 2.2. Then add only the highlighted lines in the `NodeHosts` section with your IP addresses in them and save: - ```yaml - apiVersion: v1 - data: - Corefile: | - .:53 { - errors - health - ready - kubernetes cluster.local in-addr.arpa ip6.arpa { - pods insecure - fallthrough in-addr.arpa ip6.arpa - } - hosts /etc/coredns/NodeHosts { - ttl 60 - reload 15s - fallthrough - } - prometheus :9153 - forward . /etc/resolv.conf - cache 30 - loop - reload - loadbalance - import /etc/coredns/custom/*.override - } - import /etc/coredns/custom/*.server - NodeHosts: | - 20.11.000.000 harbor.machine # Newly added line to resolve harbor.machine - 20.11.000.000 symphony.machine # Newly added line to resolve symphony.machine - 10.0.0.11 margo-wfm-v10 - ``` - - 2.3. Then apply the changes: - ```bash - sudo kubectl -n kube-system rollout restart deployment coredns - ``` - -3. **Start the device's Workload Fleet Management Client** +2. **Start the device's Workload Fleet Management Client** ```bash sudo -E bash device-agent.sh k3s ``` - Type `5` and press Enter - Choose: `Option 5: Device-agent-Start(k3s-device)` -4. **Check device status** +3. **Check device status** ```bash sudo -E bash device-agent.sh k3s ``` - Type `7` and press Enter - Choose: `Option 7: Device-agent-Status` -5. **View device logs** +4. **View device logs** ```bash # View the logs (replace with actual pod name from above using #7) sudo kubectl logs -f -n default From d68e26c6bd763f82f898241fb5265e5dc76df9b0 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 3 Aug 2026 09:59:51 +0000 Subject: [PATCH 6/7] chore: update setupguide by removing CoreDNS configuration Signed-off-by: Ubuntu --- docs/setup-guide.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/setup-guide.md b/docs/setup-guide.md index 6e4c4b06..036bcfce 100644 --- a/docs/setup-guide.md +++ b/docs/setup-guide.md @@ -254,22 +254,28 @@ On each VM, you need to configure environment variables (settings that tell the ``` You should see log messages indicating the service is running. Press `Ctrl+C` to exit the logs. +**On K3s Device VM:** -2. **Start the device's Workload Fleet Management Client** +1. **Navigate to the scripts folder** + ```bash + cd $HOME/workspace/sandbox/scripts + ``` + +3. **Start the device's Workload Fleet Management Client** ```bash sudo -E bash device-agent.sh k3s ``` - Type `5` and press Enter - Choose: `Option 5: Device-agent-Start(k3s-device)` -3. **Check device status** +4. **Check device status** ```bash sudo -E bash device-agent.sh k3s ``` - Type `7` and press Enter - Choose: `Option 7: Device-agent-Status` -4. **View device logs** +5. **View device logs** ```bash # View the logs (replace with actual pod name from above using #7) sudo kubectl logs -f -n default From 6d6db4ed0737735f5b40090b51238dfcdd4c52cd Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 3 Aug 2026 10:00:17 +0000 Subject: [PATCH 7/7] chore: update setupguide by removing CoreDNS configuration Signed-off-by: Ubuntu --- docs/setup-guide.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/setup-guide.md b/docs/setup-guide.md index 036bcfce..3b5d57db 100644 --- a/docs/setup-guide.md +++ b/docs/setup-guide.md @@ -261,21 +261,21 @@ On each VM, you need to configure environment variables (settings that tell the cd $HOME/workspace/sandbox/scripts ``` -3. **Start the device's Workload Fleet Management Client** +2. **Start the device's Workload Fleet Management Client** ```bash sudo -E bash device-agent.sh k3s ``` - Type `5` and press Enter - Choose: `Option 5: Device-agent-Start(k3s-device)` -4. **Check device status** +3. **Check device status** ```bash sudo -E bash device-agent.sh k3s ``` - Type `7` and press Enter - Choose: `Option 7: Device-agent-Status` -5. **View device logs** +4. **View device logs** ```bash # View the logs (replace with actual pod name from above using #7) sudo kubectl logs -f -n default