Skip to content

Ensure CNI dir exists before writing openshift CNI configuration under CNI dir #15064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions pkg/sdn/plugin/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"os"
osexec "os/exec"
"path/filepath"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -38,6 +39,11 @@ import (
kexec "k8s.io/kubernetes/pkg/util/exec"
)

const (
cniDirPath = "/etc/cni/net.d"
openshiftCNIFile = "80-openshift-sdn.conf"
)

type osdnPolicy interface {
Name() string
Start(node *OsdnNode) error
Expand Down Expand Up @@ -112,7 +118,7 @@ func NewNodePlugin(pluginName string, osClient *osclient.Client, kClient kclient

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

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())
if hostname == "" {
Expand Down Expand Up @@ -326,13 +332,17 @@ func (node *OsdnNode) Start() error {
}
}

if err := os.MkdirAll(cniDirPath, 0755); err != nil {
return err
}

go kwait.Forever(node.policy.SyncVNIDRules, time.Hour)

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

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