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 specifying an initialize sql file on TiDB' s first bootstrap #4862

Merged
merged 11 commits into from
Feb 16, 2023

Conversation

fgksgf
Copy link
Contributor

@fgksgf fgksgf commented Feb 7, 2023

What problem does this PR solve?

Support specifying an initialize sql file on TiDB' s first bootstrap.
Related PR: pingcap/tidb#35625

What is changed and how does it work?

  • Add a BootstrapSQLConfigMapName field to tidb spec
  • If it's enabled, will mount the specify configmap to tidb pod and add --initialize-sql-file to tidb start script

Code changes

  • Has Go code change
  • Has CI related scripts change

Tests

  • Unit test
  • E2E test
  • Manual test
    • Run tidb operator locally
    • Create a config map like:
apiVersion: v1
kind: ConfigMap
metadata:
  name: sem
data:
  bootstrap-sql: |
    CREATE USER test_admin;
    GRANT RESTRICTED_VARIABLES_ADMIN ON *.* TO 'test_admin'@'%';
    GRANT RESTRICTED_STATUS_ADMIN ON *.* TO 'test_admin'@'%';
    GRANT RESTRICTED_CONNECTION_ADMIN ON *.* TO 'test_admin'@'%';
    GRANT RESTRICTED_USER_ADMIN ON *.* TO 'test_admin'@'%';
    GRANT RESTRICTED_TABLES_ADMIN ON *.* TO 'test_admin'@'%';
    GRANT RESTRICTED_REPLICA_WRITER_ADMIN ON *.* TO 'test_admin'@'%';
    GRANT SHUTDOWN, CONFIG ON *.* TO 'test_admin'@'%';
    REVOKE SHUTDOWN, CONFIG ON *.* FROM root;
  • create a TC CR, specify the BootstrapSQLConfigMapName field and set tidb config to enable SEM
  • connect to the tidb with user test_admin and:
    • query show config where type='tidb' and name='security.enable-sem';
    • query select * from INFORMATION_SCHEMA.USER_PRIVILEGES;
+------+-----------------------------------------------------------------+---------------------+-------+
| Type | Instance                                                        | Name                | Value |
+------+-----------------------------------------------------------------+---------------------+-------+
| tidb | with-bootstrap2-tidb-0.with-bootstrap2-tidb-peer.test5.svc:4000 | security.enable-sem | true  |
+------+-----------------------------------------------------------------+---------------------+-------+

+------------------+---------------+---------------------------------+--------------+
| GRANTEE          | TABLE_CATALOG | PRIVILEGE_TYPE                  | IS_GRANTABLE |
+------------------+---------------+---------------------------------+--------------+
| 'test_admin'@'%' | def           | SHUTDOWN                        | NO           |
| 'test_admin'@'%' | def           | CONFIG                          | NO           |
| 'test_admin'@'%' | def           | RESTRICTED_VARIABLES_ADMIN      | NO           |
| 'test_admin'@'%' | def           | RESTRICTED_STATUS_ADMIN         | NO           |
| 'test_admin'@'%' | def           | RESTRICTED_CONNECTION_ADMIN     | NO           |
| 'test_admin'@'%' | def           | RESTRICTED_USER_ADMIN           | NO           |
| 'test_admin'@'%' | def           | RESTRICTED_TABLES_ADMIN         | NO           |
| 'test_admin'@'%' | def           | RESTRICTED_REPLICA_WRITER_ADMIN | NO           |
+------------------+---------------+---------------------------------+--------------+
  • tidb pod did not restart
  • 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.

Support specifying an initialize sql file on TiDB' s first bootstrap

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Feb 7, 2023

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • csuzhangxc
  • 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.

@CLAassistant
Copy link

CLAassistant commented Feb 7, 2023

CLA assistant check
All committers have signed the CLA.

@codecov-commenter
Copy link

codecov-commenter commented Feb 7, 2023

Codecov Report

Merging #4862 (776f88e) into master (ec7e73f) will increase coverage by 8.36%.
The diff coverage is 0.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4862      +/-   ##
==========================================
+ Coverage   59.43%   67.79%   +8.36%     
==========================================
  Files         226      230       +4     
  Lines       25697    28793    +3096     
==========================================
+ Hits        15273    19521    +4248     
+ Misses       8969     7800    -1169     
- Partials     1455     1472      +17     
Flag Coverage Δ
e2e 52.65% <0.00%> (?)
unittest 59.39% <0.00%> (-0.05%) ⬇️

@fgksgf fgksgf changed the title [WIP] Support specifying an initialize sql file on TiDB' s first bootstrap Support specifying an initialize sql file on TiDB' s first bootstrap Feb 8, 2023
pkg/apis/pingcap/v1alpha1/tidbcluster.go Show resolved Hide resolved
@@ -643,6 +644,21 @@ func validateUpdatePDConfig(oldPdSpec, pdSpec *v1alpha1.PDSpec, path *field.Path
return allErrs
}

func disallowMutateBootstrapSQLConfigMapName(old, new *v1alpha1.TiDBSpec, p *field.Path) field.ErrorList {
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 there are no need to restrict this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because it only take effect at the first bootstrap, so updating the field makes no sense but make tidb restart.

Copy link
Collaborator

@KanShiori KanShiori left a comment

Choose a reason for hiding this comment

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

Rest LGTM

pkg/apis/pingcap/v1alpha1/tidbcluster.go Outdated Show resolved Hide resolved
pkg/manager/member/startscript/v1/template.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot requested a review from KanShiori February 10, 2023 08:00
@fgksgf fgksgf requested review from csuzhangxc and KanShiori and removed request for handlerww, KanShiori and csuzhangxc February 13, 2023 05:44
@@ -644,6 +644,8 @@ func validateUpdatePDConfig(oldPdSpec, pdSpec *v1alpha1.PDSpec, path *field.Path
return allErrs
}

// disallowMutateBootstrapSQLConfigMapName checks if user mutate the bootstrapSQLConfigMapName field.
// Only allow to update bootstrapSQLConfigMapName from non-nil to nil.
Copy link
Member

Choose a reason for hiding this comment

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

why do we need to support updates from non-nil to nil?

Copy link
Contributor Author

@fgksgf fgksgf Feb 13, 2023

Choose a reason for hiding this comment

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

If the user deletes the bootstrap sql configmap and also wants to remove it from tidb pods.

@hanlins

This comment was marked as outdated.

@hanlins
Copy link
Contributor

hanlins commented Feb 13, 2023

/run-all-tests

@hanlins
Copy link
Contributor

hanlins commented Feb 13, 2023

/test pull-e2e-kind-across-kubernetes

1 similar comment
@handlerww
Copy link
Contributor

/test pull-e2e-kind-across-kubernetes

@handlerww
Copy link
Contributor

/test pull-e2e-kind-serial

@fgksgf
Copy link
Contributor Author

fgksgf commented Feb 15, 2023

Any ideas about the error in E2E?

Join cluster with existing data [It]

failed to check status

Unexpected error: "timed out waiting for the condition, 
last error: all pump member hosts don't contain update-1-pump.across-kubernetes-9232.svc.cluster.local"

/home/jenkins/agent/workspace/tidb-operator-pull-e2e-kind-across-kubernetes/go/src/github.com/pingcap/tidb-operator/tests/e2e/tidbcluster/across-kubernetes.go:280

if len(ownMembers) == 0 {
return fmt.Errorf("all pump member hosts don't contain %s", pumpHostSuffix)
}

Do we need to turn up the timeout?

err = CheckStatusWhenAcrossK8sWithTimeout(cli, []*v1alpha1.TidbCluster{tc1, tc2, tc3}, 5*time.Second, 3*time.Minute)

@handlerww
Copy link
Contributor

/test pull-e2e-kind-across-kubernetes

@KanShiori
Copy link
Collaborator

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 7702ee7

@ti-chi-bot
Copy link
Member

@fgksgf: Your PR was out of date, I have automatically updated it for you.

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 ti-community-infra/tichi repository.

@hanlins
Copy link
Contributor

hanlins commented Feb 15, 2023

/run-all-tests

@hanlins
Copy link
Contributor

hanlins commented Feb 15, 2023

/test pull-e2e-kind-serial

4 similar comments
@hanlins
Copy link
Contributor

hanlins commented Feb 15, 2023

/test pull-e2e-kind-serial

@hanlins
Copy link
Contributor

hanlins commented Feb 15, 2023

/test pull-e2e-kind-serial

@hanlins
Copy link
Contributor

hanlins commented Feb 15, 2023

/test pull-e2e-kind-serial

@KanShiori
Copy link
Collaborator

/test pull-e2e-kind-serial

@ti-chi-bot ti-chi-bot merged commit 0d45f8c into pingcap:master Feb 16, 2023
@fgksgf fgksgf deleted the huaxi/bootstrap-sql branch February 16, 2023 03:47
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.

9 participants