-
Notifications
You must be signed in to change notification settings - Fork 39k
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
Fix for duplicate revisions created by StatefulSet #67039
Conversation
There was a problem hiding this 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exst
-> exists
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
existed
-> exists
present tense?
thank you for your first PR @mortent 👍 @kubernetes/sig-apps-pr-reviews |
9d08e46
to
343a209
Compare
@neolit123 Thanks for the comments. I have updated the PR. |
/assign @kow3ns |
/ok-to-test |
/approve |
/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{}) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
/lgtm Other than the nit comments, everything looks good to me. |
/retest Review the full test history for this PR. Silence the bot with an |
2 similar comments
/retest Review the full test history for this PR. Silence the bot with an |
/retest Review the full test history for this PR. Silence the bot with an |
343a209
to
31f1972
Compare
/lgtm |
[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 |
/retest |
/retest Review the full test history for this PR. Silence the bot with an |
1 similar comment
/retest Review the full test history for this PR. Silence the bot with an |
/retest |
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. |
…67039-upstream-release-1.10 Automated cherry pick of #67039: Fix for duplicate revisions created by StatefulSet
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: