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

Commit 2f96731

Browse files
committed
pkg/agent: Make a node schedulable only if the agent made it unschedulable. This is accomplished using a new annotation
1 parent bf66334 commit 2f96731

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

pkg/agent/agent.go

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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")

pkg/constants/constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ const (
5252
// It is an opaque string, but might be semver.
5353
AnnotationNewVersion = Prefix + "new-version"
5454

55+
// Ket set by update-agent to indicate it was responsible for making node unschedulable
56+
AnnotationAgentMadeUnschedulable = Prefix + "agent-made-unschedulable"
57+
5558
// Keys set to true when the operator is waiting for configured annotation
5659
// before and after the reboot repectively
5760
LabelBeforeReboot = Prefix + "before-reboot"

0 commit comments

Comments
 (0)