Merge pull request #24693 from freehan/kubenetbootstrapfix

add NetworkStatus in NetworkPlugin interface for kubelet to consume
This commit is contained in:
Dawn Chen 2016-05-04 16:51:27 -07:00
commit e09ce3668b
10 changed files with 36 additions and 21 deletions

View File

@ -326,7 +326,7 @@ func (dm *DockerManager) determineContainerIP(podNamespace, podName string, cont
} }
if dm.networkPlugin.Name() != network.DefaultPluginName { if dm.networkPlugin.Name() != network.DefaultPluginName {
netStatus, err := dm.networkPlugin.Status(podNamespace, podName, kubecontainer.DockerID(container.ID).ContainerID()) netStatus, err := dm.networkPlugin.GetPodNetworkStatus(podNamespace, podName, kubecontainer.DockerID(container.ID).ContainerID())
if err != nil { if err != nil {
glog.Errorf("NetworkPlugin %s failed on the status hook for pod '%s' - %v", dm.networkPlugin.Name(), podName, err) glog.Errorf("NetworkPlugin %s failed on the status hook for pod '%s' - %v", dm.networkPlugin.Name(), podName, err)
} else if netStatus != nil { } else if netStatus != nil {

View File

@ -443,7 +443,7 @@ func NewMainKubelet(
klet.resourceAnalyzer = stats.NewResourceAnalyzer(klet, volumeStatsAggPeriod, klet.containerRuntime) klet.resourceAnalyzer = stats.NewResourceAnalyzer(klet, volumeStatsAggPeriod, klet.containerRuntime)
klet.pleg = pleg.NewGenericPLEG(klet.containerRuntime, plegChannelCapacity, plegRelistPeriod, klet.podCache, util.RealClock{}) klet.pleg = pleg.NewGenericPLEG(klet.containerRuntime, plegChannelCapacity, plegRelistPeriod, klet.podCache, util.RealClock{})
klet.runtimeState = newRuntimeState(maxWaitForContainerRuntime, configureCBR0) klet.runtimeState = newRuntimeState(maxWaitForContainerRuntime)
klet.updatePodCIDR(podCIDR) klet.updatePodCIDR(podCIDR)
// setup containerGC // setup containerGC
@ -3001,8 +3001,13 @@ func (kl *Kubelet) syncNetworkStatus() {
err = fmt.Errorf("Error configuring cbr0: %v", err) err = fmt.Errorf("Error configuring cbr0: %v", err)
glog.Error(err) glog.Error(err)
} }
if err != nil {
kl.runtimeState.setNetworkState(err)
return
}
} }
kl.runtimeState.setNetworkState(err)
kl.runtimeState.setNetworkState(kl.networkPlugin.Status())
} }
// Set addresses for the node. // Set addresses for the node.

View File

