@@ -5,19 +5,19 @@ mount -o remount rw /proc/sys
5
5
export DATASTORE_TYPE=kubernetes
6
6
7
7
masq_eni_only () {
8
- if ! " $1 " -t nat -L terway-masq; then
9
- # Create a new chain in nat table.
10
- " $1 " -t nat -N terway-masq
11
- fi
8
+ if ! " $1 " -t nat -L terway-masq; then
9
+ # Create a new chain in nat table.
10
+ " $1 " -t nat -N terway-masq
11
+ fi
12
12
13
- if ! " $1 " -t nat -L POSTROUTING | grep -q terway-masq; then
14
- # Append that chain to POSTROUTING table.
15
- " $1 " -t nat -A POSTROUTING -m comment --comment " terway:masq-outgoing" ! -o lo -j terway-masq
16
- fi
13
+ if ! " $1 " -t nat -L POSTROUTING | grep -q terway-masq; then
14
+ # Append that chain to POSTROUTING table.
15
+ " $1 " -t nat -A POSTROUTING -m comment --comment " terway:masq-outgoing" ! -o lo -j terway-masq
16
+ fi
17
17
18
- if ! " $1 " -t nat -L terway-masq | grep -q MASQUERADE; then
19
- " $1 " -t nat -A terway-masq -j MASQUERADE
20
- fi
18
+ if ! " $1 " -t nat -L terway-masq | grep -q MASQUERADE; then
19
+ " $1 " -t nat -A terway-masq -j MASQUERADE
20
+ fi
21
21
}
22
22
23
23
terway_config_val () {
@@ -51,16 +51,16 @@ if grep -q "cni_exclusive_eni *= *eniOnly" "$node_capabilities"; then
51
51
52
52
# for health check
53
53
if [ " $FELIX_HEALTHPORT " != " " ]; then
54
- # shellcheck disable=SC2016
55
- exec socat TCP-LISTEN:" $FELIX_HEALTHPORT " ,bind=127.0.0.1,fork,reuseaddr system:' sleep 2;kill -9 $SOCAT_PID 2>/dev/null'
54
+ # shellcheck disable=SC2016
55
+ exec socat TCP-LISTEN:" $FELIX_HEALTHPORT " ,bind=127.0.0.1,fork,reuseaddr system:' sleep 2;kill -9 $SOCAT_PID 2>/dev/null'
56
56
else
57
- # shellcheck disable=SC2016
58
- exec socat TCP-LISTEN:9099,bind=127.0.0.1,fork,reuseaddr system:' sleep 2;kill -9 $SOCAT_PID 2>/dev/null'
57
+ # shellcheck disable=SC2016
58
+ exec socat TCP-LISTEN:9099,bind=127.0.0.1,fork,reuseaddr system:' sleep 2;kill -9 $SOCAT_PID 2>/dev/null'
59
59
fi
60
60
fi
61
61
62
62
if grep -q " datapath *= *datapathv2" " $node_capabilities " ; then
63
- datapath_mode=veth
63
+ datapath_mode=veth
64
64
fi
65
65
66
66
# kernel version has already checked in initContainer, so just determine whether plugin chaining exists
@@ -69,7 +69,7 @@ if [ "$virtyal_type" = "ipvlan" ] || [ "$virtyal_type" = "datapathv2" ]; then
69
69
70
70
# kernel version equal and above 4.19
71
71
if { [ " $KERNEL_MAJOR_VERSION " -eq 4 ] && [ " $KERNEL_MINOR_VERSION " -ge 19 ]; } ||
72
- [ " $KERNEL_MAJOR_VERSION " -gt 4 ]; then
72
+ [ " $KERNEL_MAJOR_VERSION " -gt 4 ]; then
73
73
74
74
extra_args=$( terway_config_val ' cilium_args' )
75
75
if [ -z " $DISABLE_POLICY " ] || [ " $DISABLE_POLICY " = " false" ] || [ " $DISABLE_POLICY " = " 0" ]; then
@@ -95,106 +95,115 @@ if [ "$virtyal_type" = "ipvlan" ] || [ "$virtyal_type" = "datapathv2" ]; then
95
95
echo " turning up hubble, passing args \" ${extra_args} \" "
96
96
fi
97
97
98
- if [ " $IN_CLUSTER_LOADBALANCE " = " true" ]; then
99
- extra_args=" ${extra_args} --enable-in-cluster-loadbalance=true "
100
- echo " turning up in cluster loadbalance, passing args \" ${extra_args} \" "
101
- fi
98
+ if [ " $IN_CLUSTER_LOADBALANCE " = " true" ]; then
99
+ extra_args=" ${extra_args} --enable-in-cluster-loadbalance=true "
100
+ echo " turning up in cluster loadbalance, passing args \" ${extra_args} \" "
101
+ fi
102
102
103
- if bpftool -j feature probe | grep bpf_skb_ecn_set_ce ; then
104
- extra_args=" ${extra_args} --enable-bandwidth-manager=true "
105
- fi
103
+ if bpftool -j feature probe | grep bpf_skb_ecn_set_ce; then
104
+ extra_args=" ${extra_args} --enable-bandwidth-manager=true "
105
+ fi
106
106
107
107
echo " using cilium as network routing & policy"
108
108
109
109
# shellcheck disable=SC2086
110
110
exec cilium-agent --tunnel=disabled --enable-ipv4-masquerade=false --enable-ipv6-masquerade=false \
111
- --enable-policy=$ENABLE_POLICY \
112
- --agent-health-port=9099 --disable-envoy-version-check=true \
113
- --enable-local-node-route=false --ipv4-range=169.254.10.0/30 --ipv6-range=fe80:2400:3200:baba::/30 --enable-endpoint-health-checking=false \
114
- --enable-health-checking=false --enable-service-topology=true --disable-cnp-status-updates=true --k8s-heartbeat-timeout=0 --enable-session-affinity=true \
115
- --install-iptables-rules=false --enable-l7-proxy=false \
116
- --ipam=cluster-pool --datapath-mode=${datapath_mode} --enable-runtime-device-detection=true ${extra_args}
111
+ --enable-policy=$ENABLE_POLICY \
112
+ --agent-health-port=9099 --disable-envoy-version-check=true \
113
+ --enable-local-node-route=false --ipv4-range=169.254.10.0/30 --ipv6-range=fe80:2400:3200:baba::/30 --enable-endpoint-health-checking=false \
114
+ --enable-health-checking=false --enable-service-topology=true --disable-cnp-status-updates=true --k8s-heartbeat-timeout=0 --enable-session-affinity=true \
115
+ --install-iptables-rules=false --enable-l7-proxy=false \
116
+ --ipam=cluster-pool --datapath-mode=${datapath_mode} --enable-runtime-device-detection=true ${extra_args}
117
117
fi
118
118
fi
119
- # shellcheck disable=SC1091
120
- source uninstall_policy.sh
121
-
122
- # check kernel version
119
+ # shellcheck disable=SC1091
120
+ source uninstall_policy.sh
123
121
124
- export FELIX_IPTABLESBACKEND=Auto
125
- if ( uname -r | grep -E " el7|an7" && [ " ${KERNEL_MAJOR_VERSION} " -eq 3 ] ) || ( uname -r | grep -E " al7" && [ " ${KERNEL_MAJOR_VERSION} " -eq 4 ] ); then
126
- export FELIX_IPTABLESBACKEND=Legacy
127
- elif ( uname -r | grep -E " el8|an8" && [ " ${KERNEL_MAJOR_VERSION} " -ge 4 ] ) || ( uname -r | grep -E " al8|lifsea8" && [ " ${KERNEL_MAJOR_VERSION} " -ge 5 ] ); then
128
- export FELIX_IPTABLESBACKEND=NFT
122
+ # check kernel version
129
123
130
- # clean legacy rules if exist
131
- cleanup_legacy
132
- fi
124
+ export FELIX_IPTABLESBACKEND=Auto
125
+ if (uname -r | grep -E " el7|an7" && [ " ${KERNEL_MAJOR_VERSION} " -eq 3 ]) || (uname -r | grep -E " al7" && [ " ${KERNEL_MAJOR_VERSION} " -eq 4 ]); then
126
+ export FELIX_IPTABLESBACKEND=Legacy
127
+ elif (uname -r | grep -E " el8|an8" && [ " ${KERNEL_MAJOR_VERSION} " -ge 4 ]) || (uname -r | grep -E " al8|lifsea8" && [ " ${KERNEL_MAJOR_VERSION} " -ge 5 ]); then
128
+ export FELIX_IPTABLESBACKEND=NFT
133
129
134
- # default for veth
135
- export FELIX_LOGSEVERITYSYS=none
136
- export FELIX_LOGSEVERITYSCREEN=info
137
- export CALICO_NETWORKING_BACKEND=none
138
- export CLUSTER_TYPE=k8s,aliyun
139
- export CALICO_DISABLE_FILE_LOGGING=true
140
- # shellcheck disable=SC2154
141
- export CALICO_IPV4POOL_CIDR=" ${Network} "
142
- export FELIX_IPTABLESREFRESHINTERVAL=" ${IPTABLESREFRESHINTERVAL:- 60} "
143
- export FELIX_IPV6SUPPORT=true
144
- export WAIT_FOR_DATASTORE=true
145
- export IP=" "
146
- export NO_DEFAULT_POOLS=true
147
- export FELIX_DEFAULTENDPOINTTOHOSTACTION=ACCEPT
148
- export FELIX_HEALTHENABLED=true
149
- export FELIX_LOGFILEPATH=/dev/null
150
- export FELIX_BPFENABLED=false
151
- export FELIX_XDPENABLED=false
152
- export FELIX_BPFCONNECTTIMELOADBALANCINGENABLED=false
153
- export FELIX_BPFKUBEPROXYIPTABLESCLEANUPENABLED=false
154
- exec 2>&1
155
- if [ -n " $NODENAME " ]; then
156
- export FELIX_FELIXHOSTNAME=" $NODENAME "
157
- fi
158
- if [ -n " $DATASTORE_TYPE " ]; then
159
- export FELIX_DATASTORETYPE=" $DATASTORE_TYPE "
160
- fi
130
+ # clean legacy rules if exist
131
+ cleanup_legacy
132
+ fi
161
133
162
- if [ " $network_policy_provider " = " ebpf" ]; then
163
- cleanup_felix
164
- # kernel version equal and above 4.19
165
- if { [ " $KERNEL_MAJOR_VERSION " -eq 4 ] && [ " $KERNEL_MINOR_VERSION " -ge 19 ]; } ||
166
- [ " $KERNEL_MAJOR_VERSION " -gt 4 ]; then
167
-
168
- if [ -z " $DISABLE_POLICY " ] || [ " $DISABLE_POLICY " = " false" ] || [ " $DISABLE_POLICY " = " 0" ]; then
169
- ENABLE_POLICY=" default"
170
- else
171
- ENABLE_POLICY=" never"
172
- fi
173
- # shellcheck disable=SC2086
174
- exec cilium-agent --kube-proxy-replacement=disabled --tunnel=disabled --enable-ipv4-masquerade=false --enable-ipv6-masquerade=false \
175
- --enable-policy=$ENABLE_POLICY \
176
- --agent-health-port=9099 --disable-envoy-version-check=true \
177
- --enable-local-node-route=false --ipv4-range=169.254.10.0/30 --ipv6-range=fe80:2400:3200:baba::/30 --enable-endpoint-health-checking=false \
178
- --enable-health-checking=false --enable-service-topology=true --disable-cnp-status-updates=true --k8s-heartbeat-timeout=0 --enable-session-affinity=true \
179
- --install-iptables-rules=false --enable-l7-proxy=false \
180
- --ipam=cluster-pool
181
- else
182
- echo " unsupported kernel version"
183
- exit 1
184
- fi
185
- else
186
- if [ -z " $DISABLE_POLICY " ] || [ " $DISABLE_POLICY " = " false" ] || [ " $DISABLE_POLICY " = " 0" ]; then
187
- exec calico-felix
188
- fi
189
- fi
134
+ # default for veth
135
+ export FELIX_LOGSEVERITYSYS=none
136
+ export FELIX_LOGSEVERITYSCREEN=info
137
+ export CALICO_NETWORKING_BACKEND=none
138
+ export CLUSTER_TYPE=k8s,aliyun
139
+ export CALICO_DISABLE_FILE_LOGGING=true
140
+ # shellcheck disable=SC2154
141
+ export CALICO_IPV4POOL_CIDR=" ${Network} "
142
+ export FELIX_IPTABLESREFRESHINTERVAL=" ${IPTABLESREFRESHINTERVAL:- 60} "
143
+ export FELIX_IPV6SUPPORT=true
144
+ export WAIT_FOR_DATASTORE=true
145
+ export IP=" "
146
+ export NO_DEFAULT_POOLS=true
147
+ export FELIX_DEFAULTENDPOINTTOHOSTACTION=ACCEPT
148
+ export FELIX_HEALTHENABLED=true
149
+ export FELIX_LOGFILEPATH=/dev/null
150
+ export FELIX_BPFENABLED=false
151
+ export FELIX_XDPENABLED=false
152
+ export FELIX_BPFCONNECTTIMELOADBALANCINGENABLED=false
153
+ export FELIX_BPFKUBEPROXYIPTABLESCLEANUPENABLED=false
154
+ exec 2>&1
155
+ if [ -n " $NODENAME " ]; then
156
+ export FELIX_FELIXHOSTNAME=" $NODENAME "
157
+ fi
158
+ if [ -n " $DATASTORE_TYPE " ]; then
159
+ export FELIX_DATASTORETYPE=" $DATASTORE_TYPE "
160
+ fi
190
161
191
- config_masquerade
162
+ if [ " $network_policy_provider " = " ebpf " ] ; then
192
163
cleanup_felix
193
- # for health check
194
- if [ " $FELIX_HEALTHPORT " != " " ]; then
195
- # shellcheck disable=SC2016
196
- exec socat TCP-LISTEN:" $FELIX_HEALTHPORT " ,bind=127.0.0.1,fork,reuseaddr system:' sleep 2;kill -9 $SOCAT_PID 2>/dev/null'
164
+ # kernel version equal and above 4.19
165
+ if { [ " $KERNEL_MAJOR_VERSION " -eq 4 ] && [ " $KERNEL_MINOR_VERSION " -ge 19 ]; } ||
166
+ [ " $KERNEL_MAJOR_VERSION " -gt 4 ]; then
167
+
168
+ extra_args=$( terway_config_val ' cilium_args' )
169
+
170
+ if [ -z " $DISABLE_POLICY " ] || [ " $DISABLE_POLICY " = " false" ] || [ " $DISABLE_POLICY " = " 0" ]; then
171
+ ENABLE_POLICY=" default"
172
+ else
173
+ ENABLE_POLICY=" never"
174
+ extra_args=" ${extra_args} --labels=k8s:io\\ .kubernetes\\ .pod\\ .namespace "
175
+ fi
176
+
177
+ if [ " $IN_CLUSTER_LOADBALANCE " = " true" ]; then
178
+ extra_args=" ${extra_args} --enable-in-cluster-loadbalance=true "
179
+ echo " turning up in cluster loadbalance, passing args \" ${extra_args} \" "
180
+ fi
181
+
182
+ # shellcheck disable=SC2086
183
+ exec cilium-agent --kube-proxy-replacement=disabled --tunnel=disabled --enable-ipv4-masquerade=false --enable-ipv6-masquerade=false \
184
+ --enable-policy=$ENABLE_POLICY \
185
+ --agent-health-port=9099 --disable-envoy-version-check=true \
186
+ --enable-local-node-route=false --ipv4-range=169.254.10.0/30 --ipv6-range=fe80:2400:3200:baba::/30 --enable-endpoint-health-checking=false \
187
+ --enable-health-checking=false --enable-service-topology=true --disable-cnp-status-updates=true --k8s-heartbeat-timeout=0 --enable-session-affinity=true \
188
+ --install-iptables-rules=false --enable-l7-proxy=false \
189
+ --ipam=cluster-pool ${extra_args}
197
190
else
198
- # shellcheck disable=SC2016
199
- exec socat TCP-LISTEN:9099,bind=127.0.0.1,fork,reuseaddr system:' sleep 2;kill -9 $SOCAT_PID 2>/dev/null'
191
+ echo " unsupported kernel version"
192
+ exit 1
193
+ fi
194
+ else
195
+ if [ -z " $DISABLE_POLICY " ] || [ " $DISABLE_POLICY " = " false" ] || [ " $DISABLE_POLICY " = " 0" ]; then
196
+ exec calico-felix
200
197
fi
198
+ fi
199
+
200
+ config_masquerade
201
+ cleanup_felix
202
+ # for health check
203
+ if [ " $FELIX_HEALTHPORT " != " " ]; then
204
+ # shellcheck disable=SC2016
205
+ exec socat TCP-LISTEN:" $FELIX_HEALTHPORT " ,bind=127.0.0.1,fork,reuseaddr system:' sleep 2;kill -9 $SOCAT_PID 2>/dev/null'
206
+ else
207
+ # shellcheck disable=SC2016
208
+ exec socat TCP-LISTEN:9099,bind=127.0.0.1,fork,reuseaddr system:' sleep 2;kill -9 $SOCAT_PID 2>/dev/null'
209
+ fi
0 commit comments