Skip to content

Commit b32b067

Browse files
committed
Move to use newer IPsec DaemonSets when MCP is in paused state
When MCP is in paused state, network operator continues to render older IPsec daemonsets which blocks network cluster operator not getting upgraded to newer version. Hence this commit renders newer IPsec daemonsets for intermediate period. When MCPs are moved to unpaused state and IPsec machine configs are installed on it, then it goes ahead with rendering only host flavored IPsec daemonset. Signed-off-by: Periyasamy Palanisamy <pepalani@redhat.com>
1 parent a4f05cf commit b32b067

4 files changed

Lines changed: 415 additions & 7 deletions

File tree

bindata/network/ovn-kubernetes/common/ipsec-containerized.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ spec:
4949
- |
5050
#!/bin/bash
5151
set -exuo pipefail
52+
53+
{{ if .IPsecCheckForLibreswan }}
54+
if rpm --dbpath=/usr/share/rpm -q libreswan; then
55+
echo "host has libreswan and therefore ipsec will be configured by ipsec host daemonset, this ovn ipsec container doesnt need to init anything"
56+
exit 0
57+
fi
58+
{{ end }}
59+
5260
{{ if .NETWORK_NODE_IDENTITY_ENABLE }}
5361
# When NETWORK_NODE_IDENTITY_ENABLE is true, use the per-node certificate to create a kubeconfig
5462
# that will be used to talk to the API
@@ -189,6 +197,9 @@ spec:
189197
name: signer-ca
190198
- mountPath: /etc/openvswitch
191199
name: etc-openvswitch
200+
- mountPath: /usr/share/rpm
201+
name: host-usr-share-rpm
202+
readOnly: true
192203
resources:
193204
requests:
194205
cpu: 10m
@@ -220,6 +231,13 @@ spec:
220231
}
221232
trap cleanup SIGTERM
222233
234+
{{ if .IPsecCheckForLibreswan }}
235+
if rpm --dbpath=/usr/share/rpm -q libreswan; then
236+
echo "host has libreswan and therefore ipsec will be configured by ipsec host daemonset, this ovn ipsec container will sleep to infinity"
237+
sleep infinity
238+
fi
239+
{{ end }}
240+
223241
# Don't start IPsec until ovnkube-node has finished setting up the node
224242
counter=0
225243
until [ -f /etc/cni/net.d/10-ovn-kubernetes.conf ]
@@ -276,6 +294,9 @@ spec:
276294
name: host-var-log-ovs
277295
- mountPath: /etc/openvswitch
278296
name: etc-openvswitch
297+
- mountPath: /usr/share/rpm
298+
name: host-usr-share-rpm
299+
readOnly: true
279300
resources:
280301
requests:
281302
cpu: 10m
@@ -288,6 +309,12 @@ spec:
288309
- -c
289310
- |
290311
#!/bin/bash
312+
{{ if .IPsecCheckForLibreswan }}
313+
if rpm --dbpath=/usr/share/rpm -q libreswan; then
314+
echo "host has libreswan and therefore ipsec will be configured by ipsec host daemonset, this ovn ipsec container is always \"alive\""
315+
exit 0
316+
fi
317+
{{ end }}
291318
if [[ $(ipsec whack --trafficstatus | wc -l) -eq 0 ]]; then
292319
echo "no ipsec traffic configured"
293320
exit 10
@@ -321,6 +348,10 @@ spec:
321348
- name: host-cni-netd
322349
hostPath:
323350
path: "{{.CNIConfDir}}"
351+
- name: host-usr-share-rpm
352+
hostPath:
353+
path: /usr/share/rpm
354+
type: DirectoryOrCreate
324355
tolerations:
325356
- operator: "Exists"
326357
{{end}}

