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

Fix for duplicate revisions created by StatefulSet #67039

Conversation

mortent
Copy link
Member

@mortent mortent commented Aug 6, 2018

What this PR does / why we need it: This PR replaces PR #65038 as a fix to issue #55159. The statefulset controller can in some situations create more controller revisions than necessary and this change makes sure the controller checks with the API server and only create new revision if the raw data is different.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #55159

Special notes for your reviewer:

Release note:

Avoid creating new controller revisions for statefulsets when cache is stale

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 6, 2018
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 6, 2018
Copy link
Member

@neolit123 neolit123 left a comment

Choose a reason for hiding this comment

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

/sig apps
/kind bug

@@ -258,8 +258,8 @@ func TestRealHistory_CreateControllerRevision(t *testing.T) {
history := NewHistory(client, informer.Lister())

var collisionCount int32
for i := range test.existing {
_, err := history.CreateControllerRevision(test.existing[i].parent, test.existing[i].revision, &collisionCount)
for _, exst := range test.existing {
Copy link
Member

Choose a reason for hiding this comment

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

exst -> exists

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed the iteration variable to item. I think exists just sounds too much like a boolean variable and the name is also used by another variable in the function.

return nil, err
}
if bytes.Equal(existed.Data.Raw, clone.Data.Raw) {
return existed, err
Copy link
Member

Choose a reason for hiding this comment

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

existed, err -> existed, nil to make an explicit statement here.
or exists, nil as per the above comment about tense.

@@ -252,6 +252,13 @@ func (rh *realHistory) CreateControllerRevision(parent metav1.Object, revision *
clone.Name = ControllerRevisionName(parent.GetName(), hash)
created, err := rh.client.AppsV1().ControllerRevisions(parent.GetNamespace()).Create(clone)
if errors.IsAlreadyExists(err) {
existed, err := rh.client.AppsV1().ControllerRevisions(parent.GetNamespace()).Get(clone.Name, metav1.GetOptions{})
Copy link
Member

Choose a reason for hiding this comment

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

existed -> exists present tense?

@k8s-ci-robot k8s-ci-robot added sig/apps Categorizes an issue or PR as relevant to SIG Apps. kind/bug Categorizes issue or PR as related to a bug. labels Aug 6, 2018
@neolit123
Copy link
Member

neolit123 commented Aug 6, 2018

thank you for your first PR @mortent 👍
added a couple of review comments.

@kubernetes/sig-apps-pr-reviews

@mortent mortent force-pushed the AvoidDuplicateRevisionsForStatefulSet branch from 9d08e46 to 343a209 Compare August 6, 2018 23:23
@mortent
Copy link
Member Author

mortent commented Aug 6, 2018

@neolit123 Thanks for the comments. I have updated the PR.

@mortent
Copy link
Member Author

mortent commented Aug 6, 2018

/assign @kow3ns

@kow3ns
Copy link
Member

kow3ns commented Aug 7, 2018

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 7, 2018
@kow3ns
Copy link
Member

kow3ns commented Aug 7, 2018

/approve

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 7, 2018
@mortent
Copy link
Member Author

mortent commented Aug 7, 2018

/retest

@@ -252,6 +252,13 @@ func (rh *realHistory) CreateControllerRevision(parent metav1.Object, revision *
clone.Name = ControllerRevisionName(parent.GetName(), hash)
created, err := rh.client.AppsV1().ControllerRevisions(parent.GetNamespace()).Create(clone)
if errors.IsAlreadyExists(err) {
exists, err := rh.client.AppsV1().ControllerRevisions(parent.GetNamespace()).Get(clone.Name, metav1.GetOptions{})
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: set parent.GetNamespace to a variable, and reuse it.

modTemplate := ss1.Spec.Template.DeepCopy()
modTemplate.Labels["foo"] = "not_bar"
ss1Rev2, err := NewControllerRevision(ss1, parentKind, ss1.Spec.Template.Labels, rawTemplate(modTemplate), 2, ss1.Status.CollisionCount)
ss1Rev2.Name = ss1Rev1.Name
Copy link
Contributor

Choose a reason for hiding this comment

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

By modifying labels of modTemplate, the hash for populating name and labels fields will change, so I think it is incorrect to set ss1Rev2.Name = ss1Rev1.Name (same with .Labels below).

Copy link
Member Author

Choose a reason for hiding this comment

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

The labels are being manipulated in this way in order to set up the scenario where there are two controller revisions with the same name and hash label, but which are not identical. This is done by creating a new controller revision which is slightly different than an existing one (change the value of a label) and then give it the same name and label as the existing one. This will create a controller revision where the name and hash are "incorrect" for the content, but it works for setting up the data for the test. Normally this would be the result of a hash collision, we don't have a way to create those in the test.

Copy link
Contributor

Choose a reason for hiding this comment

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

Noted. As this is a unit test, I think this can be made clearer by creating the 2nd ControllerRevision (with the same name and labels) before modifying it's labels.

Copy link
Contributor

Choose a reason for hiding this comment

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

As sync by person, ControllerRevision is immutable once created, so this "hack" is necessary. I will LGTM again once comments are added. Thanks for the work!

@crimsonfaith91
Copy link
Contributor

/lgtm

Other than the nit comments, everything looks good to me.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 13, 2018
@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 comment for consistent failures.

2 similar comments
@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 comment for consistent failures.

@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 comment for consistent failures.

@mortent mortent force-pushed the AvoidDuplicateRevisionsForStatefulSet branch from 343a209 to 31f1972 Compare August 13, 2018 16:43
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 13, 2018
@crimsonfaith91
Copy link
Contributor

/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: crimsonfaith91, kow3ns, mortent

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

@crimsonfaith91
Copy link
Contributor

/retest

@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 comment for consistent failures.

1 similar comment
@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 comment for consistent failures.

@mortent
Copy link
Member Author

mortent commented Aug 14, 2018

/retest

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 67071, 66906, 66722, 67276, 67039). If you want to cherry-pick this change to another branch, please follow the instructions here.

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/bug Categorizes issue or PR as related to a bug. 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. sig/apps Categorizes an issue or PR as relevant to SIG Apps. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Statefulset : CreateControllerRevision function bug
7 participants