@@ -86,6 +86,16 @@ func (k *Klocksmith) process(stop <-chan struct{}) error {
8686 return fmt .Errorf ("failed to set node info: %v" , err )
8787 }
8888
89+ glog .Info ("Checking annotations" )
90+ node , err := k8sutil .GetNodeRetry (k .nc , k .node )
91+ if err != nil {
92+ return err
93+ }
94+
95+ // Only make a node schedulable if a reboot was in progress. This prevents a node from being made schedulable
96+ // if it was made unschedulable by something other thin the agent
97+ makeSchedulable := node .Annotations [constants .AnnotationAgentMadeUnschedulable ] == constants .True
98+
8999 // set coreos.com/update1/reboot-in-progress=false and
90100 // coreos.com/update1/reboot-needed=false
91101 anno := map [string ]string {
@@ -106,10 +116,14 @@ func (k *Klocksmith) process(stop <-chan struct{}) error {
106116 return err
107117 }
108118
109- // we are schedulable now.
110- glog .Info ("Marking node as schedulable" )
111- if err := k8sutil .Unschedulable (k .nc , k .node , false ); err != nil {
112- return err
119+ if makeSchedulable {
120+ // we are schedulable now.
121+ glog .Info ("Marking node as schedulable" )
122+ if err := k8sutil .Unschedulable (k .nc , k .node , false ); err != nil {
123+ return err
124+ }
125+ } else {
126+ glog .Info ("Skipping marking node as schedulable -- node was unschedulable prior to update reboot" )
113127 }
114128
115129 // watch update engine for status updates
@@ -136,16 +150,36 @@ func (k *Klocksmith) process(stop <-chan struct{}) error {
136150 return err
137151 }
138152
153+ glog .Info ("Checking if node is already unschedulable" )
154+ node , err = k8sutil .GetNodeRetry (k .nc , k .node )
155+ if err != nil {
156+ return err
157+ }
158+ alreadyUnschedulable := node .Spec .Unschedulable
159+
139160 // drain self equates to:
140- // 1. set Unschedulable
161+ // 1. set Unschedulable if necessary
141162 // 2. delete all pods
142163 // unlike `kubectl drain`, we do not care about emptyDir or orphan pods
143164 // ('any pods that are neither mirror pods nor managed by
144165 // ReplicationController, ReplicaSet, DaemonSet or Job')
145166
146- glog .Info ("Marking node as unschedulable" )
147- if err := k8sutil .Unschedulable (k .nc , k .node , true ); err != nil {
148- return err
167+ if alreadyUnschedulable == false {
168+ glog .Info ("Marking node as unschedulable" )
169+ if err := k8sutil .Unschedulable (k .nc , k .node , true ); err != nil {
170+ return err
171+ }
172+
173+ // set constants.AnnotationRebootInProgress and drain self
174+ anno = map [string ]string {
175+ constants .AnnotationAgentMadeUnschedulable : constants .True ,
176+ }
177+
178+ if err := k8sutil .SetNodeAnnotations (k .nc , k .node , anno ); err != nil {
179+ return err
180+ }
181+ } else {
182+ glog .Info ("Node already marked as unschedulable" )
149183 }
150184
151185 glog .Info ("Getting pod list for deletion" )
0 commit comments