@ -125,7 +125,8 @@ func newTestKubelet(t *testing.T) *TestKubelet {
kubelet.hostname = testKubeletHostname kubelet.hostname = testKubeletHostname
kubelet.nodeName = testKubeletHostname kubelet.nodeName = testKubeletHostname
kubelet.runtimeState = newRuntimeState(maxWaitForContainerRuntime, false) kubelet.runtimeState = newRuntimeState(maxWaitForContainerRuntime)
kubelet.runtimeState.setNetworkState(nil)
kubelet.networkPlugin, _ = network.InitNetworkPlugin([]network.NetworkPlugin{}, "", nettest.NewFakeHost(nil)) kubelet.networkPlugin, _ = network.InitNetworkPlugin([]network.NetworkPlugin{}, "", nettest.NewFakeHost(nil))
if tempDir, err := ioutil.TempDir("/tmp", "kubelet_test."); err != nil { if tempDir, err := ioutil.TempDir("/tmp", "kubelet_test."); err != nil {
t.Fatalf("can't make a temp rootdir: %v", err) t.Fatalf("can't make a temp rootdir: %v", err)

View File

@ -136,7 +136,7 @@ func (plugin *cniNetworkPlugin) TearDownPod(namespace string, name string, id ku
// TODO: Use the addToNetwork function to obtain the IP of the Pod. That will assume idempotent ADD call to the plugin. // TODO: Use the addToNetwork function to obtain the IP of the Pod. That will assume idempotent ADD call to the plugin.
// Also fix the runtime's call to Status function to be done only in the case that the IP is lost, no need to do periodic calls // Also fix the runtime's call to Status function to be done only in the case that the IP is lost, no need to do periodic calls
func (plugin *cniNetworkPlugin) Status(namespace string, name string, id kubecontainer.ContainerID) (*network.PodNetworkStatus, error) { func (plugin *cniNetworkPlugin) GetPodNetworkStatus(namespace string, name string, id kubecontainer.ContainerID) (*network.PodNetworkStatus, error) {
runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager) runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager)
if !ok { if !ok {
return nil, fmt.Errorf("CNI execution called on non-docker runtime") return nil, fmt.Errorf("CNI execution called on non-docker runtime")

View File

@ -146,7 +146,7 @@ func (plugin *execNetworkPlugin) TearDownPod(namespace string, name string, id k
return err return err
} }
func (plugin *execNetworkPlugin) Status(namespace string, name string, id kubecontainer.ContainerID) (*network.PodNetworkStatus, error) { func (plugin *execNetworkPlugin) GetPodNetworkStatus(namespace string, name string, id kubecontainer.ContainerID) (*network.PodNetworkStatus, error) {
out, err := utilexec.New().Command(plugin.getExecutable(), statusCmd, namespace, name, id.ID).CombinedOutput() out, err := utilexec.New().Command(plugin.getExecutable(), statusCmd, namespace, name, id.ID).CombinedOutput()
glog.V(5).Infof("Status 'exec' network plugin output: %s, %v", string(out), err) glog.V(5).Infof("Status 'exec' network plugin output: %s, %v", string(out), err)
if err != nil { if err != nil {

View File

@ -281,7 +281,7 @@ func TestPluginStatusHook(t *testing.T) {
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil)) plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil))
ip, err := plug.Status("namespace", "name", kubecontainer.ContainerID{Type: "docker", ID: "dockerid2345"}) ip, err := plug.GetPodNetworkStatus("namespace", "name", kubecontainer.ContainerID{Type: "docker", ID: "dockerid2345"})
if err != nil { if err != nil {
t.Errorf("Expected nil got %v", err) t.Errorf("Expected nil got %v", err)
} }
@ -320,7 +320,7 @@ func TestPluginStatusHookIPv6(t *testing.T) {
t.Errorf("InitNetworkPlugin() failed: %v", err) t.Errorf("InitNetworkPlugin() failed: %v", err)
} }
ip, err := plug.Status("namespace", "name", kubecontainer.ContainerID{Type: "docker", ID: "dockerid2345"}) ip, err := plug.GetPodNetworkStatus("namespace", "name", kubecontainer.ContainerID{Type: "docker", ID: "dockerid2345"})
if err != nil { if err != nil {
t.Errorf("Status() failed: %v", err) t.Errorf("Status() failed: %v", err)
} }

View File

@ -215,9 +215,8 @@ func (plugin *kubenetNetworkPlugin) SetUpPod(namespace string, name string, id k
return fmt.Errorf("Error reading pod bandwidth annotations: %v", err) return fmt.Errorf("Error reading pod bandwidth annotations: %v", err)
} }
// Can't set up pods if we don't have a PodCIDR yet if err := plugin.Status(); err != nil {
if plugin.netConfig == nil { return fmt.Errorf("Kubenet cannot SetUpPod: %v", err)
return fmt.Errorf("Kubenet needs a PodCIDR to set up pods")
} }
runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager) runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager)
@ -295,7 +294,7 @@ func (plugin *kubenetNetworkPlugin) TearDownPod(namespace string, name string, i
// TODO: Use the addToNetwork function to obtain the IP of the Pod. That will assume idempotent ADD call to the plugin. // TODO: Use the addToNetwork function to obtain the IP of the Pod. That will assume idempotent ADD call to the plugin.
// Also fix the runtime's call to Status function to be done only in the case that the IP is lost, no need to do periodic calls // Also fix the runtime's call to Status function to be done only in the case that the IP is lost, no need to do periodic calls
func (plugin *kubenetNetworkPlugin) Status(namespace string, name string, id kubecontainer.ContainerID) (*network.PodNetworkStatus, error) { func (plugin *kubenetNetworkPlugin) GetPodNetworkStatus(namespace string, name string, id kubecontainer.ContainerID) (*network.PodNetworkStatus, error) {
plugin.mu.Lock() plugin.mu.Lock()
defer plugin.mu.Unlock() defer plugin.mu.Unlock()
cidr, ok := plugin.podCIDRs[id] cidr, ok := plugin.podCIDRs[id]
@ -310,6 +309,14 @@ func (plugin *kubenetNetworkPlugin) Status(namespace string, name string, id kub
return &network.PodNetworkStatus{IP: ip}, nil return &network.PodNetworkStatus{IP: ip}, nil
} }
func (plugin *kubenetNetworkPlugin) Status() error {
// Can't set up pods if we don't have a PodCIDR yet
if plugin.netConfig == nil {
return fmt.Errorf("Kubenet does not have netConfig. This is most likely due to lack of PodCIDR")
}
return nil
}
func buildCNIRuntimeConf(podName string, podNs string, podInfraContainerID kubecontainer.ContainerID, podNetnsPath string) *libcni.RuntimeConf { func buildCNIRuntimeConf(podName string, podNs string, podInfraContainerID kubecontainer.ContainerID, podNetnsPath string) *libcni.RuntimeConf {
glog.V(4).Infof("Kubenet: using netns path %v", podNetnsPath) glog.V(4).Infof("Kubenet: using netns path %v", podNetnsPath)
glog.V(4).Infof("Kubenet: using podns path %v", podNs) glog.V(4).Infof("Kubenet: using podns path %v", podNs)

View File

@ -49,6 +49,6 @@ func (plugin *kubenetNetworkPlugin) TearDownPod(namespace string, name string, i
return fmt.Errorf("Kubenet is not supported in this build") return fmt.Errorf("Kubenet is not supported in this build")
} }
func (plugin *kubenetNetworkPlugin) Status(namespace string, name string, id kubecontainer.ContainerID) (*network.PodNetworkStatus, error) { func (plugin *kubenetNetworkPlugin) GetPodNetworkStatus(namespace string, name string, id kubecontainer.ContainerID) (*network.PodNetworkStatus, error) {
return nil, fmt.Errorf("Kubenet is not supported in this build") return nil, fmt.Errorf("Kubenet is not supported in this build")
} }

View File

@ -73,7 +73,10 @@ type NetworkPlugin interface {
TearDownPod(namespace string, name string, podInfraContainerID kubecontainer.ContainerID) error TearDownPod(namespace string, name string, podInfraContainerID kubecontainer.ContainerID) error
// Status is the method called to obtain the ipv4 or ipv6 addresses of the container // Status is the method called to obtain the ipv4 or ipv6 addresses of the container
Status(namespace string, name string, podInfraContainerID kubecontainer.ContainerID) (*PodNetworkStatus, error) GetPodNetworkStatus(namespace string, name string, podInfraContainerID kubecontainer.ContainerID) (*PodNetworkStatus, error)
// NetworkStatus returns error if the network plugin is in error state
Status() error
} }
// PodNetworkStatus stores the network status of a pod (currently just the primary IP address) // PodNetworkStatus stores the network status of a pod (currently just the primary IP address)
@ -188,6 +191,10 @@ func (plugin *NoopNetworkPlugin) TearDownPod(namespace string, name string, id k
return nil return nil
} }
func (plugin *NoopNetworkPlugin) Status(namespace string, name string, id kubecontainer.ContainerID) (*PodNetworkStatus, error) { func (plugin *NoopNetworkPlugin) GetPodNetworkStatus(namespace string, name string, id kubecontainer.ContainerID) (*PodNetworkStatus, error) {
return nil, nil return nil, nil
} }
func (plugin *NoopNetworkPlugin) Status() error {
return nil
}

View File

@ -89,16 +89,11 @@ func (s *runtimeState) errors() []string {
func newRuntimeState( func newRuntimeState(
runtimeSyncThreshold time.Duration, runtimeSyncThreshold time.Duration,
configureNetwork bool,
) *runtimeState { ) *runtimeState {
var networkError error = nil
if configureNetwork {
networkError = fmt.Errorf("network state unknown")
}
return &runtimeState{ return &runtimeState{
lastBaseRuntimeSync: time.Time{}, lastBaseRuntimeSync: time.Time{},
baseRuntimeSyncThreshold: runtimeSyncThreshold, baseRuntimeSyncThreshold: runtimeSyncThreshold,
networkError: networkError, networkError: fmt.Errorf("network state unknown"),
internalError: nil, internalError: nil,
} }
} }