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

Commit

Permalink
Merge pull request #37 from mischief/change-anno-label
Browse files Browse the repository at this point in the history
internal: fix label vs annotation
  • Loading branch information
mischief authored Jan 11, 2017
2 parents 40fffc5 + 1fd9cdc commit 6efa078
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
24 changes: 12 additions & 12 deletions internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func (k *Klocksmith) Run() error {
}

anno := map[string]string{
constants.AnnotationID: vi.ID,
constants.AnnotationGroup: vi.Group,
constants.AnnotationVersion: vi.Version,
constants.LabelID: vi.ID,
constants.LabelGroup: vi.Group,
constants.LabelVersion: vi.Version,
}

log.Printf("Setting annotations: %#v", anno)
Expand All @@ -78,8 +78,8 @@ func (k *Klocksmith) Run() error {
// set coreos.com/update1/reboot-in-progress=false and
// coreos.com/update1/reboot-needed=false
labels := map[string]string{
constants.LabelRebootInProgress: "false",
constants.LabelRebootNeeded: "false",
constants.AnnotationRebootInProgress: "false",
constants.AnnotationRebootNeeded: "false",
}
log.Printf("Setting labels %#v", labels)
if err := k8sutil.SetNodeLabels(k.nc, k.node, labels); err != nil {
Expand All @@ -100,22 +100,22 @@ func (k *Klocksmith) Run() error {

// indicate we need a reboot
anno = map[string]string{
constants.LabelRebootNeeded: "true",
constants.AnnotationRebootNeeded: "true",
}
log.Printf("Setting labels %#v", anno)
if err := k8sutil.SetNodeLabels(k.nc, k.node, anno); err != nil {
return err
}

// block until constants.LabelOkToReboot is set
// block until constants.AnnotationOkToReboot is set
log.Printf("Waiting for ok-to-reboot from controller...")
if err := k.waitForOkToReboot(); err != nil {
return err
}

// set constants.LabelRebootInProgress and drain self
// set constants.AnnotationRebootInProgress and drain self
anno = map[string]string{
constants.LabelRebootInProgress: "true",
constants.AnnotationRebootInProgress: "true",
}
log.Printf("Setting labels %#v", anno)
if err := k8sutil.SetNodeLabels(k.nc, k.node, anno); err != nil {
Expand Down Expand Up @@ -202,9 +202,9 @@ func (k *Klocksmith) waitForOkToReboot() error {

// hopefully 24 hours is enough time between indicating we need a
// reboot and the controller telling us to do it
ev, err := watch.Until(time.Hour*24, watcher, k8sutil.NodeLabelCondition(constants.LabelOkToReboot, "true"))
ev, err := watch.Until(time.Hour*24, watcher, k8sutil.NodeLabelCondition(constants.AnnotationOkToReboot, "true"))
if err != nil {
return fmt.Errorf("waiting for label %q failed: %v", constants.LabelOkToReboot, err)
return fmt.Errorf("waiting for label %q failed: %v", constants.AnnotationOkToReboot, err)
}

// sanity check
Expand All @@ -213,7 +213,7 @@ func (k *Klocksmith) waitForOkToReboot() error {
panic("event contains a non-*api.Node object")
}

if no.Labels[constants.LabelOkToReboot] != "true" {
if no.Labels[constants.AnnotationOkToReboot] != "true" {
panic("event did not contain label expected")
}

Expand Down
28 changes: 14 additions & 14 deletions internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,15 @@ const (
Prefix = "container-linux-update.v1.coreos.com/"

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

// Key set to "true" by the update-agent when node-drain and reboot is
// initiated.
LabelRebootInProgress = Prefix + "reboot-in-progress"
AnnotationRebootInProgress = Prefix + "reboot-in-progress"

// Key set to "true" by the update-operator when an agent may proceed
// with a node-drain and reboot.
LabelOkToReboot = Prefix + "reboot-ok"

// Key set by the update-agent to the value of "ID" in /etc/os-release.
AnnotationID = Prefix + "id"

// Key set by the update-agent to the value of "GROUP" in
// /usr/share/coreos/update.conf, overridden by the value of "GROUP" in
// /etc/coreos/update.conf.
AnnotationGroup = Prefix + "group"

// Key set by the update-agent to the value of "VERSION" in /etc/os-release.
AnnotationVersion = Prefix + "version"
AnnotationOkToReboot = Prefix + "reboot-ok"

// Key set by the update-agent to the current operator status of update_agent.
//
Expand All @@ -46,4 +35,15 @@ const (
//
// It is possible, but extremely unlike for it to be "unknown status".
AnnotationStatus = Prefix + "status"

// Key set by the update-agent to the value of "ID" in /etc/os-release.
LabelID = Prefix + "id"

// Key set by the update-agent to the value of "GROUP" in
// /usr/share/coreos/update.conf, overridden by the value of "GROUP" in
// /etc/coreos/update.conf.
LabelGroup = Prefix + "group"

// Key set by the update-agent to the value of "VERSION" in /etc/os-release.
LabelVersion = Prefix + "version"
)
30 changes: 15 additions & 15 deletions internal/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ func (k *Kontroller) Run() error {
for {
rl.Accept()

// find nodes which rebooted, reset constants.LabelOkToReboot
// find nodes which rebooted, reset constants.AnnotationOkToReboot
ls := labels.Set(map[string]string{
constants.LabelOkToReboot: "true",
constants.LabelRebootNeeded: "false",
constants.LabelRebootInProgress: "false",
constants.AnnotationOkToReboot: "true",
constants.AnnotationRebootNeeded: "false",
constants.AnnotationRebootInProgress: "false",
})

nodes, err := k.nc.List(api.ListOptions{LabelSelector: ls.AsSelector()})
Expand All @@ -67,25 +67,25 @@ func (k *Kontroller) Run() error {
}

if len(nodes.Items) > 0 {
log.Printf("Found %d rebooted nodes, setting label %q to false", len(nodes.Items), constants.LabelOkToReboot)
log.Printf("Found %d rebooted nodes, setting label %q to false", len(nodes.Items), constants.AnnotationOkToReboot)
}

for _, n := range nodes.Items {
if err := k8sutil.SetNodeLabels(k.nc, n.Name, map[string]string{
constants.LabelOkToReboot: "false",
constants.AnnotationOkToReboot: "false",
}); err != nil {
log.Printf("Failed setting label %q on node %q to false: %v", constants.LabelOkToReboot, n.Name, err)
log.Printf("Failed setting label %q on node %q to false: %v", constants.AnnotationOkToReboot, n.Name, err)
}
}

// find N nodes that want to reboot
ls = labels.Set(map[string]string{
constants.LabelRebootNeeded: "true",
constants.AnnotationRebootNeeded: "true",
})

nodes, err = k.nc.List(api.ListOptions{LabelSelector: ls.AsSelector()})
if err != nil {
log.Printf("Failed listing nodes with label %q: %v", constants.LabelRebootNeeded, err)
log.Printf("Failed listing nodes with label %q: %v", constants.AnnotationRebootNeeded, err)
continue
}

Expand All @@ -106,9 +106,9 @@ func (k *Kontroller) Run() error {
func (k *Kontroller) handleReboot(n *v1api.Node) {
// node wants to reboot, so let it.
if err := k8sutil.SetNodeLabels(k.nc, n.Name, map[string]string{
constants.LabelOkToReboot: "true",
constants.AnnotationOkToReboot: "true",
}); err != nil {
log.Printf("Failed to set label %q on node %q: %v", constants.LabelOkToReboot, n.Name, err)
log.Printf("Failed to set label %q on node %q: %v", constants.AnnotationOkToReboot, n.Name, err)
return
}

Expand All @@ -119,13 +119,13 @@ func (k *Kontroller) handleReboot(n *v1api.Node) {
})

conds := []watch.ConditionFunc{
k8sutil.NodeLabelCondition(constants.LabelOkToReboot, "true"),
k8sutil.NodeLabelCondition(constants.LabelRebootNeeded, "false"),
k8sutil.NodeLabelCondition(constants.LabelRebootInProgress, "false"),
k8sutil.NodeLabelCondition(constants.AnnotationOkToReboot, "true"),
k8sutil.NodeLabelCondition(constants.AnnotationRebootNeeded, "false"),
k8sutil.NodeLabelCondition(constants.AnnotationRebootInProgress, "false"),
}
_, err = watch.Until(time.Hour*1, watcher, conds...)
if err != nil {
log.Printf("Waiting for label %q on node %q failed: %v", constants.LabelOkToReboot, n.Name, err)
log.Printf("Waiting for label %q on node %q failed: %v", constants.AnnotationOkToReboot, n.Name, err)
log.Printf("Failed to wait for successful reboot of node %q", n.Name)

k.er.Eventf(n, api.EventTypeWarning, eventReasonRebootFailed, "Timed out waiting for node to return after a reboot")
Expand Down

0 comments on commit 6efa078

Please sign in to comment.