Skip to content

Commit afaf234

Browse files
Merge pull request openshift#15064 from pravisankar/ensure-cnidir-exits
Ensure CNI dir exists before writing openshift CNI configuration under CNI dir
2 parents a108425 + 23368fb commit afaf234

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

pkg/sdn/plugin/node.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net"
77
"os"
88
osexec "os/exec"
9+
"path/filepath"
910
"strings"
1011
"sync"
1112
"time"
@@ -38,6 +39,11 @@ import (
3839
kexec "k8s.io/kubernetes/pkg/util/exec"
3940
)
4041

42+
const (
43+
cniDirPath = "/etc/cni/net.d"
44+
openshiftCNIFile = "80-openshift-sdn.conf"
45+
)
46+
4147
type osdnPolicy interface {
4248
Name() string
4349
Start(node *OsdnNode) error
@@ -112,7 +118,7 @@ func NewNodePlugin(pluginName string, osClient *osclient.Client, kClient kclient
112118

113119
// If our CNI config file exists, remove it so that kubelet doesn't think
114120
// we're ready yet
115-
os.Remove("/etc/cni/net.d/80-openshift-sdn.conf")
121+
os.Remove(filepath.Join(cniDirPath, openshiftCNIFile))
116122

117123
log.Infof("Initializing SDN node of type %q with configured hostname %q (IP %q), iptables sync period %q", pluginName, hostname, selfIP, proxyConfig.IPTablesSyncPeriod.Duration.String())
118124
if hostname == "" {
@@ -326,13 +332,17 @@ func (node *OsdnNode) Start() error {
326332
}
327333
}
328334

335+
if err := os.MkdirAll(cniDirPath, 0755); err != nil {
336+
return err
337+
}
338+
329339
go kwait.Forever(node.policy.SyncVNIDRules, time.Hour)
330340

331341
log.V(5).Infof("openshift-sdn network plugin ready")
332342

333343
// Write our CNI config file out to disk to signal to kubelet that
334344
// our network plugin is ready
335-
return ioutil.WriteFile("/etc/cni/net.d/80-openshift-sdn.conf", []byte(`
345+
return ioutil.WriteFile(filepath.Join(cniDirPath, openshiftCNIFile), []byte(`
336346
{
337347
"cniVersion": "0.1.0",
338348
"name": "openshift-sdn",

0 commit comments

Comments
 (0)