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

Evenly spread volumes of a StatefuleSet across nodes based on topology #151

Merged
merged 1 commit into from
Oct 26, 2018

Conversation

ddebroy
Copy link
Collaborator

@ddebroy ddebroy commented Oct 16, 2018

If immediate volume binding mode is set and the PVC follows StatefulSet naming format, then the provisioner will choose, as the first segment in preferred topology, a segment from requisite topology based on the relevant parts of the PVC name that ensures an even spread of topology across the StatefulSet's volumes.

The logic around determining the StatefulSet naming format and obtaining a hash and index is identical to the logic in pkg/volume/util/util.go Kubernetes main tree.

Fixes: #143

cc @msau42 @verult

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 16, 2018
@ddebroy ddebroy requested a review from msau42 October 16, 2018 08:40
@ddebroy
Copy link
Collaborator Author

ddebroy commented Oct 16, 2018

/assign @jsafrane

// ordering of segments in preferred array is sensitive to statefulset name: testset
// if statefuleset name is changed, make sure expectedPreferred is kept in sync
// pvc prefix in pvcName does not have any effect on segment ordering
"pvc 1a": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also a test case when allowedTopologies is specified?. Do we also need to to convert the old zone/zones to AllowedTopologies for migration?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point - I can add an additional sanity test with allowedTopologies specified for completeness. TestAllowedTopologies already covers several scenarios for trimming down the requisiteTerms based on allowedTopologies but it will be good to have a sanity case here as well.

Added point 4b in https://docs.google.com/document/d/15Q4wXVqbalrVgf_jlGis4QFXN1RY1GMiY-Ek-hpCr-o/edit# for the migration work around topology.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Extra test cases with allowedTopologies added in latest commit.

@msau42
Copy link
Collaborator

msau42 commented Oct 17, 2018

/assign

@verult
Copy link
Contributor

verult commented Oct 18, 2018

/assign

@k8s-ci-robot
Copy link
Contributor

@verult: GitHub didn't allow me to assign the following users: verult.

Note that only kubernetes-csi members and repo collaborators can be assigned.
For more information please see the contributor guide

In response to this:

/assign

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
Contributor

@verult verult left a comment

Choose a reason for hiding this comment

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

First pass. Thanks Deep!

@@ -120,6 +123,14 @@ func GenerateAccessibilityRequirements(
return nil, fmt.Errorf("topology %v from selected node %q is not in requisite", selectedTopology, selectedNode.Name)
}

requirement.Preferred = toCSITopology(preferredTerms)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can pull this out of the if branch

@@ -120,6 +123,14 @@ func GenerateAccessibilityRequirements(
return nil, fmt.Errorf("topology %v from selected node %q is not in requisite", selectedTopology, selectedNode.Name)
}

requirement.Preferred = toCSITopology(preferredTerms)
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: if selectedNode == nil branch above the other; positive branch first

@@ -120,6 +123,14 @@ func GenerateAccessibilityRequirements(
return nil, fmt.Errorf("topology %v from selected node %q is not in requisite", selectedTopology, selectedNode.Name)
}

requirement.Preferred = toCSITopology(preferredTerms)
} else {
hash, index := getPVCNameHashAndIndexOffset(pvcName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on why all the logic in this else branch is needed

requirement.Preferred = toCSITopology(preferredTerms)
} else {
hash, index := getPVCNameHashAndIndexOffset(pvcName)
sort.Slice(requisiteTerms, func(i, j int) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we potentially reuse sortAndShift() here? Would make it easier to read if the runtime loss isn't significant

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done. Added an an extra parameter to sortAndShift() - shiftIndex - which will be considered if the topologyTerm parameter is nil.

@@ -367,3 +378,52 @@ func toCSITopology(terms []topologyTerm) []*csi.Topology {
}
return out
}

// identical to logic in in-tree pkg/volume/util/util.go
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to have the full URL to the master branch version of this file?

pvcName string
expectedPreferred []*csi.Topology
}{
// ordering of segments in preferred array is sensitive to statefulset name: testset
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Maybe move this comment outside? At first glance I thought this comment was for a specific test case

expectedPreferred []*csi.Topology
}{
// ordering of segments in preferred array is sensitive to statefulset name: testset
// if statefuleset name is changed, make sure expectedPreferred is kept in sync
Copy link
Contributor

Choose a reason for hiding this comment

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

statefuleset -> statefulset

// ordering of segments in preferred array is sensitive to statefulset name: testset
// if statefuleset name is changed, make sure expectedPreferred is kept in sync
// pvc prefix in pvcName does not have any effect on segment ordering
"pvc 1a": {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Use a test name that describes what the case is testing

@ddebroy
Copy link
Collaborator Author

ddebroy commented Oct 19, 2018

Thanks for the detailed review @verult and @msau42. Addressed the code review comments so far.

Copy link
Contributor

@verult verult left a comment

Choose a reason for hiding this comment

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

Just some minor comments now, otherwise looks good!

@ddebroy
Copy link
Collaborator Author

ddebroy commented Oct 24, 2018

@verult comments fixed.

@verult
Copy link
Contributor

verult commented Oct 24, 2018

/lgtm

@k8s-ci-robot
Copy link
Contributor

@verult: changing LGTM is restricted to assignees, and only kubernetes-csi/external-provisioner repo collaborators may be assigned issues.

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.

@ddebroy
Copy link
Collaborator Author

ddebroy commented Oct 24, 2018

/assign @verult

@ddebroy
Copy link
Collaborator Author

ddebroy commented Oct 24, 2018

@verult assigned you so that lgtm is accepted :-)

@verult
Copy link
Contributor

verult commented Oct 24, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 24, 2018
@ddebroy
Copy link
Collaborator Author

ddebroy commented Oct 25, 2018

@jsafrane can you PTAL?

@jsafrane
Copy link
Contributor

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ddebroy, jsafrane

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 Oct 26, 2018
@jsafrane
Copy link
Contributor

/hold

please squash the last commit

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 26, 2018
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 26, 2018
@ddebroy
Copy link
Collaborator Author

ddebroy commented Oct 26, 2018

@jsafrane squashed all commits.

@jsafrane
Copy link
Contributor

/hold cancel
/lgtm

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Oct 26, 2018
@k8s-ci-robot k8s-ci-robot merged commit a8d9d8d into kubernetes-csi:master Oct 26, 2018
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants