-
Notifications
You must be signed in to change notification settings - Fork 498
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
add controller for tidb initializer #1403
Conversation
Manual test passed, UT and e2e test will be done in #1404. |
@@ -71,13 +71,17 @@ type TidbInitializerSpec struct { | |||
|
|||
// InitSqlConfigMapName reference a configmap that provide init-sql, take high precedence than initSql if set | |||
// +optional | |||
InitSqlConfigMap *corev1.LocalObjectReference `json:"initSqlConfigMap,omitempty"` |
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.
It would be more extensible to use a struct, for example, we could support reference configmap cross namespaces by adding namespace
to the object, that is, change LocalObjectReference
to ObjectReference
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.
A Pod cannot mount a configmap from other ns, from the definition of ConfigMapVolumeSource
, only LocalObjectReference
is included.
do we have a basic TiDBInitializer e2e case right now? if not, I prefer adding one with this feature PR instead of another PR. This help reviewers to review PR. now, we can create tidb cluster without helm, it's very easy to start a tidb cluster. A basic e2e case can be:
This is an example e2e case which create and verify tidb cluster without helm: https://github.com/pingcap/tidb-operator/pull/1396/files#diff-92579a43c91e473b9716eeeee2068004R653 |
@onlymellb @aylei comments addressed, PTAL. |
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.
Rest LGTM
name := controller.TiDBInitializerMemberName(ti.Spec.Clusters.Name) | ||
ns := ti.Namespace | ||
cm := &corev1.ConfigMap{} | ||
|
||
exist, err := tm.typedControl.Exist(client.ObjectKey{ | ||
Namespace: ns, | ||
Name: name, | ||
}, cm) | ||
if err != nil { | ||
return err | ||
} | ||
if !exist { | ||
err = tm.syncTiDBInitConfigMap(ti) | ||
if err != nil { | ||
return 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.
Instead of check-and-create
, it is recommended to create the object directly and expect no err or an AlreadyExisted
error if the only purpose of the check is to determine whether we should create the object, which is atomic compared to two separate API calls.
Also, this could make the logic simple and the name calculation of TiDB init configmap don't have to be maintained in two places
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.
For a one-time deal, I agree that we can just create the object, but here is the logic in sync, it will be done at least periodically, it's not reasonable to create the object each time.
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.
Check before creation can reduce the API call to kube-apiserver, and I have moved the check block to separate sync functions.
job, err := tm.jobLister.Jobs(ns).Get(name) | ||
if err == nil { | ||
// job has been created | ||
return tm.updateStatus(ti.DeepCopy(), job) | ||
} | ||
|
||
if !errors.IsNotFound(err) { | ||
return fmt.Errorf("TiDBInitializer %s/%s get job %s failed, err: %v", ns, ti.Name, name, err) | ||
} | ||
|
||
return tm.syncTiDBInitJob(ti) |
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.
ditto
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.
Check before creation can reduce the API call to kube-apiserver, and I have moved the check block to separate sync functions.
var update bool | ||
if !apiequality.Semantic.DeepEqual(ti.Status.JobStatus, job.Status) { | ||
job.Status.DeepCopyInto(&ti.Status.JobStatus) | ||
update = true | ||
} | ||
if ti.Status.Phase != phase { | ||
ti.Status.Phase = phase | ||
update = true | ||
} | ||
if update { | ||
return tm.retryUpdateStatus(ti) | ||
} | ||
return nil |
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.
This could be simplified using GuaranteedUpdate
, we don't have to check the equality in client-side actually, if the update do not mutate the object, the resourceVersion
of object won't be changed, that is, the object will not be affected at all.
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.
Check before creation can reduce the API call to kube-apiserver, and I have updated to use GuaranteedUpdate
.
@aylei comments addressed, PTAL again. |
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.
LGTM
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.
LGTM
/merge |
/run-all-tests |
/run-all-tests |
* zh: doc for how to evict tikv pod * zh: fix script syntax * zh: add notes for deprecated commands * zh: add doc to maintain PD instance * Update maintain-a-kubernetes-node.md * fix broken link * Update maintain-a-kubernetes-node.md * Update maintain-a-kubernetes-node.md * Update maintain-a-kubernetes-node.md * Apply suggestions from code review Co-authored-by: Grace Cai <qqzczy@126.com> * fix comments * Apply suggestions from code review Co-authored-by: Grace Cai <qqzczy@126.com> * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Grace Cai <qqzczy@126.com> * fix lint * fix lint Co-authored-by: DanielZhangQD <36026334+DanielZhangQD@users.noreply.github.com> Co-authored-by: Grace Cai <qqzczy@126.com>
What problem does this PR solve?
fix #1262
What is changed and how does it work?
Add controller for TidbInitializer CR
Check List
Tests
Code changes
Side effects
Related changes
Does this PR introduce a user-facing change?: