Skip to content

Commit 3146b18

Browse files
committed
Delete CNI configuration file when SDN pod is stopped
The openshift sdn CNI configuration file /etc/cni/net.d/80-openshift-network.conf is written on the node upon first time of sdn pod deployment and remains to be there on the node during its lifetime. This makes multus to assume sdn is in ready state though sdn pod is coming up during reboot scenarios. Because of this, for a pod delete request, CNI DELETE request fails with connection refused error when sdn cni server socket is being created, this may end up in entries for the pod may not get cleaned up (example: IP address allocated for the pod by host-local IPAM plugin). Hence this commit cleans up the cni config file as soon as sigterm signal is received, it makes multus to wait until sdn plugin is actually ready and then invoke CNI requests. Signed-off-by: Periyasamy Palanisamy <[email protected]>
1 parent cbddb0b commit 3146b18

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pkg/cmd/openshift-sdn-node/cmd.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package openshift_sdn_node
22

33
import (
44
"fmt"
5-
"github.com/spf13/pflag"
65
"io"
76
"os"
87
"path/filepath"
98
"time"
109

10+
"github.com/spf13/pflag"
11+
1112
"github.com/fsnotify/fsnotify"
1213
"github.com/spf13/cobra"
1314
"k8s.io/klog/v2"
@@ -120,6 +121,10 @@ func (sdn *openShiftSDN) run(c *cobra.Command, errout io.Writer, stopCh chan str
120121
}
121122

122123
<-stopCh
124+
err = sdn.deleteConfigFile()
125+
if err != nil {
126+
klog.Errorf("unable to delete sdn cni configuration file: %v", err)
127+
}
123128
time.Sleep(500 * time.Millisecond) // gracefully shut down
124129
}
125130

pkg/cmd/openshift-sdn-node/sdn.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package openshift_sdn_node
22

33
import (
44
"io/ioutil"
5+
"os"
56

67
corev1 "k8s.io/api/core/v1"
78
"k8s.io/client-go/kubernetes/scheme"
@@ -56,3 +57,8 @@ func (sdn *openShiftSDN) writeConfigFile() error {
5657
}
5758
`), 0600)
5859
}
60+
61+
func (sdn *openShiftSDN) deleteConfigFile() error {
62+
// Delete CNI config file from disk if it's no longer able to serve CNI requests.
63+
return os.Remove(openshiftCNIFile)
64+
}

0 commit comments

Comments
 (0)