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

[WIP] Optimization for CreateOrUpdateConfigMap #4170

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

mianhk
Copy link
Contributor

@mianhk mianhk commented Sep 1, 2021

What problem does this PR solve?

Close #3737

What is changed and how does it work?

Code changes

  • Has Go code change
  • Has CI related scripts change

Tests

  • Unit test
  • E2E test
  • Manual test
  • No code

Side effects

  • Breaking backward compatibility
  • Other side effects:

Related changes

  • Need to cherry-pick to the release branch
  • Need to update the documentation

Release Notes

Please refer to Release Notes Language Style Guide before writing the release note.

Optimization for CreateOrUpdateConfigMap

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Sep 1, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • DanielZhangQD
  • july2993

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@DanielZhangQD
Copy link
Contributor

@mianhk Even with this PR, the function here https://github.com/pingcap/tidb-operator/blob/master/pkg/controller/generic_control.go#L425 will also call the Create API first, so it does not fix this issue thoroughly.

@DanielZhangQD DanielZhangQD changed the title Optimization for CreateOrUpdateConfigMap [WIP] Optimization for CreateOrUpdateConfigMap Sep 24, 2021
…UpdateConfigMap

Conflicts:
	pkg/controller/generic_control.go
@codecov-commenter
Copy link

codecov-commenter commented Sep 30, 2021

Codecov Report

Merging #4170 (5b0e271) into master (dc276de) will increase coverage by 0.01%.
The diff coverage is 70.00%.

@@            Coverage Diff             @@
##           master    #4170      +/-   ##
==========================================
+ Coverage   61.65%   61.67%   +0.01%     
==========================================
  Files         181      181              
  Lines       19482    19520      +38     
==========================================
+ Hits        12011    12038      +27     
- Misses       6313     6315       +2     
- Partials     1158     1167       +9     
Flag Coverage Δ
unittest 61.67% <70.00%> (+0.01%) ⬆️

@mianhk
Copy link
Contributor Author

mianhk commented Sep 30, 2021

@mianhk Even with this PR, the function here https://github.com/pingcap/tidb-operator/blob/master/pkg/controller/generic_control.go#L425 will also call the Create API first, so it does not fix this issue thoroughly.

I fixed this by CheckAndUpdateConfigMap and check the configMap by ConfigMapLister. And if is it necessary to create or upgrade other resources before after checking by Listers.

@mianhk mianhk changed the title [WIP] Optimization for CreateOrUpdateConfigMap Optimization for CreateOrUpdateConfigMap Sep 30, 2021
pkg/controller/generic_control.go Outdated Show resolved Hide resolved
pkg/controller/generic_control.go Outdated Show resolved Hide resolved
@DanielZhangQD
Copy link
Contributor

/run-all-tests

configMapNeedUpdate := false

if !configMapNotExist {
if err := mergeFn(cm, oldCm); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that mergeFn will never return err!=nil.
BTW, why set configMapNeedUpdate = true when err!=nil?

}

if configMapNotExist || configMapNeedUpdate {
result, err := w.GenericControlInterface.CreateOrUpdate(controller, cm, mergeFn, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

If you call CreateOrUpdate, it will always call create first before the update, which is a useless call to the kube-apiserver.
Could you please refer to the StatefulSet sync function https://github.com/pingcap/tidb-operator/blob/master/pkg/manager/member/tidb_member_manager.go#L177, just create if not exist and update if necessary?
Refer to https://github.com/pingcap/tidb-operator/blob/master/pkg/manager/member/config.go#L27 for configmap comparison. And you have to consider the components in the other files of this PR.

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.

Please check the comments.

pkg/controller/configmap_control.go Outdated Show resolved Hide resolved
pkg/manager/member/utils.go Outdated Show resolved Hide resolved
pkg/manager/member/utils.go Outdated Show resolved Hide resolved
pkg/controller/dependences.go Outdated Show resolved Hide resolved
pkg/manager/member/utils.go Outdated Show resolved Hide resolved
pkg/manager/member/utils.go Outdated Show resolved Hide resolved
pkg/manager/member/tikv_member_manager.go Show resolved Hide resolved
@DanielZhangQD
Copy link
Contributor

/run-all-tests

@@ -29,6 +31,8 @@ func updateConfigMap(old, new *corev1.ConfigMap) (bool, error) {

// check config
tomlField := []string{"config-file" /*pd,tikv,tidb */, "pump-config", "config_templ.toml" /*tiflash*/, "proxy_templ.toml" /*tiflash*/}
yamlField := []string{"prometheus-config", "prometheus.yml" /*prometheus*/}
Copy link
Contributor

Choose a reason for hiding this comment

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

prometheus-config is used as a key for external configmap that can be mounted for Prometheus which is not managed by TiDB Operator, so we can ignore this.
However, dashboards.yaml should be considered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, fixed.

@DanielZhangQD
Copy link
Contributor

/run-all-tests

@DanielZhangQD
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 742d0e1

@DanielZhangQD
Copy link
Contributor

/run-all-tests

1 similar comment
@DanielZhangQD
Copy link
Contributor

/run-all-tests

@DanielZhangQD
Copy link
Contributor

/test pull-e2e-kind-br

@DanielZhangQD
Copy link
Contributor

/test pull-e2e-kind

@DanielZhangQD
Copy link
Contributor

/run-all-tests

@DanielZhangQD
Copy link
Contributor

/test pull-e2e-kind

@DanielZhangQD
Copy link
Contributor

/run-all-tests

1 similar comment
@DanielZhangQD
Copy link
Contributor

/run-all-tests

@DanielZhangQD
Copy link
Contributor

/test pull-e2e-kind

3 similar comments
@DanielZhangQD
Copy link
Contributor

/test pull-e2e-kind

@DanielZhangQD
Copy link
Contributor

/test pull-e2e-kind

@DanielZhangQD
Copy link
Contributor

/test pull-e2e-kind

@mianhk
Copy link
Contributor Author

mianhk commented Dec 10, 2021

Some e2e tests can't pass caused by the labelFilterKubeInformerFactory :

ConfigMapLister: labelFilterKubeInformerFactory.Core().V1().ConfigMaps().Lister(),

This will always filter configmap with the label app.kubernetes.io/managed-by=tidb-operator.

But at the same time, some e2e tests install tidbcluster by Helm with chats:

labels:
app.kubernetes.io/name: {{ template "chart.name" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: pump
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}

Which may create configmaps with the label app.kubernetes.io/managed-by=Helm which will not be cached by the informer.

There are three ways to fix this:

  • Reset tidbcluster's default labels to app.kubernetes.io/managed-by=tidb-operator in charts. Don't know if there are other effects.
  • Modify labelFilterKubeInformerFactory to kubeInformerFactory of ConfigMapLister. This will save all ConfigMap locally refer to [WIP] Optimization for CreateOrUpdateConfigMap #4170 (comment).
  • Replace the way to create tidbcluster by Helm to kubeCli, maybe we can do this in another PR, refer to:
    tc, err := cli.PingcapV1alpha1().TidbClusters(tc.Namespace).Create(context.TODO(), tc, metav1.CreateOptions{})
    framework.ExpectNoError(err, "failed to create TidbCluster: %v", tc)
    err = oa.WaitForTidbClusterReady(tc, 30*time.Minute, 5*time.Second)
    framework.ExpectNoError(err, "failed to wait for TidbCluster ready: %v", tc)

@DanielZhangQD PTAL, which way can be taken?

@ti-chi-bot
Copy link
Member

@mianhk: PR needs rebase.

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.

@mianhk mianhk force-pushed the optimize-CreateOrUpdateConfigMap branch from 14a2357 to f236c8d Compare December 15, 2021 09:57
@ti-chi-bot
Copy link
Member

Merge canceled because a new commit is pushed.

@DanielZhangQD DanielZhangQD changed the title Optimization for CreateOrUpdateConfigMap [WIP] Optimization for CreateOrUpdateConfigMap Feb 22, 2022
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.

Optimization for CreateOrUpdateConfigMap
6 participants