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 parallel scaling on StatefulSets #44899

Merged
merged 3 commits into from
May 23, 2017

Conversation

smarterclayton
Copy link
Contributor

@smarterclayton smarterclayton commented Apr 25, 2017

Fixes #41255

StatefulSets now include an alpha scaling feature accessible by setting the `spec.podManagementPolicy` field to `Parallel`.  The controller will not wait for pods to be ready before adding the other pods, and will replace deleted pods as needed.  Since parallel scaling creates pods out of order, you cannot depend on predictable membership changes within your set.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 25, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@k8s-github-robot k8s-github-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-label-needed labels Apr 25, 2017
@smarterclayton smarterclayton requested a review from kow3ns April 25, 2017 04:44
@k8s-github-robot k8s-github-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-label-needed labels Apr 25, 2017
@k8s-github-robot k8s-github-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 Apr 25, 2017
@smarterclayton smarterclayton force-pushed the burst branch 2 times, most recently from 3a141ba to 03b3e2f Compare April 25, 2017 14:57
// StatefulsetBurstAnnotation instructs the stateful set controller to not wait when replacing pods from the set,
// and that it may create pods out of order. If enabling this annotation, ensure that your set is capable of
// forming a safe quorum even if pod creation is out of order. Accepts "true".
StatefulSetBurstAnnotation = "statefulset.alpha.kubernetes.io/burst"
Copy link
Member

Choose a reason for hiding this comment

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

Consider just making it a field in the Spec? We know we need this functionality, and we already have use cases for it. Starting with an annotation might be more trouble than its worth if we intend to upgrade to a field before GA.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I need to circle back on what exactly what we want to do for this. Will hunt that down.

Copy link
Member

Choose a reason for hiding this comment

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

Initial proposal in the issue was for an annotation, @bgrant0607 seems to favor just adding the field if we want to evolve it from an annotation to a field. I prefer the field primarily for validation integration and API clarity, but, as the annotation is functionally equivalent, if you want to go in that direction I'm on board.

}
return nil
}

var _ StatefulSetControlInterface = &defaultStatefulSetControl{}

// setAllowsBurst is true if the alpha burst annotation is set.
func setAllowsBurst(set *apps.StatefulSet) bool {
Copy link
Member

Choose a reason for hiding this comment

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

Move the helper to utils. If you keep the annotation instead of going with a field you're going to have to validate it here. You should report an error to runtime.ReportError if annotations value is not boolean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we report error here it will rate limit the controller. Argument for a field for sure. I'd say either way we can validate the annotation.

// is created while any pod is unhealthy, and pods are terminated in descending order. The burst
// strategy allows these constraints to be relaxed - pods will be created eagerly and terminated
// in bulk. Clients using the burst strategy should be careful to ensure they understand the consistency
// implications of having unpredictable numbers of pods available.
func (ssc *defaultStatefulSetControl) UpdateStatefulSet(set *apps.StatefulSet, pods []*v1.Pod) error {
Copy link
Member

Choose a reason for hiding this comment

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

Update method internal comments to be consistent with the behavior of out of order creation and termination.

@@ -25,6 +25,10 @@ import (
const (
// StatefulSetInitAnnotation if present, and set to false, indicates that a Pod's readiness should be ignored.
StatefulSetInitAnnotation = "pod.alpha.kubernetes.io/initialized"
// StatefulsetBurstAnnotation instructs the stateful set controller to not wait when replacing pods from the set,
Copy link
Member

@kow3ns kow3ns Apr 25, 2017

Choose a reason for hiding this comment

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

Doesn't respect ordered termination either. Basically it preserves uniqueness but not ordering. This is captured in the control loop method comments and should be captured here as well.

Copy link
Member

@kow3ns kow3ns left a comment

Choose a reason for hiding this comment

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

You should consider using a field in the Spec instead of an annotation. Comments need to be updated. If you decide to keep the annotation we should do some validation as validation.go won't check for an actual boolean value. Other than that looks good.

@0xmichalis
Copy link
Contributor

@kubernetes/sig-apps-pr-reviews

@0xmichalis
Copy link
Contributor

Do we need an issue in the features repo?

@smarterclayton
Copy link
Contributor Author

One already exists

@smarterclayton
Copy link
Contributor Author

Sounds like we have consensus on a field. Although I'm not sure whether we want a struct for "change policy" or whether this is eventually part of the strategy for rollout. I can imagine that the policy during an update is different than normal behavior or initial rollout.

// if the set does not allow bursting, return immediately
if monotonic {
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.

You want to continue here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, if you are in burst mode we scale all them up immediately.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean

if !isCreated(replicas[i]) {
   if err := ssc.podControl.CreateStatefulPod(set, replicas[i]); err != nil {
		return err
	}
   if monotonic {
		return nil
	}
   continue
}

since the replica you just created is not going to fall under any of the following 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.

Ah, yes, thanks.

@0xmichalis
Copy link
Contributor

Although I'm not sure whether we want a struct for "change policy" or whether this is eventually part of the strategy for rollout. I can imagine that the policy during an update is different than normal behavior or initial rollout.

The original issue is about forming initial quorum. We can constrain burst during a rollout with rollout-specific parameters (maxSurge-maxUnavailable?).

@smarterclayton
Copy link
Contributor Author

It seems appropriate that deployment specific policy overrides / replaces steady state requirements.

@smarterclayton
Copy link
Contributor Author

const OrderedReplacement ReplacementPolicyType = `Ordered`
const ImmediateReplacement ReplacementPolicyType = `Immediate`

type StatefulSetSpec struct {
  ...

  ReplacementPolicy ReplacementPolicyType
}

{"spec":{"replacementPolicy": "Ordered"}}

? Better description than "replacementPolicy"?

@k8s-github-robot k8s-github-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 19, 2017
@smarterclayton
Copy link
Contributor Author

Barring broken tests, can I get a final review pass on the rest of the PR (got one for the annotation version)?

sort.Sort(ascendingOrdinal(pods))
for ord := 0; ord < len(pods); ord++ {
if !storageMatches(set, pods[ord]) {
return fmt.Errorf("Pods %s does not match the storage specification of StatefulSet %s ", pods[ord].Name, set.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

s/Pods/pod/

}
}

if !identityMatches(set, pods[ord]) {
return fmt.Errorf("Pods %s does not match the identity specification of StatefulSet %s ",
Copy link
Contributor

Choose a reason for hiding this comment

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

s/Pods/pod/

fnName = fnName[i+1:]
}
t.Run(
fmt.Sprintf("%s/Monotonic", fnName),
Copy link
Contributor

Choose a reason for hiding this comment

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

t.Logf ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this is the name of the test case

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, you get is an an arg, ack

@0xmichalis
Copy link
Contributor

got one for the annotation version

Not sure what do you mean with this one, code lgtm

@smarterclayton
Copy link
Contributor Author

smarterclayton commented May 20, 2017 via email

@smarterclayton smarterclayton changed the title Support burst scaling on StatefulSets Support parallel scaling on StatefulSets May 20, 2017
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 20, 2017
@0xmichalis
Copy link
Contributor

fields lgtm too

@smarterclayton smarterclayton force-pushed the burst branch 4 times, most recently from a6b5f3d to 0b9532b Compare May 21, 2017 02:49
The alpha field podManagementPolicy defines how pods are created,
deleted, and replaced. The new `Parallel` policy will replace pods
as fast as possible, not waiting for the pod to be `Ready` or providing
an order. This allows for advanced clustered software to take advantage
of rapid changes in scale.
Use subtests to avoid duplicating entire suite of control logic.
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented May 21, 2017

@smarterclayton: The following test(s) failed:

Test name Commit Details Rerun command
Jenkins Bazel Build ef6bed8c193a61fcd04af3eb2007ab4ad150c09f link @k8s-bot bazel test this
Jenkins unit/integration ce560929e99fe4fd95cbdaa80cc6a20068a656fa link @k8s-bot unit test this
Jenkins verification ce560929e99fe4fd95cbdaa80cc6a20068a656fa link @k8s-bot verify test this
pull-kubernetes-federation-e2e-gce e40648d link @k8s-bot pull-kubernetes-federation-e2e-gce test this

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@smarterclayton
Copy link
Contributor Author

Any other comments? Ready for final review.

@kow3ns
Copy link
Member

kow3ns commented May 22, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 22, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kow3ns, smarterclayton

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 38990, 45781, 46225, 44899, 43663)

@k8s-github-robot k8s-github-robot merged commit c2c5051 into kubernetes:master May 23, 2017
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 lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants