Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal feature: Adding label to node after applying the job #129

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/apis/upgrade.cattle.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type PlanSpec struct {
Prepare *ContainerSpec `json:"prepare,omitempty"`
Cordon bool `json:"cordon,omitempty"`
Drain *DrainSpec `json:"drain,omitempty"`
Label *LabelSpec `json:"label,omitempty"`
Upgrade *ContainerSpec `json:"upgrade,omitempty" wrangler:"required"`
}

Expand Down Expand Up @@ -80,3 +81,9 @@ type SecretSpec struct {
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"`
}

// LabelSpec specifies which label should be added to the node after update.
type LabelSpec struct {
Key string `json:"key,omitempty"`
Value string `json:"value,omitempty"`
}
9 changes: 9 additions & 0 deletions pkg/upgrade/handle_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ func (ctl *Controller) handleJobs(ctx context.Context) error {
}
return obj, enqueueOrDelete(jobs, obj, upgradejob.ConditionComplete)
}

// label the node after the update
if plan.Spec.Label != nil {
node.ObjectMeta.Labels[plan.Spec.Label.Key] = plan.Spec.Label.Value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
node.ObjectMeta.Labels[plan.Spec.Label.Key] = plan.Spec.Label.Value
node.Labels[plan.Spec.Label.Key] = plan.Spec.Label.Value

Also, you should want to move this twiddle (with the conditional guard against nil) up to line 91, immediately prior to the following block:

				if node, err = nodes.Update(node); err != nil {
					return obj, err
				}

This would augment (and piggyback your change as part of) the "this job has completed so lets label the node and mark it as schedulable once again (if cordon or drain were specified)" operation. The extra call to Update() the node becomes superfluous.

if _, err := ctl.kcs.CoreV1().Nodes().Update(ctx, node, metav1.UpdateOptions{}); err != nil {
return obj, err
}
}

// if the job is hasn't failed or completed but the job Node is not on the applying list, consider it running out-of-turn and delete it
if i := sort.SearchStrings(plan.Status.Applying, nodeName); i == len(plan.Status.Applying) ||
(i < len(plan.Status.Applying) && plan.Status.Applying[i] != nodeName) {
Expand Down