@@ -7,30 +7,38 @@ BRIDGE_NAME=brext
7
7
8
8
export KUBECONFIG=${KUBECONFIG:- ../ OpenShift/ ocp/ auth/ kubeconfig}
9
9
10
+ nodes=$( oc get nodes -o jsonpath=' {range .items[*]}{.metadata.name} {end}' )
11
+
10
12
echo " Configuring networks on nodes"
13
+ for node in $nodes ; do
14
+ echo " Detecting the default interface"
15
+ while ! default_iface=$( oc get nodenetworkstate ${node} -o jsonpath=" {.status.currentState.routes.running[?(@.destination==\" ${MACHINE_CIDR} \" )].next-hop-interface}" | cut -d " " -f 1) ; do
16
+ sleep 10
17
+ done
11
18
12
- echo " Detecting the default interface "
13
- while ! default_iface= $( oc get nodenetworkstate ${node} -o jsonpath= " {.items[0].status.currentState.routes.running[?(@.destination== \" ${MACHINE_CIDR} \" )].next-hop- interface} " | cut -d " " -f 1 ) ; do
14
- sleep 10
15
- done
19
+ if [ " ${default_iface} " == " ${BRIDGE_NAME} " ] ; then
20
+ echo " Bridge ${BRIDGE_NAME} seems to be already configured as the default interface on node ${node} , skipping the rest of network setup "
21
+ continue
22
+ fi
16
23
17
- if [ " ${default_iface} " == " ${BRIDGE_NAME} " ]; then
18
- echo " Bridge ${BRIDGE_NAME} seems to be already configured as the default interface, skipping the rest of network setup"
19
- exit 0
20
- fi
24
+ echo " Detecting MAC address of the default interface"
25
+ default_iface_mac=$( oc get nodenetworkstate ${node} -o jsonpath=" {.status.currentState.interfaces[?(@.name==\" ${default_iface} \" )].mac-address}" )
21
26
22
- echo " Applying node network configuration policy"
23
- cat << EOF | oc apply -f -
27
+ echo " Applying node network configuration policy"
28
+ cat << EOF | oc apply -f -
24
29
apiVersion: nmstate.io/v1alpha1
25
30
kind: NodeNetworkConfigurationPolicy
26
31
metadata:
27
- name: kni-policy
32
+ name: kni-${node}
28
33
spec:
34
+ nodeSelector:
35
+ kubernetes.io/hostname: ${node}
29
36
desiredState:
30
37
interfaces:
31
38
- name: ${BRIDGE_NAME}
32
39
type: linux-bridge
33
40
state: up
41
+ mac-address: ${default_iface_mac}
34
42
ipv4:
35
43
dhcp: true
36
44
enabled: true
@@ -44,10 +52,10 @@ spec:
44
52
port:
45
53
- name: ${default_iface}
46
54
EOF
55
+ done
47
56
48
57
echo " Waiting until the configuration is done, it may take up to 5 minutes until keepalived gets reconfigured"
49
- nodes=$( oc get nodes -o jsonpath=' {range .items[*]}{.metadata.name} {end}' )
50
58
for node in $nodes ; do
51
59
until [ " $( oc get nodenetworkstate ${node} -o jsonpath=" {.status.currentState.routes.running[?(@.destination==\" ${MACHINE_CIDR} \" )].next-hop-interface}" ) " == " ${BRIDGE_NAME} " ]; do sleep 10; done
60
+ oc wait node ${node} --for condition=Ready --timeout=10m
52
61
done
53
- oc wait node --all --for condition=Ready --timeout=10m
0 commit comments