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

Commit

Permalink
agent: set a label when after successful os-update
Browse files Browse the repository at this point in the history
This sets the label
`container-linux-update.v1.coreos.com/os-update-staged: "true"`
on nodes where the OS has been upgraded but not yet rebooted. This is so
daemonsets like tectonic-torcx can run ASAP.

Fixes: #167
  • Loading branch information
Casey Callendrello committed Jan 23, 2018
1 parent dedf1a2 commit da02653
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions doc/labels-and-annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ A few labels may be set directly by admins to customize behavior. These are call
| id | coreos | update-agent | Reflects the ID in `/etc/os-release` |
| version | 1497.7.0 | update-agent | Reflects the VERSION in `/etc/os-release` |
| group | stable | update-agent | Reflects the GROUP in `/usr/share/coreos/update.conf` or `/etc/coreos/update.conf` |
| reboot-needed | true | update-agent | Set to true to request a coordinated reboot |

**Annotations**

Expand Down
11 changes: 9 additions & 2 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,14 @@ func (k *Klocksmith) process(stop <-chan struct{}) error {
constants.AnnotationRebootInProgress: constants.False,
constants.AnnotationRebootNeeded: constants.False,
}
labels := map[string]string{
constants.LabelRebootNeeded: constants.False,
}
glog.Infof("Setting annotations %#v", anno)
if err := k8sutil.SetNodeAnnotations(k.nc, k.node, anno); err != nil {
if err := k8sutil.SetNodeAnnotationsLabels(k.nc, k.node, anno, labels); err != nil {
return err
}

// Since we set 'reboot-needed=false', 'ok-to-reboot' should clear.
// Wait for it to do so, else we might start reboot-looping
if err := k.waitForNotOkToReboot(); err != nil {
Expand Down Expand Up @@ -199,14 +203,17 @@ func (k *Klocksmith) updateStatusCallback(s updateengine.Status) {
constants.AnnotationNewVersion: s.NewVersion,
}

labels := map[string]string{}

// indicate we need a reboot
if s.CurrentOperation == updateengine.UpdateStatusUpdatedNeedReboot {
glog.Info("Indicating a reboot is needed")
anno[constants.AnnotationRebootNeeded] = constants.True
labels[constants.LabelRebootNeeded] = constants.True
}

wait.PollUntil(defaultPollInterval, func() (bool, error) {
if err := k8sutil.SetNodeAnnotations(k.nc, k.node, anno); err != nil {
if err := k8sutil.SetNodeAnnotationsLabels(k.nc, k.node, anno, labels); err != nil {
glog.Errorf("Failed to set annotation %q: %v", constants.AnnotationStatus, err)
return false, nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (

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

// Key set to "true" by the update-agent when node-drain and reboot is
// initiated.
Expand Down
4 changes: 2 additions & 2 deletions pkg/k8sutil/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func SetNodeAnnotations(nc v1core.NodeInterface, node string, m map[string]strin
})
}

// SetNodeAnnotationsLabels sets all keys in a and l to their respective values in
// node's annotations and labels, likewise
// SetNodeAnnotationsLabels sets all keys in a and l to their values in
// node's annotations and labels, respectively
func SetNodeAnnotationsLabels(nc v1core.NodeInterface, node string, a, l map[string]string) error {
return UpdateNodeRetry(nc, node, func(n *v1api.Node) {
for k, v := range a {
Expand Down

0 comments on commit da02653

Please sign in to comment.