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 866d4cdf36..b51d8797bb 100644 --- a/images/tidb-operator-e2e/tidb-cluster-values.yaml +++ b/images/tidb-operator-e2e/tidb-cluster-values.yaml @@ -77,6 +77,7 @@ pd: # operator: Equal # value: tidb # effect: "NoSchedule" + annotations: {} tikv: replicas: 3 @@ -110,6 +111,7 @@ tikv: # operator: Equal # value: tidb # effect: "NoSchedule" + annotations: {} tikvPromGateway: image: prom/pushgateway:v0.3.1 @@ -150,6 +152,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/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/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..a9c27d7506 100644 --- a/pkg/manager/member/utils.go +++ b/pkg/manager/member/utils.go @@ -203,3 +203,14 @@ 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, b map[string]string) map[string]string { + if a == nil { + a = make(map[string]string) + } + for k, v := range b { + a[k] = v + } + return a +}