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

Commit 420190e

Browse files
authored
Merge pull request #168 from squeed/update-staged-label
agent: set a label when after successful os-update
2 parents 60bd412 + b9ba316 commit 420190e

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

doc/labels-and-annotations.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ A few labels may be set directly by admins to customize behavior. These are call
3030
| id | coreos | update-agent | Reflects the ID in `/etc/os-release` |
3131
| version | 1497.7.0 | update-agent | Reflects the VERSION in `/etc/os-release` |
3232
| group | stable | update-agent | Reflects the GROUP in `/usr/share/coreos/update.conf` or `/etc/coreos/update.conf` |
33+
| reboot-needed | true | update-agent | Reflects the reboot-needed annotation |
3334

3435
**Annotations**
3536

3637
| name | example | setter | description |
3738
|------|---------|------------------|-------------|
38-
| reboot-needed | true/false | update-agent | Set to true to request a coordinated reboot |
39+
| reboot-needed | true/false | update-agent | Updates to true to request a coordinated reboot from the operator |
3940
| reboot-in-progress | true/false | update-agent | Set to true to indicate a reboot is in progress |
4041
| status | UPDATE_STATUS_IDLE | update-agent | Reflects the `update_engine` CurrentOperation status value |
4142
| new-version | 0.0.0 | update-agent | Reflects the `update_engine` NewVersion status value |

pkg/agent/agent.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,14 @@ func (k *Klocksmith) process(stop <-chan struct{}) error {
9292
constants.AnnotationRebootInProgress: constants.False,
9393
constants.AnnotationRebootNeeded: constants.False,
9494
}
95+
labels := map[string]string{
96+
constants.LabelRebootNeeded: constants.False,
97+
}
9598
glog.Infof("Setting annotations %#v", anno)
96-
if err := k8sutil.SetNodeAnnotations(k.nc, k.node, anno); err != nil {
99+
if err := k8sutil.SetNodeAnnotationsLabels(k.nc, k.node, anno, labels); err != nil {
97100
return err
98101
}
102+
99103
// Since we set 'reboot-needed=false', 'ok-to-reboot' should clear.
100104
// Wait for it to do so, else we might start reboot-looping
101105
if err := k.waitForNotOkToReboot(); err != nil {
@@ -199,14 +203,17 @@ func (k *Klocksmith) updateStatusCallback(s updateengine.Status) {
199203
constants.AnnotationNewVersion: s.NewVersion,
200204
}
201205

206+
labels := map[string]string{}
207+
202208
// indicate we need a reboot
203209
if s.CurrentOperation == updateengine.UpdateStatusUpdatedNeedReboot {
204210
glog.Info("Indicating a reboot is needed")
205211
anno[constants.AnnotationRebootNeeded] = constants.True
212+
labels[constants.LabelRebootNeeded] = constants.True
206213
}
207214

208215
wait.PollUntil(defaultPollInterval, func() (bool, error) {
209-
if err := k8sutil.SetNodeAnnotations(k.nc, k.node, anno); err != nil {
216+
if err := k8sutil.SetNodeAnnotationsLabels(k.nc, k.node, anno, labels); err != nil {
210217
glog.Errorf("Failed to set annotation %q: %v", constants.AnnotationStatus, err)
211218
return false, nil
212219
}

pkg/constants/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const (
1212

1313
// Key set to "true" by the update-agent when a reboot is requested.
1414
AnnotationRebootNeeded = Prefix + "reboot-needed"
15+
LabelRebootNeeded = Prefix + "reboot-needed"
1516

1617
// Key set to "true" by the update-agent when node-drain and reboot is
1718
// initiated.

pkg/k8sutil/metadata.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ func SetNodeAnnotations(nc v1core.NodeInterface, node string, m map[string]strin
8080
})
8181
}
8282

83+
// SetNodeAnnotationsLabels sets all keys in a and l to their values in
84+
// node's annotations and labels, respectively
85+
func SetNodeAnnotationsLabels(nc v1core.NodeInterface, node string, a, l map[string]string) error {
86+
return UpdateNodeRetry(nc, node, func(n *v1api.Node) {
87+
for k, v := range a {
88+
n.Annotations[k] = v
89+
}
90+
91+
for k, v := range l {
92+
n.Labels[k] = v
93+
}
94+
})
95+
}
96+
8397
// DeleteNodeLabels deletes all keys in ks
8498
func DeleteNodeLabels(nc v1core.NodeInterface, node string, ks []string) error {
8599
return UpdateNodeRetry(nc, node, func(n *v1api.Node) {

0 commit comments

Comments
 (0)