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

Support Hierarchical Cohorts in Cache/Snapshot #3006

Merged
merged 1 commit into from
Sep 16, 2024

Conversation

gabesaba
Copy link
Contributor

@gabesaba gabesaba commented Sep 6, 2024

What type of PR is this?

/kind feature

What this PR does / why we need it:

Support HierarchicalCohorts (#79), with cycle-detection, in the cache and snapshot.

Special notes for your reviewer:

I wrote tests which check resource usage. I will add them to this PR once #3005 merges.

Does this PR introduce a user-facing change?

NONE

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. labels Sep 6, 2024
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 6, 2024
Copy link

netlify bot commented Sep 6, 2024

Deploy Preview for kubernetes-sigs-kueue canceled.

Name Link
🔨 Latest commit 9aae9ea
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-kueue/deploys/66e803a271318a0009a33e42

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 6, 2024
@gabesaba
Copy link
Contributor Author

gabesaba commented Sep 6, 2024

/assign @mimowo

@alculquicondor
Copy link
Contributor

/cc

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 6, 2024
// getRoot returns the root of the Cohort tree IFF there was not a
// cycle.
func getRoot(c *cohort) (*cohort, bool) {
checker := cycleChecker{cycles: make(map[string]bool, 8)}
Copy link
Contributor

Choose a reason for hiding this comment

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

clarify in a comment that 8 is a reasonable upper-bound for hierarchy height

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted in this revision.

Copy link
Contributor

Choose a reason for hiding this comment

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

hierarchy.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted in this revision. We now have cycle.go in hierarchy package

return getRootHelper(c), true
}

func getRootHelper(c *cohort) *cohort {
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
func getRootHelper(c *cohort) *cohort {
func getRoot(c *cohort) *cohort {

Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect the scheduling cycle to call this function directly, as opposed to check for cycles again.


// getRoot returns the root of the Cohort tree IFF there was not a
// cycle.
func getRoot(c *cohort) (*cohort, bool) {
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
func getRoot(c *cohort) (*cohort, bool) {
func getRootUnsafe(c *cohort) (*cohort, bool) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

shouldn't the other function be called unsafe, as it will enter an infinite loop if called with cycle?

Comment on lines 46 to 48
if c.cycles[cohort.GetName()] {
return true
}
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
if c.cycles[cohort.GetName()] {
return true
}
if cycle, seen := c.cycles[cohort.GetName()]; seen {
return cycle
}

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is better, thanks :)

@@ -84,12 +84,19 @@ func (c *Cache) Snapshot() Snapshot {
ResourceFlavors: make(map[kueue.ResourceFlavorReference]*kueue.ResourceFlavor, len(c.resourceFlavors)),
InactiveClusterQueueSets: sets.New[string](),
}
cycleChecker := cycleChecker{cycles: make(map[string]bool, len(c.hm.Cohorts))}
Copy link
Contributor

Choose a reason for hiding this comment

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

why do you need to check at this point?
I think the information should be stored in the cache somehow. We need to communicate it to the CQ and cohort statuses anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm storing this structure in the hierarchy.Manager (and thus cache) now, but it will still be called again during snapshotting - using the memoized result.

Comment on lines 1058 to 1059
_ = cache.AddCohort(cohort)
return nil
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
_ = cache.AddCohort(cohort)
return nil
return cache.AddCohort(cohort)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

t.Fatal("Expected success")
}

t.Run("before move", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

do not use t.Run for non-independent tests cases

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 13, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 13, 2024
@gabesaba
Copy link
Contributor Author

/retest

@@ -104,7 +104,9 @@ func (r *CohortReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
}

log.V(2).Info("Cohort is being created or updated", "resources", cohort.Spec.ResourceGroups)
r.cache.AddOrUpdateCohort(&cohort)
if err := r.cache.AddOrUpdateCohort(&cohort); err != nil {
return ctrl.Result{}, err
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this cause a requeue into the reconciler?

Maybe we should log the issue, but then don't return the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, updated.

Copy link
Contributor

@alculquicondor alculquicondor left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 16, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: c3d67eb01af97818021dc8b9379cf9317d75678c

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alculquicondor, gabesaba

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 16, 2024
@k8s-ci-robot k8s-ci-robot merged commit f6ebfe5 into kubernetes-sigs:main Sep 16, 2024
16 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v0.9 milestone Sep 16, 2024
@gabesaba gabesaba deleted the hc_cache branch September 16, 2024 13:51
@gabesaba
Copy link
Contributor Author

Only attaching release note to a single PR, where we define the API #2693

/release-note-edit

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants