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

Use patch for sts in periodicity controller #2332

Merged
merged 5 commits into from
Apr 29, 2020

Conversation

Yisaer
Copy link
Contributor

@Yisaer Yisaer commented Apr 29, 2020

What problem does this PR solve?

periodicity controller use update to inject timestamp annotation for the tidbcluster sts. However, the data in the Lister might be out-of-date which causing the tikv/tidb sts scale-in again after they get scale-out by auto-scaler.
In this request, we use patch to merge the target sts annotation instead of updating.

Related changes

  • Need to cherry-pick to the release branch

Does this PR introduce a user-facing change?:

Using `Patch` in `Periodicity` to avoid `StatefulSet` be updated to wrong state.

if err != nil {
errs = append(errs, err)
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

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

why remove this? there is no need to update statefulsets not owned by tidb clusters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

"metadata": map[string]interface{}{
"annotations": sts.Annotations,
},
})
Copy link
Contributor

@cofyc cofyc Apr 29, 2020

Choose a reason for hiding this comment

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

I think using the Patch method is a good idea. It can avoid API conflicts in kube-apiserver.

But the root cause is we should copy before modifying the statefulset if the data in the Lister are touched.

if err != nil {
errs = append(errs, err)
continue
}
if sts.Annotations == nil {
sts.Annotations = map[string]string{}
}
sts.Annotations[label.AnnStsLastSyncTimestamp] = time.Now().Format(time.RFC3339)
Copy link
Contributor

Choose a reason for hiding this comment

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

create a new annotations map, otherwise, cache in informer will be modified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

@Yisaer Yisaer requested a review from cofyc April 29, 2020 04:07
Comment on lines 98 to 100
if sts.Annotations == nil {
sts.Annotations = map[string]string{}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if sts.Annotations == nil {
sts.Annotations = map[string]string{}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

@Yisaer Yisaer requested a review from cofyc April 29, 2020 06:07
Copy link
Contributor

@DanielZhangQD DanielZhangQD left a comment

Choose a reason for hiding this comment

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

LGTM

@Yisaer Yisaer merged commit 434d5bf into pingcap:master Apr 29, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Apr 29, 2020

cherry pick to release-1.1 in PR #2335

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants