Skip to content

Commit

Permalink
sdn: wait for kubelet network plugin init before processing pods
Browse files Browse the repository at this point in the history
We need the kubelet network Host object before we can update pods, so
wait for it.
  • Loading branch information
dcbw committed Oct 27, 2016
1 parent d861f06 commit 75252d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions pkg/sdn/plugin/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type OsdnNode struct {
localIP string
hostName string
podNetworkReady chan struct{}
kubeletInitReady chan struct{}
vnids *nodeVNIDMap
iptablesSyncPeriod time.Duration
mtu uint32
Expand Down Expand Up @@ -96,6 +97,7 @@ func NewNodePlugin(pluginName string, osClient *osclient.Client, kClient *kclien
hostName: hostname,
vnids: newNodeVNIDMap(),
podNetworkReady: make(chan struct{}),
kubeletInitReady: make(chan struct{}),
iptablesSyncPeriod: iptablesSyncPeriod,
mtu: mtu,
egressPolicies: make(map[uint32][]*osapi.EgressNetworkPolicy),
Expand Down Expand Up @@ -203,6 +205,7 @@ func (node *OsdnNode) Start() error {
}
}

log.V(5).Infof("Creating and initializing openshift-sdn pod manager")
node.podManager, err = newPodManager(node.host, node.multitenant, node.localSubnetCIDR, node.networkInfo, node.kClient, node.vnids, node.mtu)
if err != nil {
return err
Expand All @@ -211,6 +214,10 @@ func (node *OsdnNode) Start() error {
return err
}

// Wait for kubelet to init the plugin so we get a knetwork.Host
log.V(5).Infof("Waiting for kubelet network plugin initialization")
<-node.kubeletInitReady

if networkChanged {
var pods []kapi.Pod
pods, err = node.GetLocalPods(kapi.NamespaceAll)
Expand All @@ -226,6 +233,7 @@ func (node *OsdnNode) Start() error {
}
}

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

return nil
Expand Down
10 changes: 9 additions & 1 deletion pkg/sdn/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
knetwork "k8s.io/kubernetes/pkg/kubelet/network"
kcni "k8s.io/kubernetes/pkg/kubelet/network/cni"
utilsets "k8s.io/kubernetes/pkg/util/sets"

"github.com/golang/glog"
)

// This kubelet network plugin shim only exists to grab the knetwork.Host
Expand All @@ -22,7 +24,13 @@ func (node *OsdnNode) Init(host knetwork.Host, hairpinMode componentconfig.Hairp
node.host = host
node.kubeletCniPlugin = plugins[0]

return node.kubeletCniPlugin.Init(host, hairpinMode, nonMasqueradeCIDR, mtu)
err := node.kubeletCniPlugin.Init(host, hairpinMode, nonMasqueradeCIDR, mtu)

// Let initial pod updates happen if they need to
glog.V(5).Infof("openshift-sdn CNI plugin initialized")
close(node.kubeletInitReady)

return err
}

func (node *OsdnNode) Name() string {
Expand Down

0 comments on commit 75252d7

Please sign in to comment.