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

Even Pods Spread - 2. Calculating Predicates Metadata #77760

Merged
merged 6 commits into from
Jul 24, 2019

Conversation

Huang-Wei
Copy link
Member

@Huang-Wei Huang-Wei commented May 10, 2019

What type of PR is this?

/sig scheduling
/hold

/assign @bsalamat
/cc @krmayankk

What this PR does / why we need it:

This is the 2nd PR of the "Even Pods Spread" KEP implementation.

  • build a new topologyPairsPodSpreadMap into PredicateMetadata
  • update ShallowCopy()
  • unit tests
  • a new set of utils using "chained" pattern to build API objects

Which issue(s) this PR fixes:

Part of #77284.

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

(will document all the changes in one place)

NONE

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. release-note-none Denotes a PR that doesn't merit a release note. labels May 10, 2019
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. labels May 10, 2019
@k8s-ci-robot k8s-ci-robot requested a review from krmayankk May 10, 2019 21:08
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels May 10, 2019
@Huang-Wei
Copy link
Member Author

/kind feature
/priority important-soon

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API sig/apps Categorizes an issue or PR as relevant to SIG Apps. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels May 10, 2019
@Huang-Wei Huang-Wei force-pushed the eps-pred-meta branch 2 times, most recently from d6a656b to 5ae8ed5 Compare May 11, 2019 07:20
@Huang-Wei Huang-Wei changed the title Even Pods Spread - 2 Calculating Predicates Metadata Even Pods Spread - 2. Calculating Predicates Metadata May 13, 2019
@Huang-Wei
Copy link
Member Author

/retest

@Huang-Wei
Copy link
Member Author

/retest

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 31, 2019
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 14, 2019
@Huang-Wei
Copy link
Member Author

/retest

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 20, 2019
}

func (topologyPairsMaps *topologyPairsMaps) removePod(deletedPod *v1.Pod) {
// add a topology pair holder if needed
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this comment should start with the function name.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's usually tolerant for private functions.

podFullName := schedutil.GetPodFullName(pod)
if topologyPairsMaps.topologyPairToPods[pair] == nil {
topologyPairsMaps.topologyPairToPods[pair] = make(map[*v1.Pod]struct{})
if m.topologyPairToPods[pair] == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Could we replace this we addTopologyPairWithoutPods?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@@ -19,7 +19,7 @@ package predicates
import (
"strings"

v1 "k8s.io/api/core/v1"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we revert this change since there is nothing updates else in this file and it is not a restriction that we should import without v1 prefix

@@ -21,7 +21,7 @@ import (

"time"

v1 "k8s.io/api/core/v1"
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

@alculquicondor
Copy link
Member

That discussion was based on the context of switching to the {tpPair:count} solution. In that case, we don't hold a {podName:tpPairSet} structure.

I don't think we suggested that. Only to get rid of {tpPair:podSet}. I think we should still be able to hold {podName:tpPairSet}, which can even point to the same map (same address) for all the pods in the same node.

@Huang-Wei
Copy link
Member Author

I don't think we suggested that. Only to get rid of {tpPair:podSet}. I think we should still be able to hold {podName:tpPairSet}, which can even point to the same map (same address) for all the pods in the same node.

That's an option. Let's see how it can benefit upon eliminating {tpPair:podSet}.

@alculquicondor
Copy link
Member

I don't think we suggested that. Only to get rid of {tpPair:podSet}. I think we should still be able to hold {podName:tpPairSet}, which can even point to the same map (same address) for all the pods in the same node.

That's an option. Let's see how it can benefit upon eliminating {tpPair:podSet}.

sgtm

- build a new `topologyPairsPodSpreadMap` into PredicateMetadata
- update ShallowCopy()
- unit tests
- update minMatchMap from []int32 to map[string]int32
- move "chanined" utils to pkg/scheduler/testing/utils.go so as to be re-used by all scheduler tests
@Huang-Wei
Copy link
Member Author

/retest

1 similar comment
@Huang-Wei
Copy link
Member Author

/retest

@alculquicondor
Copy link
Member

/lgtm

@k8s-ci-robot
Copy link
Contributor

@alculquicondor: changing LGTM is restricted to collaborators

In response to this:

/lgtm

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link
Member

@ahg-g ahg-g left a comment

Choose a reason for hiding this comment

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

/lgtm

Thanks for modifying it.

errCh.SendErrorWithCancel(err, cancel)
return
}
if ok {
// constraint.TopologyKey is already guaranteed to be present
pair := topologyPair{key: constraint.TopologyKey, value: node.Labels[constraint.TopologyKey]}
Copy link
Member

Choose a reason for hiding this comment

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

You may also want to add that since we restrict a toplogyKey to exist in a single hard constraint, using topolgyKey as the key in this map is good enough to identify which exact constraint this pod is counted against (because otherwise the key to the map should be some sort of an identifier that combines the topologyKey and the label selector)

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 23, 2019
@Huang-Wei
Copy link
Member Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 23, 2019
@fejta-bot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@k8s-ci-robot k8s-ci-robot merged commit 87c3f51 into kubernetes:master Jul 24, 2019
@Huang-Wei Huang-Wei deleted the eps-pred-meta branch July 24, 2019 00:31
for _, constraint := range constraints {
topologyPairsPodSpreadMap.topologyKeyToMinPodsMap[constraint.TopologyKey] = math.MaxInt32
}
for pair, podSet := range topologyPairsPodSpreadMap.topologyPairToPods {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible that value of some topologyPairsPodSpreadMap.topologyKeyToMinPodsMap is
math.MaxInt32 at the end of this loop ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope. The logic below ensures for each tp pair, they're valued with either empty podSet, or a concrete podSet:

// If needed, append topology pair without entry of pods.
// For example, on node-x, there is no pod matching spread constraints,
// but node-x should be also considered as a match (with match number 0)
// i.e. <node: node-x>: {}
for _, constraint := range constraints {
// constraint.TopologyKey is already guaranteed to be present
pair := topologyPair{
key: constraint.TopologyKey,
value: node.Labels[constraint.TopologyKey],
}
// addTopologyPairWithoutPods is a non-op if other pods match this pair
nodeTopologyMaps.addTopologyPairWithoutPods(pair)
}

Then in the above loop, the default value (MaxInt32) will be compared with len(podSet), so they won't remain MaxInt32 at the end of the loop.

topologyPairsPodSpreadMap.topologyKeyToMinPodsMap[constraint.TopologyKey] = math.MaxInt32
}
for pair, podSet := range topologyPairsPodSpreadMap.topologyPairToPods {
// TODO(Huang-Wei): short circuit unvisited portions of <topologyKey: any value>
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder what type of short circuiting you were thinking about.
Without short circuiting, the following comparison is performed and we continue to the next pair:

l < topologyPairsPodSpreadMap.topologyKeyToMinPodsMap[pair.key]

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/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API 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. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. 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.

9 participants