/
daemonset-merge.yaml
80 lines (70 loc) · 2.58 KB
/
daemonset-merge.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: resolve-host-patcher
namespace: kube-system
spec:
selector:
matchLabels:
name: resolve-host-patcher
template:
metadata:
labels:
name: resolve-host-patcher
spec:
containers:
- image: bash
name: resolve-host-patcher
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
command:
- bash
- -c
- |
#!/bin/bash
set -x -e
function patch(){
echo "$(date -u) - Beginning to patch /etc/resolv.conf on the node"
# get around systemd-resolved shenanigans
cat /var/run/hostpaths/etc/resolv.conf > /var/run/hostpaths/etc/resolv.conf.tmp
unlink /var/run/hostpaths/etc/resolv.conf || true # read-only docker-desktop shenanigans
cat /var/run/hostpaths/etc/resolv.conf.tmp > /var/run/hostpaths/etc/resolv.conf
# Patch the resolve.conf file
MOD_LINE="# $(date -u) - modified by resolve-host-patcher on boot"
grep -v 'resolve-host-patcher' /var/run/hostpaths/etc/resolv.conf > /tmp/original-node-resolve.conf
echo "${MOD_LINE}" > /tmp/kube-resolv.conf
for ip in $(grep ^nameserver /etc/resolv.conf | awk '{$1=""; print}'); do
echo "nameserver ${ip} # added by resolve-host-patcher" >> /tmp/kube-resolv.conf
done
# options can break things, we're just going to disable those
sed -i -e 's/^options/#options/g' /tmp/original-node-resolve.conf
# concatenate the files and merge them into a singular resolv.conf
# the sed plumbing prevents empty lines from growing
cat /tmp/kube-resolv.conf /tmp/original-node-resolve.conf | sed '/^$/d' > /var/run/hostpaths/etc/resolv.conf
cat /var/run/hostpaths/etc/resolv.conf
ls -lah /var/run/hostpaths/etc/resolv.conf
cat /var/run/hostpaths/etc/resolv.conf
echo "$(date -u) - Done patching /etc/resolv.conf"
}
while true; do
patch
echo "$(date -u) - Sleeping for 30 min"
sleep 30m
done
exit 0 # I would like to exit 0 and only run on boot...
volumeMounts:
- mountPath: /var/run/hostpaths/etc/
name: etc
- mountPath: /var/run/hostpaths/run/
name: run
volumes:
- name: etc
hostPath:
path: /etc
- name: run
hostPath:
path: /run