2015-09-24 22:26:25 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015 The Kubernetes Authors All rights reserved.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package kubelet
|
|
|
|
|
|
|
|
import (
|
2015-09-25 17:49:18 +00:00
|
|
|
"fmt"
|
2015-09-24 22:26:25 +00:00
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type runtimeState struct {
|
|
|
|
sync.Mutex
|
|
|
|
lastBaseRuntimeSync time.Time
|
|
|
|
baseRuntimeSyncThreshold time.Duration
|
|
|
|
networkError error
|
2015-11-07 01:03:39 +00:00
|
|
|
internalError error
|
2015-09-25 18:00:14 +00:00
|
|
|
cidr string
|
2015-09-24 22:26:25 +00:00
|
|
|
initError error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *runtimeState) setRuntimeSync(t time.Time) {
|
|
|
|
s.Lock()
|
|
|
|
defer s.Unlock()
|
|
|
|
s.lastBaseRuntimeSync = t
|
|
|
|
}
|
|
|
|
|
2015-11-07 01:03:39 +00:00
|
|
|
func (s *runtimeState) setInternalError(err error) {
|
|
|
|
s.Lock()
|
|
|
|
defer s.Unlock()
|
|
|
|
s.internalError = err
|
|
|
|
}
|
|
|
|
|
2015-09-25 17:49:18 +00:00
|
|
|
func (s *runtimeState) setNetworkState(err error) {
|
2015-09-24 22:26:25 +00:00
|
|
|
s.Lock()
|
|
|
|
defer s.Unlock()
|
|
|
|
s.networkError = err
|
|
|
|
}
|
|
|
|
|
2015-09-25 18:00:14 +00:00
|
|
|
func (s *runtimeState) setPodCIDR(cidr string) {
|
|
|
|
s.Lock()
|
|
|
|
defer s.Unlock()
|
|
|
|
s.cidr = cidr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *runtimeState) podCIDR() string {
|
|
|
|
s.Lock()
|
|
|
|
defer s.Unlock()
|
|
|
|
return s.cidr
|
|
|
|
}
|
|
|
|
|
2015-09-24 22:26:25 +00:00
|
|
|
func (s *runtimeState) setInitError(err error) {
|
|
|
|
s.Lock()
|
|
|
|
defer s.Unlock()
|
|
|
|
s.initError = err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *runtimeState) errors() []string {
|
|
|
|
s.Lock()
|
|
|
|
defer s.Unlock()
|
|
|
|
var ret []string
|
|
|
|
if s.initError != nil {
|
|
|
|
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()) {
|
|
|
|
ret = append(ret, "container runtime is down")
|
|
|
|
}
|
2015-11-07 01:03:39 +00:00
|
|
|
if s.internalError != nil {
|
|
|
|
ret = append(ret, s.internalError.Error())
|
|
|
|
}
|
2015-09-24 22:26:25 +00:00
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2015-11-07 01:03:39 +00:00
|
|
|
func newRuntimeState(
|
|
|
|
runtimeSyncThreshold time.Duration,
|
|
|
|
) *runtimeState {
|
2015-09-24 22:26:25 +00:00
|
|
|
return &runtimeState{
|
|
|
|
lastBaseRuntimeSync: time.Time{},
|
|
|
|
baseRuntimeSyncThreshold: runtimeSyncThreshold,
|
2016-04-22 22:23:03 +00:00
|
|
|
networkError: fmt.Errorf("network state unknown"),
|
2015-11-07 01:03:39 +00:00
|
|
|
internalError: nil,
|
2015-09-24 22:26:25 +00:00
|
|
|
}
|
|
|
|
}
|