bindata/network/ovn-kubernetes/common/ipsec-host.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ spec:
5050
- |
5151
#!/bin/bash
5252
set -exuo pipefail
53+
{{ if .IPsecCheckForLibreswan }}
54+
if ! rpm --dbpath=/usr/share/rpm -q libreswan; then
55+
echo "host doesnt have libreswan, therefore ipsec will be configured by ipsec-containerized daemonset, this ovn ipsec container has nothing to init"
56+
exit 0
57+
fi
58+
{{ end }}
5359
{{ if .NETWORK_NODE_IDENTITY_ENABLE }}
5460
# When NETWORK_NODE_IDENTITY_ENABLE is true, use the per-node certificate to create a kubeconfig
5561
# that will be used to talk to the API
@@ -194,6 +200,9 @@ spec:
194200
name: etc-openvswitch
195201
- mountPath: /etc
196202
name: host-etc
203+
- mountPath: /usr/share/rpm
204+
name: host-usr-share-rpm
205+
readOnly: true
197206
resources:
198207
requests:
199208
cpu: 10m
@@ -210,6 +219,12 @@ spec:
210219
#!/bin/bash
211220
set -exuo pipefail
212221
222+
{{ if .IPsecCheckForLibreswan }}
223+
if ! rpm --dbpath=/usr/share/rpm -q libreswan; then
224+
echo "host doesnt have libreswan, therefore ipsec will be configured by ipsec-containerized daemonset, this ovn ipsec container will sleep to infinity"
225+
sleep infinity
226+
fi
227+
{{ end }}
213228

214229
# Don't start IPsec until ovnkube-node has finished setting up the node
215230
counter=0
@@ -268,6 +283,13 @@ spec:
268283
# In order to maintain traffic flows during container restart, we
269284
# need to ensure that xfrm state and policies are not flushed.
270285
286+
{{ if .IPsecCheckForLibreswan }}
287+
if ! rpm --dbpath=/usr/share/rpm -q libreswan; then
288+
echo "host doesnt have libreswan, therefore ipsec will be configured by ipsec-containerized daemonset, preStop wont do anything"
289+
exit 0
290+
fi
291+
{{ end }}
292+
271293
# Don't allow ovs monitor to cleanup persistent state
272294
kill "$(cat /var/run/openvswitch/ovs-monitor-ipsec.pid 2>/dev/null)" 2>/dev/null || true
273295
env:
@@ -291,6 +313,9 @@ spec:
291313
name: host-var-lib
292314
- mountPath: /etc
293315
name: host-etc
316+
- mountPath: /usr/share/rpm
317+
name: host-usr-share-rpm
318+
readOnly: true
294319
resources:
295320
requests:
296321
cpu: 10m
@@ -303,6 +328,12 @@ spec:
303328
- -c
304329
- |
305330
#!/bin/bash
331+
{{ if .IPsecCheckForLibreswan }}
332+
if ! rpm --dbpath=/usr/share/rpm -q libreswan; then
333+
echo "host doesnt have libreswan, therefore ipsec will be configured by ipsec-containerized daemonset, this ovn ipsec container is always \"alive\""
334+
exit 0
335+
fi
336+
{{ end }}
306337
if [[ $(ipsec whack --trafficstatus | wc -l) -eq 0 ]]; then
307338
echo "no ipsec traffic configured"
308339
exit 10
@@ -346,6 +377,10 @@ spec:
346377
path: /etc
347378
type: Directory
348379
name: host-etc
380+
- name: host-usr-share-rpm
381+
hostPath:
382+
path: /usr/share/rpm
383+
type: DirectoryOrCreate
349384
tolerations:
350385
- operator: "Exists"
351386
{{end}}

pkg/network/ovn_kubernetes.go

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,11 @@ func renderOVNKubernetes(conf *operv1.NetworkSpec, bootstrapResult *bootstrap.Bo
270270
}
271271

272272
IPsecMachineConfigEnable, OVNIPsecDaemonsetEnable, OVNIPsecEnable, renderIPsecHostDaemonSet, renderIPsecContainerizedDaemonSet,
273-
renderIPsecDaemonSetAsCreateWaitOnly := shouldRenderIPsec(c, bootstrapResult)
273+
renderIPsecDaemonSetAsCreateWaitOnly, renderBothIPsecDemonSetsWhenAPoolPausedState := shouldRenderIPsec(c, bootstrapResult)
274274
data.Data["IPsecMachineConfigEnable"] = IPsecMachineConfigEnable
275275
data.Data["OVNIPsecDaemonsetEnable"] = OVNIPsecDaemonsetEnable
276276
data.Data["OVNIPsecEnable"] = OVNIPsecEnable
277+
data.Data["IPsecCheckForLibreswan"] = renderBothIPsecDemonSetsWhenAPoolPausedState
277278

