diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 8fa61fe642f..ec6331af925 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.NetworkStatus()) } // 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/kubenet/kubenet_linux.go b/pkg/kubelet/network/kubenet/kubenet_linux.go index 63b12a24e65..35c8e9bf30a 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.NetworkStatus(); err != nil { + return fmt.Errorf("Kubenet cannot SetUpPod: %v", err) } runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager) @@ -310,6 +309,14 @@ func (plugin *kubenetNetworkPlugin) Status(namespace string, name string, id kub return &network.PodNetworkStatus{IP: ip}, nil } +func (plugin *kubenetNetworkPlugin) NetworkStatus() 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/plugins.go b/pkg/kubelet/network/plugins.go index 6198098fd1e..35629754035 100644 --- a/pkg/kubelet/network/plugins.go +++ b/pkg/kubelet/network/plugins.go @@ -74,6 +74,9 @@ type NetworkPlugin interface { // 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) + + // NetworkStatus returns error if the network plugin is in error state + NetworkStatus() error } // PodNetworkStatus stores the network status of a pod (currently just the primary IP address) @@ -191,3 +194,7 @@ func (plugin *NoopNetworkPlugin) TearDownPod(namespace string, name string, id k func (plugin *NoopNetworkPlugin) Status(namespace string, name string, id kubecontainer.ContainerID) (*PodNetworkStatus, error) { return nil, nil } + +func (plugin *NoopNetworkPlugin) NetworkStatus() 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, } }