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

225: Add support for exclusive plans #260

Merged
merged 4 commits into from
Sep 29, 2023
Merged
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
3 changes: 3 additions & 0 deletions pkg/apis/upgrade.cattle.io/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const (
// LabelController is the name of the upgrade controller.
LabelController = GroupName + `/controller`

// LabelExclusive is set if the plan should not run concurrent with other plans.
LabelExclusive = GroupName + `/exclusive`

// LabelNode is the node being upgraded.
LabelNode = GroupName + `/node`

Expand Down
2 changes: 2 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,8 @@ type PlanSpec struct {

Tolerations []corev1.Toleration `json:"tolerations,omitempty"`

Exclusive bool `json:"exclusive,omitempty"`

Prepare *ContainerSpec `json:"prepare,omitempty"`
Cordon bool `json:"cordon,omitempty"`
Drain *DrainSpec `json:"drain,omitempty"`
Expand Down
18 changes: 18 additions & 0 deletions pkg/upgrade/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ var (
)

func New(plan *upgradeapiv1.Plan, node *corev1.Node, controllerName string) *batchv1.Job {
exclusiveString := strconv.FormatBool(plan.Spec.Exclusive)
hostPathDirectory := corev1.HostPathDirectory
labelPlanName := upgradeapi.LabelPlanName(plan.Name)
nodeHostname := upgradenode.Hostname(node)
Expand All @@ -119,6 +120,7 @@ func New(plan *upgradeapiv1.Plan, node *corev1.Node, controllerName string) *bat
},
Labels: labels.Set{
upgradeapi.LabelController: controllerName,
upgradeapi.LabelExclusive: exclusiveString,
upgradeapi.LabelNode: node.Name,
upgradeapi.LabelPlan: plan.Name,
upgradeapi.LabelVersion: plan.Status.LatestVersion,
Expand All @@ -132,6 +134,7 @@ func New(plan *upgradeapiv1.Plan, node *corev1.Node, controllerName string) *bat
ObjectMeta: metav1.ObjectMeta{
Labels: labels.Set{
upgradeapi.LabelController: controllerName,
upgradeapi.LabelExclusive: exclusiveString,
upgradeapi.LabelNode: node.Name,
upgradeapi.LabelPlan: plan.Name,
upgradeapi.LabelVersion: plan.Status.LatestVersion,
Expand Down Expand Up @@ -211,6 +214,21 @@ func New(plan *upgradeapiv1.Plan, node *corev1.Node, controllerName string) *bat
*job.Spec.Parallelism = 1
}

if plan.Spec.Exclusive {
job.Spec.Template.Spec.Affinity.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution = []corev1.PodAffinityTerm{{
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{{
Key: upgradeapi.LabelExclusive,
Operator: metav1.LabelSelectorOpIn,
Values: []string{
exclusiveString,
},
}},
},
TopologyKey: corev1.LabelHostname,
}}
}

podTemplate := &job.Spec.Template
// setup secrets volumes
for _, secret := range plan.Spec.Secrets {
Expand Down