move oldNodeUnschedulable pkg var to kubelet struct

pull/8/head
xuzhonghu 2018-05-30 11:57:37 +08:00
parent 57b8fda91b
commit 9492cf368e
2 changed files with 8 additions and 12 deletions

View File

@ -1091,6 +1091,10 @@ type Kubelet struct {
// handlers called during the tryUpdateNodeStatus cycle // handlers called during the tryUpdateNodeStatus cycle
setNodeStatusFuncs []func(*v1.Node) error setNodeStatusFuncs []func(*v1.Node) error
lastNodeUnschedulableLock sync.Mutex
// maintains Node.Spec.Unschedulable value from previous run of tryUpdateNodeStatus()
lastNodeUnschedulable bool
// TODO: think about moving this to be centralized in PodWorkers in follow-on. // TODO: think about moving this to be centralized in PodWorkers in follow-on.
// the list of handlers to call during pod admission. // the list of handlers to call during pod admission.
admitHandlers lifecycle.PodAdmitHandlers admitHandlers lifecycle.PodAdmitHandlers

View File

@ -23,7 +23,6 @@ import (
"net" "net"
goruntime "runtime" goruntime "runtime"
"strings" "strings"
"sync"
"time" "time"
"github.com/golang/glog" "github.com/golang/glog"
@ -1034,24 +1033,17 @@ func (kl *Kubelet) setNodeOODCondition(node *v1.Node) {
} }
} }
// Maintains Node.Spec.Unschedulable value from previous run of tryUpdateNodeStatus()
// TODO: why is this a package var?
var (
oldNodeUnschedulable bool
oldNodeUnschedulableLock sync.Mutex
)
// record if node schedulable change. // record if node schedulable change.
func (kl *Kubelet) recordNodeSchedulableEvent(node *v1.Node) { func (kl *Kubelet) recordNodeSchedulableEvent(node *v1.Node) {
oldNodeUnschedulableLock.Lock() kl.lastNodeUnschedulableLock.Lock()
defer oldNodeUnschedulableLock.Unlock() defer kl.lastNodeUnschedulableLock.Unlock()
if oldNodeUnschedulable != node.Spec.Unschedulable { if kl.lastNodeUnschedulable != node.Spec.Unschedulable {
if node.Spec.Unschedulable { if node.Spec.Unschedulable {
kl.recordNodeStatusEvent(v1.EventTypeNormal, events.NodeNotSchedulable) kl.recordNodeStatusEvent(v1.EventTypeNormal, events.NodeNotSchedulable)
} else { } else {
kl.recordNodeStatusEvent(v1.EventTypeNormal, events.NodeSchedulable) kl.recordNodeStatusEvent(v1.EventTypeNormal, events.NodeSchedulable)
} }
oldNodeUnschedulable = node.Spec.Unschedulable kl.lastNodeUnschedulable = node.Spec.Unschedulable
} }
} }