-
Notifications
You must be signed in to change notification settings - Fork 499
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
sync tidb configmap in controller #1291
Conversation
/run-e2e-test |
3 similar comments
/run-e2e-test |
/run-e2e-test |
/run-e2e-test |
/run-e2e-test |
pkg/controller/configmap_control.go
Outdated
cmC.Labels = cmD.Labels | ||
for k, v := range cmD.Annotations { | ||
cmC.Annotations[k] = v | ||
} |
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.
why we must keep old annotations?
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 is not a must. I preserve the un-overridden annotations deliberately, which allows user and third-party components could safely add their annotations (as long as the annotation key is not taken by tidb-operator) to resources owned by TidbCluster.
ns := tc.GetNamespace() | ||
tcName := tc.GetName() | ||
instanceName := tc.GetLabels()[label.InstanceLabelKey] | ||
tidbConfigMap := controller.MemberConfigMapName(tc, v1alpha1.TiDBMemberType) | ||
if cm != nil { | ||
tidbConfigMap = cm.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.
in which case, cm will be 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.
when .spec.tidb.config
is nil
Signed-off-by: Aylei <rayingecho@gmail.com> unified grep command for mac and linux (pingcap#1285) Refactor apply Signed-off-by: Aylei <rayingecho@gmail.com> pdapi: only read secret for PD client cert (on TLS enabled clusters) … (pingcap#1290) * pdapi: only read secret for PD client cert (on TLS enabled clusters) when needed * pdapi: adjust log message * pdapi: fix error in logging Remove DinD related scripts and document (pingcap#1283) * Remove DinD related scripts * Remove local-dind-tutorial doc * drop dind part from CONTRIBUTING guide. Fix configmap ownerreference Signed-off-by: Aylei <rayingecho@gmail.com>
/run-e2e-test |
I'm not quite satisfied with the generalization made in this PR and find that Marked as |
Signed-off-by: Aylei <rayingecho@gmail.com>
/run-e2e-test |
|
||
// GenericControlInterface manages generic object that managed by an arbitrary controller | ||
type GenericControlInterface interface { | ||
CreateOrUpdate(controller, obj runtime.Object, mergeFn MergeFn) (runtime.Object, error) |
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.
Apply
is ambiguous with the server-side apply
of kubernetes, rename to CreateOrUpdate
|
||
// 5. check if the copy is actually mutated | ||
if !apiequality.Semantic.DeepEqual(existing, mutated) { | ||
err := c.client.Update(context.TODO(), mutated) |
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.
Optionally, we could retry on conflict like other controls do, I choose no retry here because CreateOrUpdate
will never meet conflicts if there is no concurrent modification, and if there are concurrent modifications, it is better to return the error to caller instead of aggressive retrying.
@@ -114,6 +116,11 @@ func main() { | |||
if err != nil { | |||
glog.Fatalf("failed to get advanced-statefulset Clientset: %v", err) | |||
} | |||
// TODO: optimize the read of genericCli with the shared cache | |||
genericCli, err := client.New(cfg, client.Options{Scheme: scheme.Scheme}) |
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.
Using the client of controller-runtime
without using the informer
of controller-runtime
has a drawback that all read operations will go to kube-apiserver, it is acceptable now because the only read operation is to get the latest version when perform a CreateOrUpdate
.
// override. Note that aggressive override usually causes unnecessary updates because the object will be mutated | ||
// after POST/PUT to api-server (e.g. Defaulting), an annotation based technique could be used to avoid such | ||
// updating: set a last-applied-config annotation and diff the annotation instead of the real spec. | ||
type MergeFn func(existing, desired runtime.Object) error |
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.
server-side apply
maybe a better solution in the future.
ref: https://kubernetes.io/docs/reference/using-api/api-concepts/#server-side-apply
Signed-off-by: Aylei <rayingecho@gmail.com>
/run-e2e-test |
/run-e2e-test |
1 similar comment
/run-e2e-test |
Signed-off-by: Aylei <rayingecho@gmail.com>
/run-e2e-test |
/run-e2e-test |
/run-e2e-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.
LGTM
/run-e2e-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.
Rest LGTM
pkg/controller/configmap_control.go
Outdated
UpdateConfigMap(*v1alpha1.TidbCluster, *corev1.ConfigMap) (*corev1.ConfigMap, error) | ||
DeleteConfigMap(*v1alpha1.TidbCluster, *corev1.ConfigMap) error | ||
// CreateConfigMap create the given ConfigMap | ||
CreateConfigMap(runtime.Object, *corev1.ConfigMap) (*corev1.ConfigMap, error) |
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.
Should add a comment for what the runtime.Object
is.
if config.Security == nil { | ||
config.Security = &v1alpha1.Security{} | ||
} | ||
config.Security.ClusterSSLCA = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" |
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's better to define these 3 paths as constant.
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.
Good catch!
Signed-off-by: Aylei <rayingecho@gmail.com>
/run-e2e-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.
LGTM
Signed-off-by: Aylei rayingecho@gmail.com
What problem does this PR solve?
close #1192
What is changed and how does it work?
New controller logic to sync tidb configmap.
Generify the
CreateOrUpdate
logic and the template rendering code.This PR introduce a new dependency
controller-runtime
in favor of its generic client for kubernetes.Check List
Tests
Does this PR introduce a user-facing change?:
check the e2e case to get an overview of this PR: https://github.com/pingcap/tidb-operator/pull/1291/files#diff-92579a43c91e473b9716eeeee2068004
@onlymellb @cofyc @tennix @weekface @Yisaer PTAL