diff --git a/pkg/kubelet/dockertools/manager.go b/pkg/kubelet/dockertools/manager.go index 9fc47030c95..544cd3b5e2c 100644 --- a/pkg/kubelet/dockertools/manager.go +++ b/pkg/kubelet/dockertools/manager.go @@ -326,7 +326,7 @@ func (dm *DockerManager) determineContainerIP(podNamespace, podName string, cont } 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 { glog.Errorf("NetworkPlugin %s failed on the status hook for pod '%s' - %v", dm.networkPlugin.Name(), podName, err) } else if netStatus != nil { diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 8fa61fe642f..18fca693c10 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -443,7 +443,7 @@ func NewMainKubelet( klet.resourceAnalyzer = stats.NewResourceAnalyzer(klet, volumeStatsAggPeriod, klet.containerRuntime) klet.pleg = pleg.NewGenericPLEG(klet.containerRuntime, plegChannelCapacity, plegRelistPeriod, klet.podCache, util.RealClock{}) - klet.runtimeState = newRuntimeState(maxWaitForContainerRuntime, configureCBR0) + klet.runtimeState = newRuntimeState(maxWaitForContainerRuntime) klet.updatePodCIDR(podCIDR) // setup containerGC @@ -3001,8 +3001,13 @@ func (kl *Kubelet) syncNetworkStatus() { err = fmt.Errorf("Error configuring cbr0: %v", 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. diff --git a/pkg/kubelet/kubelet_test.go b/pkg/kubelet/kubelet_test.go index de92dd462c9..fd33216257f 100644 --- a/pkg/kubelet/kubelet_test.go +++ b/pkg/kubelet/kubelet_test.go @@ -125,7 +125,8 @@ func newTestKubelet(t *testing.T) *TestKubelet { kubelet.hostname = 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)) if tempDir, err := ioutil.TempDir("/tmp", "kubelet_test."); err != nil { t.Fatalf("can't make a temp rootdir: %v", err) diff --git a/pkg/kubelet/network/cni/cni.go b/pkg/kubelet/network/cni/cni.go index daa9c8bf8fe..43b6ef8992b 100644 --- a/pkg/kubelet/network/cni/cni.go +++ b/pkg/kubelet/network/cni/cni.go @@ -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. // 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) if !ok { return nil, fmt.Errorf("CNI execution called on non-docker runtime") diff --git a/pkg/kubelet/network/exec/exec.go b/pkg/kubelet/network/exec/exec.go index 776cfd99377..d9eb987e949 100644 --- a/pkg/kubelet/network/exec/exec.go +++ b/pkg/kubelet/network/exec/exec.go @@ -146,7 +146,7 @@ func (plugin *execNetworkPlugin) TearDownPod(namespace string, name string, id k 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() glog.V(5).Infof("Status 'exec' network plugin output: %s, %v", string(out), err) if err != nil { diff --git a/pkg/kubelet/network/exec/exec_test.go b/pkg/kubelet/network/exec/exec_test.go index 42cbc3065f2..348d746a4b9 100644 --- a/pkg/kubelet/network/exec/exec_test.go +++ b/pkg/kubelet/network/exec/exec_test.go @@ -281,7 +281,7 @@ func TestPluginStatusHook(t *testing.T) { 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 { t.Errorf("Expected nil got %v", err) } @@ -320,7 +320,7 @@ func TestPluginStatusHookIPv6(t *testing.T) { 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 { t.Errorf("Status() failed: %v", err) } diff --git a/pkg/kubelet/network/kubenet/kubenet_linux.go b/pkg/kubelet/network/kubenet/kubenet_linux.go index 63b12a24e65..34165d83218 100644 --- a/pkg/kubelet/network/kubenet/kubenet_linux.go +++ b/pkg/kubelet/network/kubenet/kubenet_linux.go @@ -215,9 +215,8 @@ func (plugin *kubenetNetworkPlugin) SetUpPod(namespace string, name string, id k return fmt.Errorf("Error reading pod bandwidth annotations: %v", err) } - // Can't set up pods if we don't have a PodCIDR yet - if plugin.netConfig == nil { - return fmt.Errorf("Kubenet needs a PodCIDR to set up pods") + if err := plugin.Status(); err != nil { + return fmt.Errorf("Kubenet cannot SetUpPod: %v", err) } 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. // 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() defer plugin.mu.Unlock() 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 } +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 { glog.V(4).Infof("Kubenet: using netns path %v", podNetnsPath) glog.V(4).Infof("Kubenet: using podns path %v", podNs) diff --git a/pkg/kubelet/network/kubenet/kubenet_unsupported.go b/pkg/kubelet/network/kubenet/kubenet_unsupported.go index 04f534730a1..c52642f3d15 100644 --- a/pkg/kubelet/network/kubenet/kubenet_unsupported.go +++ b/pkg/kubelet/network/kubenet/kubenet_unsupported.go @@ -49,6 +49,6 @@ func (plugin *kubenetNetworkPlugin) TearDownPod(namespace string, name string, i 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") } diff --git a/pkg/kubelet/network/plugins.go b/pkg/kubelet/network/plugins.go index 6198098fd1e..38e79e19b57 100644 --- a/pkg/kubelet/network/plugins.go +++ b/pkg/kubelet/network/plugins.go @@ -73,7 +73,10 @@ type NetworkPlugin interface { 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(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) @@ -188,6 +191,10 @@ func (plugin *NoopNetworkPlugin) TearDownPod(namespace string, name string, id k 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 } + +func (plugin *NoopNetworkPlugin) Status() error { + return nil +} diff --git a/pkg/kubelet/runtime.go b/pkg/kubelet/runtime.go index 9b26f11166e..63dd0136363 100644 --- a/pkg/kubelet/runtime.go +++ b/pkg/kubelet/runtime.go @@ -89,16 +89,11 @@ func (s *runtimeState) errors() []string { func newRuntimeState( runtimeSyncThreshold time.Duration, - configureNetwork bool, ) *runtimeState { - var networkError error = nil - if configureNetwork { - networkError = fmt.Errorf("network state unknown") - } return &runtimeState{ lastBaseRuntimeSync: time.Time{}, baseRuntimeSyncThreshold: runtimeSyncThreshold, - networkError: networkError, + networkError: fmt.Errorf("network state unknown"), internalError: nil, } }