278279
// Set progressing to true until IPsec DaemonSet is rendered when EW IPsec config is enabled.
279280
// TODO Do a poor man's job mapping machine config pool status to CNO progressing state for now.
@@ -610,7 +611,7 @@ func IsIPsecLegacyAPI(conf *operv1.OVNKubernetesConfig) bool {
610611
// MachineConfig kind is not supported there.
611612
// All Other cases are not supported in pre-4.14 deployments.
612613
func shouldRenderIPsec(conf *operv1.OVNKubernetesConfig, bootstrapResult *bootstrap.BootstrapResult) (renderCNOIPsecMachineConfig, renderIPsecDaemonSet,
613-
renderIPsecOVN, renderIPsecHostDaemonSet, renderIPsecContainerizedDaemonSet, renderIPsecDaemonSetAsCreateWaitOnly bool) {
614+
renderIPsecOVN, renderIPsecHostDaemonSet, renderIPsecContainerizedDaemonSet, renderIPsecDaemonSetAsCreateWaitOnly, renderBothIPsecDemonSetsWhenAPoolPausedState bool) {
614615
isHypershiftHostedCluster := bootstrapResult.Infra.HostedControlPlane != nil
615616
isIpsecUpgrade := bootstrapResult.OVN.IPsecUpdateStatus != nil && bootstrapResult.OVN.IPsecUpdateStatus.LegacyIPsecUpgrade
616617
isOVNIPsecActive := bootstrapResult.OVN.IPsecUpdateStatus != nil && bootstrapResult.OVN.IPsecUpdateStatus.OVNIPsecActive
@@ -620,7 +621,9 @@ func shouldRenderIPsec(conf *operv1.OVNKubernetesConfig, bootstrapResult *bootst
620621
// On upgrade, we will just remove any existing ipsec deployment without making any
621622
// change to them. So during upgrade, we must keep track if IPsec MachineConfigs are
622623
// active or not for non Hybrid hosted cluster.
623-
isIPsecMachineConfigActive := isIPsecMachineConfigActive(bootstrapResult.Infra)
624+
machineConfigPoolPaused := isThereAnyMachineConfigPoolPaused(bootstrapResult.Infra)
625+
isIPsecMachineConfigActiveInUnPausedPools := isIPsecMachineConfigActive(bootstrapResult.Infra, true)
626+
isIPsecMachineConfigActive := isIPsecMachineConfigActive(bootstrapResult.Infra, false)
624627
isIPsecMachineConfigNotActiveOnUpgrade := isIpsecUpgrade && !isIPsecMachineConfigActive && !isHypershiftHostedCluster
625628
isMachineConfigClusterOperatorReady := bootstrapResult.Infra.MachineConfigClusterOperatorReady
626629
isCNOIPsecMachineConfigPresent := isCNOIPsecMachineConfigPresent(bootstrapResult.Infra)
@@ -629,16 +632,24 @@ func shouldRenderIPsec(conf *operv1.OVNKubernetesConfig, bootstrapResult *bootst
629632
// or if EW IPsec config is enabled.
630633
renderIPsecDaemonSet = isOVNIPsecActive || mode == operv1.IPsecModeFull
631634

635+
// When any of the machine pool in paused state and IPsec MachineConfig is not active on paused pools and active on
636+
// other unpaused pools then render both host and containerized ipsec deployment until machine config pools are moved
637+
// into unpaused state and IPsec MachineConfig is active on all pools.
638+
renderBothIPsecDemonSetsWhenAPoolPausedState = machineConfigPoolPaused && isIPsecMachineConfigActiveInUnPausedPools &&
639+
!isIPsecMachineConfigActive
640+
632641
// If ipsec is enabled, we render the host ipsec deployment except for
633642
// hypershift hosted clusters and we need to wait for the ipsec MachineConfig
634643
// extensions to be active first. We must also render host ipsec deployment
635644
// at the time of upgrade though user created IPsec Machine Config is not
636645
// present/active.
637-
renderIPsecHostDaemonSet = (renderIPsecDaemonSet && isIPsecMachineConfigActive && !isHypershiftHostedCluster) || isIPsecMachineConfigNotActiveOnUpgrade
646+
renderIPsecHostDaemonSet = (renderIPsecDaemonSet && isIPsecMachineConfigActive && !isHypershiftHostedCluster) ||
647+
isIPsecMachineConfigNotActiveOnUpgrade || renderBothIPsecDemonSetsWhenAPoolPausedState
638648

639649
// The containerized ipsec deployment is only rendered during upgrades or
640650
// for hypershift hosted clusters.
641-
renderIPsecContainerizedDaemonSet = (renderIPsecDaemonSet && isHypershiftHostedCluster) || isIPsecMachineConfigNotActiveOnUpgrade
651+
renderIPsecContainerizedDaemonSet = (renderIPsecDaemonSet && isHypershiftHostedCluster) || isIPsecMachineConfigNotActiveOnUpgrade ||
652+
renderBothIPsecDemonSetsWhenAPoolPausedState
642653

643654
// MachineConfig IPsec extensions rollout is needed for the ipsec enablement and are used in both External and Full modes.
644655
// except when the containerized deployment is used in hypershift hosted clusters.
@@ -653,7 +664,7 @@ func shouldRenderIPsec(conf *operv1.OVNKubernetesConfig, bootstrapResult *bootst
653664

654665
// While OVN ipsec is being upgraded and IPsec MachineConfigs deployment is in progress
655666
// (or) IPsec config in OVN is being disabled, then ipsec deployment is not updated.
656-
renderIPsecDaemonSetAsCreateWaitOnly = isIPsecMachineConfigNotActiveOnUpgrade || (isOVNIPsecActive && !renderIPsecOVN)
667+
renderIPsecDaemonSetAsCreateWaitOnly = (isIPsecMachineConfigNotActiveOnUpgrade && !renderBothIPsecDemonSetsWhenAPoolPausedState) || (isOVNIPsecActive && !renderIPsecOVN)
657668

658669
return
659670
}
@@ -1479,7 +1490,7 @@ func containsNetworkOwnerRef(ownerRefs []metav1.OwnerReference) bool {
14791490

14801491
// isIPsecMachineConfigActive returns true if both master and worker's machine config pools are ready with
14811492
// ipsec machine config extension rolled out, otherwise returns false.
1482-
func isIPsecMachineConfigActive(infra bootstrap.InfraStatus) bool {
1493+
func isIPsecMachineConfigActive(infra bootstrap.InfraStatus, checkOnlyUnpausedPool bool) bool {
14831494
if infra.MasterIPsecMachineConfigs == nil || infra.WorkerIPsecMachineConfigs == nil {
14841495
// One of the IPsec MachineConfig is not created yet, so return false.
14851496
return false
@@ -1493,18 +1504,49 @@ func isIPsecMachineConfigActive(infra bootstrap.InfraStatus) bool {
14931504
hasSourceInMachineConfigStatus(status, machineConfigs)
14941505
}
14951506
for _, masterMCP := range infra.MasterMCPs {
1507+
if checkOnlyUnpausedPool && masterMCP.Spec.Paused {
1508+
continue
1509+
}
14961510
if !ipSecPluginOnPool(masterMCP.Status, infra.MasterIPsecMachineConfigs) {
14971511
return false
14981512
}
14991513
}
15001514
for _, workerMCP := range infra.WorkerMCPs {
1515+
if checkOnlyUnpausedPool && workerMCP.Spec.Paused {
1516+
continue
1517+
}
15011518
if !ipSecPluginOnPool(workerMCP.Status, infra.WorkerIPsecMachineConfigs) {
15021519
return false
15031520
}
15041521
}
15051522
return true
15061523
}
15071524

1525+
func isThereAnyMachineConfigPoolPaused(infra bootstrap.InfraStatus) bool {
1526+
if infra.MasterIPsecMachineConfigs == nil || infra.WorkerIPsecMachineConfigs == nil {
1527+
// One of the IPsec MachineConfig is not created yet, so return false.
1528+
return false
1529+
}
1530+
if len(infra.MasterMCPs) == 0 || len(infra.WorkerMCPs) == 0 {
1531+
// When none of MachineConfig pools exist, then return false. needed for unit test.
1532+
return false
1533+
}
1534+
isPausedPool := func(pool mcfgv1.MachineConfigPool) bool {
1535+
return pool.Spec.Paused
1536+
}
1537+
for _, masterMCP := range infra.MasterMCPs {
1538+
if isPausedPool(masterMCP) {
1539+
return true
1540+
}
1541+
}
1542+
for _, workerMCP := range infra.WorkerMCPs {
1543+
if isPausedPool(workerMCP) {
1544+
return true
1545+
}
1546+
}
1547+
return false
1548+
}
1549+
15081550
func hasSourceInMachineConfigStatus(machineConfigStatus mcfgv1.MachineConfigPoolStatus, machineConfigs []*mcfgv1.MachineConfig) bool {
15091551
ipSecMachineConfigNames := sets.New[string]()
15101552
for _, machineConfig := range machineConfigs {

0 commit comments

Comments
 (0)