Commit f8eb179c authored by Justin Santa Barbara's avatar Justin Santa Barbara

Create hostNetwork pods even if network plugin not ready

We do now admit pods (unlike the first attempt), but now we will stop non-hostnetwork pods from starting if the network is not ready. Issue #35409
parent b4e84d3e
...@@ -1393,6 +1393,11 @@ func (kl *Kubelet) syncPod(o syncPodOptions) error { ...@@ -1393,6 +1393,11 @@ func (kl *Kubelet) syncPod(o syncPodOptions) error {
return errOuter return errOuter
} }
// If the network plugin is not ready, only start the pod if it uses the host network
if rs := kl.runtimeState.networkErrors(); len(rs) != 0 && !podUsesHostNetwork(pod) {
return fmt.Errorf("network is not ready: %v", rs)
}
// Create Cgroups for the pod and apply resource parameters // Create Cgroups for the pod and apply resource parameters
// to them if cgroup-per-qos flag is enabled. // to them if cgroup-per-qos flag is enabled.
pcm := kl.containerManager.NewPodContainerManager() pcm := kl.containerManager.NewPodContainerManager()
...@@ -1644,7 +1649,7 @@ func (kl *Kubelet) syncLoop(updates <-chan kubetypes.PodUpdate, handler SyncHand ...@@ -1644,7 +1649,7 @@ func (kl *Kubelet) syncLoop(updates <-chan kubetypes.PodUpdate, handler SyncHand
defer housekeepingTicker.Stop() defer housekeepingTicker.Stop()
plegCh := kl.pleg.Watch() plegCh := kl.pleg.Watch()
for { for {
if rs := kl.runtimeState.errors(); len(rs) != 0 { if rs := kl.runtimeState.runtimeErrors(); len(rs) != 0 {
glog.Infof("skipping pod synchronization - %v", rs) glog.Infof("skipping pod synchronization - %v", rs)
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
continue continue
......
...@@ -577,7 +577,8 @@ func (kl *Kubelet) setNodeReadyCondition(node *api.Node) { ...@@ -577,7 +577,8 @@ func (kl *Kubelet) setNodeReadyCondition(node *api.Node) {
// ref: https://github.com/kubernetes/kubernetes/issues/16961 // ref: https://github.com/kubernetes/kubernetes/issues/16961
currentTime := unversioned.NewTime(kl.clock.Now()) currentTime := unversioned.NewTime(kl.clock.Now())
var newNodeReadyCondition api.NodeCondition var newNodeReadyCondition api.NodeCondition
if rs := kl.runtimeState.errors(); len(rs) == 0 { rs := append(kl.runtimeState.runtimeErrors(), kl.runtimeState.networkErrors()...)
if len(rs) == 0 {
newNodeReadyCondition = api.NodeCondition{ newNodeReadyCondition = api.NodeCondition{
Type: api.NodeReady, Type: api.NodeReady,
Status: api.ConditionTrue, Status: api.ConditionTrue,
......
...@@ -83,6 +83,7 @@ func TestRunOnce(t *testing.T) { ...@@ -83,6 +83,7 @@ func TestRunOnce(t *testing.T) {
kubeClient: &fake.Clientset{}, kubeClient: &fake.Clientset{},
hostname: testKubeletHostname, hostname: testKubeletHostname,
nodeName: testKubeletHostname, nodeName: testKubeletHostname,
runtimeState: newRuntimeState(time.Second),
} }
kb.containerManager = cm.NewStubContainerManager() kb.containerManager = cm.NewStubContainerManager()
......
...@@ -68,16 +68,13 @@ func (s *runtimeState) setInitError(err error) { ...@@ -68,16 +68,13 @@ func (s *runtimeState) setInitError(err error) {
s.initError = err s.initError = err
} }
func (s *runtimeState) errors() []string { func (s *runtimeState) runtimeErrors() []string {
s.RLock() s.RLock()
defer s.RUnlock() defer s.RUnlock()
var ret []string var ret []string
if s.initError != nil { if s.initError != nil {
ret = append(ret, s.initError.Error()) ret = append(ret, s.initError.Error())
} }
if s.networkError != nil {
ret = append(ret, s.networkError.Error())
}
if !s.lastBaseRuntimeSync.Add(s.baseRuntimeSyncThreshold).After(time.Now()) { if !s.lastBaseRuntimeSync.Add(s.baseRuntimeSyncThreshold).After(time.Now()) {
ret = append(ret, "container runtime is down") ret = append(ret, "container runtime is down")
} }
...@@ -87,6 +84,16 @@ func (s *runtimeState) errors() []string { ...@@ -87,6 +84,16 @@ func (s *runtimeState) errors() []string {
return ret return ret
} }
func (s *runtimeState) networkErrors() []string {
s.RLock()
defer s.RUnlock()
var ret []string
if s.networkError != nil {
ret = append(ret, s.networkError.Error())
}
return ret
}
func newRuntimeState( func newRuntimeState(
runtimeSyncThreshold time.Duration, runtimeSyncThreshold time.Duration,
) *runtimeState { ) *runtimeState {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment