Skip to content
This repository was archived by the owner on Sep 18, 2020. It is now read-only.

Commit 620da75

Browse files
committed
pkg/agent: reorder annotation and label logic for agent-made-unschedulable annotation
1 parent 8d9ae52 commit 620da75

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

pkg/agent/agent.go

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,16 @@ func (k *Klocksmith) process(stop <-chan struct{}) error {
123123
return err
124124
}
125125
} else {
126-
glog.Info("Skipping marking node as schedulable -- node was unschedulable prior to update reboot")
126+
glog.Info("Skipping marking node as schedulable -- node was marked unschedulable by an external source")
127+
}
128+
129+
anno = map[string]string{
130+
constants.AnnotationAgentMadeUnschedulable: constants.False,
131+
}
132+
133+
glog.Infof("Setting annotations %#v", anno)
134+
if err := k8sutil.SetNodeAnnotations(k.nc, k.node, anno); err != nil {
135+
return err
127136
}
128137

129138
// watch update engine for status updates
@@ -140,22 +149,26 @@ func (k *Klocksmith) process(stop <-chan struct{}) error {
140149
glog.Warningf("error waiting for an ok-to-reboot: %v", err)
141150
}
142151

152+
glog.Info("Checking if node is already unschedulable")
153+
node, err = k8sutil.GetNodeRetry(k.nc, k.node)
154+
if err != nil {
155+
return err
156+
}
157+
alreadyUnschedulable := node.Spec.Unschedulable
158+
143159
// set constants.AnnotationRebootInProgress and drain self
144160
anno = map[string]string{
145161
constants.AnnotationRebootInProgress: constants.True,
146162
}
147163

148-
glog.Infof("Setting annotations %#v", anno)
149-
if err := k8sutil.SetNodeAnnotations(k.nc, k.node, anno); err != nil {
150-
return err
164+
if !alreadyUnschedulable {
165+
anno[constants.AnnotationAgentMadeUnschedulable] = constants.True
151166
}
152167

153-
glog.Info("Checking if node is already unschedulable")
154-
node, err = k8sutil.GetNodeRetry(k.nc, k.node)
155-
if err != nil {
168+
glog.Infof("Setting annotations %#v", anno)
169+
if err := k8sutil.SetNodeAnnotations(k.nc, k.node, anno); err != nil {
156170
return err
157171
}
158-
alreadyUnschedulable := node.Spec.Unschedulable
159172

160173
// drain self equates to:
161174
// 1. set Unschedulable if necessary
@@ -164,20 +177,11 @@ func (k *Klocksmith) process(stop <-chan struct{}) error {
164177
// ('any pods that are neither mirror pods nor managed by
165178
// ReplicationController, ReplicaSet, DaemonSet or Job')
166179

167-
if alreadyUnschedulable == false {
180+
if !alreadyUnschedulable {
168181
glog.Info("Marking node as unschedulable")
169182
if err := k8sutil.Unschedulable(k.nc, k.node, true); err != nil {
170183
return err
171184
}
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-
}
181185
} else {
182186
glog.Info("Node already marked as unschedulable")
183187
}

pkg/k8sutil/retry.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,8 @@ func RetryOnError(backoff wait.Backoff, fn func() error) error {
8585
var lastErr error
8686
err := wait.ExponentialBackoff(backoff, func() (bool, error) {
8787
lastErr := fn()
88-
if lastErr == nil {
89-
return true, nil
90-
}
9188

92-
return false, nil
89+
return lastErr == nil, nil
9390
})
9491

9592
if err == wait.ErrWaitTimeout {

0 commit comments

Comments
 (0)