From 92e73316d09500a64130214596f1019392591543 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 17 May 2019 18:39:09 +0800 Subject: [PATCH 1/3] allow custom pod annotations --- charts/tidb-cluster/templates/tidb-cluster.yaml | 12 ++++++++++++ charts/tidb-cluster/values.yaml | 3 +++ images/tidb-operator-e2e/tidb-cluster-values.yaml | 3 +++ pkg/apis/pingcap.com/v1alpha1/types.go | 3 +++ pkg/manager/member/pd_member_manager.go | 3 ++- pkg/manager/member/tidb_member_manager.go | 3 ++- pkg/manager/member/tikv_member_manager.go | 3 ++- pkg/manager/member/utils.go | 8 ++++++++ 8 files changed, 35 insertions(+), 3 deletions(-) diff --git a/charts/tidb-cluster/templates/tidb-cluster.yaml b/charts/tidb-cluster/templates/tidb-cluster.yaml index c8e85bafd3..b27c85773d 100644 --- a/charts/tidb-cluster/templates/tidb-cluster.yaml +++ b/charts/tidb-cluster/templates/tidb-cluster.yaml @@ -41,6 +41,10 @@ spec: {{- if .Values.pd.tolerations }} tolerations: {{ toYaml .Values.pd.tolerations | indent 4 }} + {{- end }} + {{- if .Values.pd.annotations }} + annotations: +{{ toYaml .Values.pd.annotations | indent 6 }} {{- end }} tikv: replicas: {{ .Values.tikv.replicas }} @@ -60,6 +64,10 @@ spec: {{- if .Values.tikv.tolerations }} tolerations: {{ toYaml .Values.tikv.tolerations | indent 4 }} + {{- end }} + {{- if .Values.tikv.annotations }} + annotations: +{{ toYaml .Values.tikv.annotations | indent 6 }} {{- end }} tidb: replicas: {{ .Values.tidb.replicas }} @@ -76,6 +84,10 @@ spec: {{- if .Values.tidb.tolerations }} tolerations: {{ toYaml .Values.tidb.tolerations | indent 4 }} + {{- end }} + {{- if .Values.tidb.annotations }} + annotations: +{{ toYaml .Values.tidb.annotations | indent 6 }} {{- end }} binlogEnabled: {{ .Values.binlog.pump.create | default false }} maxFailoverCount: {{ .Values.tidb.maxFailoverCount | default 3 }} diff --git a/charts/tidb-cluster/values.yaml b/charts/tidb-cluster/values.yaml index 8a9a5a4f90..645072caac 100644 --- a/charts/tidb-cluster/values.yaml +++ b/charts/tidb-cluster/values.yaml @@ -88,6 +88,7 @@ pd: # operator: Equal # value: tidb # effect: "NoSchedule" + annotations: {} tikv: replicas: 3 @@ -125,6 +126,7 @@ tikv: # operator: Equal # value: tidb # effect: "NoSchedule" + annotations: {} # block-cache used to cache uncompressed blocks, big block-cache can speed up read. # in normal cases should tune to 30%-50% tikv.resources.limits.memory @@ -203,6 +205,7 @@ tidb: # operator: Equal # value: tidb # effect: "NoSchedule" + annotations: {} maxFailoverCount: 3 service: type: NodePort diff --git a/images/tidb-operator-e2e/tidb-cluster-values.yaml b/images/tidb-operator-e2e/tidb-cluster-values.yaml index 29d7da8667..a85e13a0f4 100644 --- a/images/tidb-operator-e2e/tidb-cluster-values.yaml +++ b/images/tidb-operator-e2e/tidb-cluster-values.yaml @@ -73,6 +73,7 @@ pd: # operator: Equal # value: tidb # effect: "NoSchedule" + annotations: {} tikv: replicas: 3 @@ -106,6 +107,7 @@ tikv: # operator: Equal # value: tidb # effect: "NoSchedule" + annotations: {} tikvPromGateway: image: prom/pushgateway:v0.3.1 @@ -146,6 +148,7 @@ tidb: # operator: Equal # value: tidb # effect: "NoSchedule" + annotations: {} maxFailoverCount: 3 service: type: NodePort diff --git a/pkg/apis/pingcap.com/v1alpha1/types.go b/pkg/apis/pingcap.com/v1alpha1/types.go index b45d17aaaa..26f5f9f86d 100644 --- a/pkg/apis/pingcap.com/v1alpha1/types.go +++ b/pkg/apis/pingcap.com/v1alpha1/types.go @@ -112,6 +112,7 @@ type PDSpec struct { NodeSelectorRequired bool `json:"nodeSelectorRequired,omitempty"` StorageClassName string `json:"storageClassName,omitempty"` Tolerations []corev1.Toleration `json:"tolerations,omitempty"` + Annotations map[string]string `json:"annotations,omitempty"` } // TiDBSpec contains details of PD member @@ -122,6 +123,7 @@ type TiDBSpec struct { NodeSelectorRequired bool `json:"nodeSelectorRequired,omitempty"` StorageClassName string `json:"storageClassName,omitempty"` Tolerations []corev1.Toleration `json:"tolerations,omitempty"` + Annotations map[string]string `json:"annotations,omitempty"` BinlogEnabled bool `json:"binlogEnabled,omitempty"` MaxFailoverCount int32 `json:"maxFailoverCount,omitempty"` SeparateSlowLog bool `json:"separateSlowLog,omitempty"` @@ -141,6 +143,7 @@ type TiKVSpec struct { NodeSelectorRequired bool `json:"nodeSelectorRequired,omitempty"` StorageClassName string `json:"storageClassName,omitempty"` Tolerations []corev1.Toleration `json:"tolerations,omitempty"` + Annotations map[string]string `json:"annotations,omitempty"` } // TiKVPromGatewaySpec runs as a sidecar with TiKVSpec diff --git a/pkg/manager/member/pd_member_manager.go b/pkg/manager/member/pd_member_manager.go index 3127af5f89..b2a7edb6e8 100644 --- a/pkg/manager/member/pd_member_manager.go +++ b/pkg/manager/member/pd_member_manager.go @@ -448,6 +448,7 @@ func (pmm *pdMemberManager) getNewPDSetForTidbCluster(tc *v1alpha1.TidbCluster) } pdLabel := label.New().Instance(instanceName).PD() setName := controller.PDMemberName(tcName) + podAnnotations := CombineAnnotations(controller.AnnProm(2379), tc.Spec.PD.Annotations) storageClassName := tc.Spec.PD.StorageClassName if storageClassName == "" { storageClassName = controller.DefaultStorageClassName @@ -472,7 +473,7 @@ func (pmm *pdMemberManager) getNewPDSetForTidbCluster(tc *v1alpha1.TidbCluster) Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: pdLabel.Labels(), - Annotations: controller.AnnProm(2379), + Annotations: podAnnotations, }, Spec: corev1.PodSpec{ SchedulerName: tc.Spec.SchedulerName, diff --git a/pkg/manager/member/tidb_member_manager.go b/pkg/manager/member/tidb_member_manager.go index 3cffaa5820..412b79d50f 100644 --- a/pkg/manager/member/tidb_member_manager.go +++ b/pkg/manager/member/tidb_member_manager.go @@ -330,6 +330,7 @@ func (tmm *tidbMemberManager) getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbClust }) tidbLabel := label.New().Instance(instanceName).TiDB() + podAnnotations := CombineAnnotations(controller.AnnProm(10080), tc.Spec.TiDB.Annotations) tidbSet := &apps.StatefulSet{ ObjectMeta: metav1.ObjectMeta{ Name: controller.TiDBMemberName(tcName), @@ -343,7 +344,7 @@ func (tmm *tidbMemberManager) getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbClust Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: tidbLabel.Labels(), - Annotations: controller.AnnProm(10080), + Annotations: podAnnotations, }, Spec: corev1.PodSpec{ SchedulerName: tc.Spec.SchedulerName, diff --git a/pkg/manager/member/tikv_member_manager.go b/pkg/manager/member/tikv_member_manager.go index 18a4ab0b0b..624dff9a75 100644 --- a/pkg/manager/member/tikv_member_manager.go +++ b/pkg/manager/member/tikv_member_manager.go @@ -311,6 +311,7 @@ func (tkmm *tikvMemberManager) getNewSetForTidbCluster(tc *v1alpha1.TidbCluster) tikvLabel := tkmm.labelTiKV(tc) setName := controller.TiKVMemberName(tcName) + podAnnotations := CombineAnnotations(controller.AnnProm(20180), tc.Spec.TiKV.Annotations) capacity := controller.TiKVCapacity(tc.Spec.TiKV.Limits) headlessSvcName := controller.TiKVPeerMemberName(tcName) storageClassName := tc.Spec.TiKV.StorageClassName @@ -331,7 +332,7 @@ func (tkmm *tikvMemberManager) getNewSetForTidbCluster(tc *v1alpha1.TidbCluster) Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: tikvLabel.Labels(), - Annotations: controller.AnnProm(20180), + Annotations: podAnnotations, }, Spec: corev1.PodSpec{ SchedulerName: tc.Spec.SchedulerName, diff --git a/pkg/manager/member/utils.go b/pkg/manager/member/utils.go index e3d95a1032..b5f7696137 100644 --- a/pkg/manager/member/utils.go +++ b/pkg/manager/member/utils.go @@ -203,3 +203,11 @@ func pdPodName(tcName string, ordinal int32) string { func tidbPodName(tcName string, ordinal int32) string { return fmt.Sprintf("%s-%d", controller.TiDBMemberName(tcName), ordinal) } + +// CombineAnnotations merges two annotations maps +func CombineAnnotations(a map[string]string, b map[string]string) map[string]string { + for k, v := range b { + a[k] = v + } + return a +} From ad7c97e3ff2def21e301adb06f2deac07b547a62 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 17 May 2019 20:38:09 +0800 Subject: [PATCH 2/3] fix CombineAnnotations func --- pkg/manager/member/utils.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/manager/member/utils.go b/pkg/manager/member/utils.go index b5f7696137..72ce57d2cc 100644 --- a/pkg/manager/member/utils.go +++ b/pkg/manager/member/utils.go @@ -205,9 +205,13 @@ func tidbPodName(tcName string, ordinal int32) string { } // CombineAnnotations merges two annotations maps -func CombineAnnotations(a map[string]string, b map[string]string) map[string]string { +func CombineAnnotations(a, b map[string]string) map[string]string { + m := make(map[string]string) + for k, v := range a { + m[k] = v + } for k, v := range b { - a[k] = v + m[k] = v } - return a + return m } From c433b89174e4e7de8e1cec6592e64ec8251d3720 Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 21 May 2019 10:28:42 +0800 Subject: [PATCH 3/3] add generated deepcopy file --- .../v1alpha1/zz_generated.deepcopy.go | 21 +++++++++++++++++++ pkg/manager/member/utils.go | 9 ++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/pkg/apis/pingcap.com/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/pingcap.com/v1alpha1/zz_generated.deepcopy.go index 9ae44e85c5..9304c82205 100644 --- a/pkg/apis/pingcap.com/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/pingcap.com/v1alpha1/zz_generated.deepcopy.go @@ -103,6 +103,13 @@ func (in *PDSpec) DeepCopyInto(out *PDSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.Annotations != nil { + in, out := &in.Annotations, &out.Annotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } return } @@ -252,6 +259,13 @@ func (in *TiDBSpec) DeepCopyInto(out *TiDBSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.Annotations != nil { + in, out := &in.Annotations, &out.Annotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } in.SlowLogTailer.DeepCopyInto(&out.SlowLogTailer) return } @@ -352,6 +366,13 @@ func (in *TiKVSpec) DeepCopyInto(out *TiKVSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.Annotations != nil { + in, out := &in.Annotations, &out.Annotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } return } diff --git a/pkg/manager/member/utils.go b/pkg/manager/member/utils.go index 72ce57d2cc..a9c27d7506 100644 --- a/pkg/manager/member/utils.go +++ b/pkg/manager/member/utils.go @@ -206,12 +206,11 @@ func tidbPodName(tcName string, ordinal int32) string { // CombineAnnotations merges two annotations maps func CombineAnnotations(a, b map[string]string) map[string]string { - m := make(map[string]string) - for k, v := range a { - m[k] = v + if a == nil { + a = make(map[string]string) } for k, v := range b { - m[k] = v + a[k] = v } - return m + return a }