-
Notifications
You must be signed in to change notification settings - Fork 8
dnorman3/priority system #119
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
Changes from 10 commits
4d00f25
18e4f6f
da244fa
f01af16
8c3e152
797c689
c491336
d58dce4
ed50518
9a1baea
ec68f28
78f3273
f7ec290
70f3323
9ab7a5a
65cdbf9
2be3d22
4a5d699
63e856b
0839bfc
4468e29
34abc20
b187dbd
a95dfb1
25e602a
de0b25f
a34bcec
9104133
73ad501
b25458a
116933f
0a5ccc9
a77c634
c8e791b
bb6e575
091a7aa
1621d15
10148d5
c8730da
38bda70
89fab8a
75e7651
457dcd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -273,31 +273,77 @@ func (c *controller) dropInProgressNodeGroups(nodeGroups v1.NodeGroupList, cnrs | |
|
|
||
| // createCNRs generates and applies CNRs from the changedNodeGroups | ||
| func (c *controller) createCNRs(changedNodeGroups []*ListedNodeGroups) { | ||
|
dnorman3 marked this conversation as resolved.
|
||
| klog.V(3).Infoln("applying") | ||
| for _, nodeGroup := range changedNodeGroups { | ||
| nodeNames := make([]string, 0, len(nodeGroup.List)) | ||
| for _, node := range nodeGroup.List { | ||
| nodeNames = append(nodeNames, node.Name) | ||
| } | ||
| // generate cnr with prefix and use generate name method | ||
| cnr := generation.GenerateCNR(*nodeGroup.NodeGroup, nodeNames, c.CNRPrefix, c.Namespace) | ||
| generation.UseGenerateNameCNR(&cnr) | ||
| generation.GiveReason(&cnr, nodeGroup.Reason) | ||
| generation.SetAPIVersion(&cnr, apiVersion) | ||
| klog.V(3).Infoln("applying") | ||
| for _, nodeGroup := range changedNodeGroups { | ||
| nodeNames := make([]string, 0, len(nodeGroup.List)) | ||
| for _, node := range nodeGroup.List { | ||
| nodeNames = append(nodeNames, node.Name) | ||
| } | ||
| // generate cnr with prefix and use generate name method | ||
| cnr := generation.GenerateCNR(*nodeGroup.NodeGroup, nodeNames, c.CNRPrefix, c.Namespace) | ||
| generation.UseGenerateNameCNR(&cnr) | ||
| generation.GiveReason(&cnr, nodeGroup.Reason) | ||
| generation.SetAPIVersion(&cnr, apiVersion) | ||
|
|
||
| name := generation.GetName(cnr.ObjectMeta) | ||
|
|
||
| if err := generation.ApplyCNR(c.client, c.DryMode, cnr); err != nil { | ||
| klog.Errorf("failed to apply cnr %q for nodegroup %q: %s", name, nodeGroup.NodeGroup.Name, err) | ||
| } else { | ||
| var drymodeStr string | ||
| if c.DryMode { | ||
| drymodeStr = "[drymode] " | ||
| } | ||
| klog.V(2).Infof("%ssuccessfully applied cnr %q for nodegroup %q", drymodeStr, name, nodeGroup.NodeGroup.Name) | ||
| c.CNRsCreated.WithLabelValues(nodeGroup.NodeGroup.Name).Inc() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| name := generation.GetName(cnr.ObjectMeta) | ||
| // filterNodeGroupsByPriority returns only the node groups at the lowest priority value | ||
| // Backward compatibility: negative or missing priorities are treated as 0 | ||
| func (c *controller) filterNodeGroupsByPriority(changedNodeGroups []*ListedNodeGroups) []*ListedNodeGroups { | ||
| if len(changedNodeGroups) == 0 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a redundant check because
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes please create and return an empty list if you end up keeping this check. |
||
| return nil | ||
| } | ||
| getPriority := func(ng *v1.NodeGroup) int32 { return max(ng.Spec.Priority, 0) } | ||
|
dnorman3 marked this conversation as resolved.
Outdated
|
||
| minPriority := getPriority(changedNodeGroups[0].NodeGroup) | ||
| for i := 1; i < len(changedNodeGroups); i++ { | ||
|
dnorman3 marked this conversation as resolved.
|
||
| p := getPriority(changedNodeGroups[i].NodeGroup) | ||
| if p < minPriority { | ||
| minPriority = p | ||
| } | ||
| } | ||
| var filtered []*ListedNodeGroups | ||
| for _, g := range changedNodeGroups { | ||
| if getPriority(g.NodeGroup) == minPriority { | ||
| filtered = append(filtered, g) | ||
| } | ||
| } | ||
| return filtered | ||
|
dnorman3 marked this conversation as resolved.
|
||
| } | ||
|
dnorman3 marked this conversation as resolved.
|
||
|
|
||
| if err := generation.ApplyCNR(c.client, c.DryMode, cnr); err != nil { | ||
| klog.Errorf("failed to apply cnr %q for nodegroup %q: %s", name, nodeGroup.NodeGroup.Name, err) | ||
| } else { | ||
| var drymodeStr string | ||
| if c.DryMode { | ||
| drymodeStr = "[drymode] " | ||
| } | ||
| klog.V(2).Infof("%ssuccessfully applied cnr %q for nodegroup %q", drymodeStr, name, nodeGroup.NodeGroup.Name) | ||
| c.CNRsCreated.WithLabelValues(nodeGroup.NodeGroup.Name).Inc() | ||
| } | ||
| } | ||
| // isLowerPriorityInProgress returns true if any in-progress CNR belongs to a NodeGroup with | ||
| // a priority lower than the provided minPriority (i.e., must finish before creating higher priorities) | ||
| func (c *controller) isLowerPriorityInProgress(minPriority int32, inProg v1.CycleNodeRequestList) bool { | ||
| if len(inProg.Items) == 0 { | ||
| return false | ||
| } | ||
| // Build a list of valid nodegroups to map CNRs to priorities | ||
| allNG := c.validNodeGroups() | ||
|
dnorman3 marked this conversation as resolved.
Outdated
|
||
| for _, cnr := range inProg.Items { | ||
| for i := range allNG.Items { | ||
|
dnorman3 marked this conversation as resolved.
Outdated
|
||
| ng := allNG.Items[i] | ||
| if cnr.IsFromNodeGroup(ng) { | ||
| p := max(ng.Spec.Priority, 0) | ||
| if p < minPriority { | ||
| return true | ||
| } | ||
| break | ||
| } | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| // nextRunTime returns the next time the controller loop will run from now in UTC | ||
|
|
@@ -319,8 +365,9 @@ func (c *controller) Run() { | |
| nodeGroups = c.dropInProgressNodeGroups(nodeGroups, inProgressCNRs) | ||
| } | ||
|
|
||
| // observer the changes using the remaining nodegroups. This is stateless and will pickup changes again if restarted | ||
| changedNodeGroups := c.observeChanges(nodeGroups) | ||
| // observe the changes using the remaining nodegroups. This is stateless and will pickup changes again if restarted | ||
| changedNodeGroups := c.observeChanges(nodeGroups) | ||
| c.NodeGroupsDetectedChanges.WithLabelValues().Set(float64(len(changedNodeGroups))) | ||
| if len(changedNodeGroups) == 0 { | ||
| klog.V(2).Infoln("all nodegroups up to date. next check in", c.CheckInterval) | ||
| return | ||
|
|
@@ -334,12 +381,31 @@ func (c *controller) Run() { | |
| } | ||
| } | ||
|
|
||
| // wait for the desired amount to allow any in progress changes to batch up | ||
| // Filter to only the lowest priority nodegroups | ||
| filtered := c.filterNodeGroupsByPriority(changedNodeGroups) | ||
| if len(filtered) == 0 { | ||
| klog.V(2).Infoln("no nodegroups to apply after priority filter") | ||
| return | ||
| } | ||
|
|
||
| // If any lower priority CNRs are still in progress, skip this run | ||
| minP := max(filtered[0].NodeGroup.Spec.Priority, 0) | ||
| if c.isLowerPriorityInProgress(minP, inProgressCNRs) { | ||
| c.NodeGroupsBlocked.WithLabelValues().Set(float64(len(filtered))) | ||
| klog.V(2).Infof("lower priority CNRs still in progress for priority < %d; skipping creation", minP) | ||
| return | ||
| } | ||
| // Not blocked | ||
| c.NodeGroupsBlocked.WithLabelValues().Set(0) | ||
|
|
||
| // wait for the desired amount to allow any in progress changes to batch up | ||
| klog.V(3).Infof("waiting for %v to allow changes to settle", c.WaitInterval) | ||
| select { | ||
| case <-time.After(c.WaitInterval): | ||
| klog.V(3).Infof("applying %d CNRs", len(changedNodeGroups)) | ||
| c.createCNRs(changedNodeGroups) | ||
| klog.V(3).Infof("applying %d CNRs (lowest priority batch)", len(filtered)) | ||
| c.NodeGroupsApplying.WithLabelValues().Set(float64(len(filtered))) | ||
| c.createCNRs(filtered) | ||
| c.NodeGroupsApplying.WithLabelValues().Set(0) | ||
| if c.RunOnce { | ||
| klog.V(3).Infoln("done creating CNRs after runOnce. exiting") | ||
| } else { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.