Skip to content

Commit 03ee24f

Browse files
authored
Merge pull request #63 from ijc/cni-bridge-configurability
Cni bridge configurability
2 parents a620e96 + e07e328 commit 03ee24f

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

boot.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ set -e
1717
: ${KUBE_MAC:=}
1818
: ${KUBE_CLEAR_STATE:=}
1919

20+
: ${KUBE_METADATA:=} # Without the outermost braces {}.
21+
2022
[ "$(uname -s)" = "Darwin" ] && KUBE_EFI=1
2123

2224
suffix=".iso"
@@ -28,10 +30,10 @@ if [ $# -eq 0 ] ; then
2830
# then we configure for auto init. If it is completely unset then
2931
# we do not.
3032
if [ -n "${KUBE_MASTER_AUTOINIT+x}" ] ; then
31-
kubeadm_data="${kubeadm_data+$kubeadm_data, }\"init\": { \"content\": \"${KUBE_MASTER_AUTOINIT}\" }"
33+
kubeadm_data="${kubeadm_data:+$kubeadm_data, }\"init\": { \"content\": \"${KUBE_MASTER_AUTOINIT}\" }"
3234
fi
3335
if [ "${KUBE_MASTER_UNTAINT}" = "y" ] ; then
34-
kubeadm_data="${kubeadm_data+$kubeadm_data, }\"untaint-master\": { \"content\": \"\" }"
36+
kubeadm_data="${kubeadm_data:+$kubeadm_data, }\"untaint-master\": { \"content\": \"\" }"
3537
fi
3638

3739
state="kube-master-state"
@@ -84,8 +86,15 @@ fi
8486

8587
mkdir -p "${state}"
8688
touch $state/metadata.json
89+
if [ -n "${KUBE_METADATA}" ] ; then
90+
metadata="${metadata:+$metadata, }${KUBE_METADATA}"
91+
fi
8792
if [ -n "${kubeadm_data}" ] ; then
88-
echo "{ \"kubeadm\": { \"entries\": { ${kubeadm_data} } } }" > $state/metadata.json
93+
metadata="${metadata:+$metadata, }\"kubeadm\": { \"entries\": { ${kubeadm_data} } }"
94+
fi
95+
if [ -n "${metadata}" ] ; then
96+
metadata="{ ${metadata} }"
97+
echo "${metadata}" > $state/metadata.json
8998
fi
9099

91100
exec linuxkit run ${KUBE_RUN_ARGS} -networking ${KUBE_NETWORKING} -cpus ${KUBE_VCPUS} -mem ${KUBE_MEM} -state "${state}" -disk size=${KUBE_DISK} -data-file $state/metadata.json ${uefi} "${img}${suffix}"

test/cases/000_smoke/test.exp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ if [string match "Welcome to nginx!" $curl] {
216216
}
217217
puts "SUCCESS nginx responded well"
218218

219+
sshcmd "cat cni config" {grep . /var/lib/cni/conf/*.conf /var/lib/cni/conf/*.conflist}
220+
sshcmd "host ifconfig" {ifconfig -a && route -n && echo && grep . /etc/resolv.conf}
221+
sshcmd "nginx ifconfig" {kubectl exec $(kubectl get pods -l name==nginx -o=jsonpath='{.items[*].metadata.name}') -- sh -c 'ifconfig -a && route -n && echo && grep . /etc/resolv.conf'}
222+
sshcmd "alpine ifconfig" {kubectl exec $(kubectl get pods -l name==alpine -o=jsonpath='{.items[*].metadata.name}') -- sh -c 'ifconfig -a && route -n && echo && grep . /etc/resolv.conf'}
223+
219224
# This also happens to test external connectivity...
220225
sshcmd "alpine install curl" {kubectl exec $(kubectl get pods -l name==alpine -o=jsonpath='{.items[*].metadata.name}') -- apk add --update curl}
221226

yml/bridge.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@ onboot:
55
- "/bin/sh"
66
- "-c"
77
- |
8-
set -ex
8+
set -e
9+
field() {
10+
local f=$1
11+
local d=$2
12+
if [ -r "/run/config/cni.bridge/$f" ] ; then
13+
cat "/run/config/cni.bridge/$f"
14+
else
15+
echo -e "\"$d\"\\n"
16+
fi
17+
}
18+
subnet="$(field subnet '10.1.0.0/16')"
19+
gateway="$(field gateway '10.1.0.1')"
20+
ns="$(field ns '10.1.0.1')"
921
cat <<EOF >/var/lib/cni/conf/10-default.conflist
1022
{
1123
"cniVersion": "0.3.1",
@@ -19,11 +31,11 @@ onboot:
1931
"hairpinMode": true,
2032
"ipam": {
2133
"type": "host-local",
22-
"subnet": "10.1.0.0/16",
23-
"gateway": "10.1.0.1"
34+
"subnet": $subnet,
35+
"gateway": $gateway
2436
},
2537
"dns": {
26-
"nameservers": ["10.1.0.1"]
38+
"nameservers": [$ns]
2739
}
2840
},
2941
{
@@ -42,7 +54,11 @@ onboot:
4254
"type": "loopback"
4355
}
4456
EOF
57+
if [ -r "/run/config/cni.bridge/debug-show-configs" ] ; then
58+
grep . /var/lib/cni/conf/*.conf /var/lib/cni/conf/*.conflist
59+
fi
4560
runtime:
4661
mkdir: ["/var/lib/cni/conf"]
4762
binds:
4863
- /var/lib:/var/lib
64+
- /run/config:/run/config

0 commit comments

Comments
 (0)