From 27bb599fde715d04230e774309f426f12740832e Mon Sep 17 00:00:00 2001
From: xhe
Date: Fri, 21 Jul 2023 16:42:34 +0800
Subject: [PATCH] fix: add label overwrite for tiproxy component val
compatibility
Signed-off-by: xhe
---
docs/api-references/docs.md | 10 +++
manifests/crd.yaml | 80 +++++++++++++++++++
manifests/crd/v1/pingcap.com_dmclusters.yaml | 20 +++++
.../crd/v1/pingcap.com_tidbclusters.yaml | 45 +++++++++++
.../crd/v1/pingcap.com_tidbdashboards.yaml | 5 ++
.../crd/v1/pingcap.com_tidbngmonitorings.yaml | 10 +++
pkg/apis/pingcap/v1alpha1/component_spec.go | 9 ++-
pkg/apis/pingcap/v1alpha1/types.go | 4 +-
.../pingcap/v1alpha1/zz_generated.deepcopy.go | 20 ++++-
9 files changed, 198 insertions(+), 5 deletions(-)
diff --git a/docs/api-references/docs.md b/docs/api-references/docs.md
index b18ce3f351d..9f06f5dc03b 100644
--- a/docs/api-references/docs.md
+++ b/docs/api-references/docs.md
@@ -25489,6 +25489,16 @@ LabelSelector is generated by component type
See pkg/apis/pingcap/v1alpha1/tidbcluster_component.go#TopologySpreadConstraints()
+
+
+matchLabels
+
+github.com/pingcap/tidb-operator/pkg/apis/label.Label
+
+ |
+
+ |
+
TxnLocalLatches
diff --git a/manifests/crd.yaml b/manifests/crd.yaml
index e12421ba09e..e7a91b3ed19 100644
--- a/manifests/crd.yaml
+++ b/manifests/crd.yaml
@@ -7451,9 +7451,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -9990,9 +9995,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -10122,9 +10132,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -12590,9 +12605,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -18429,9 +18449,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -21004,9 +21029,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -23538,9 +23568,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -26049,9 +26084,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -28742,9 +28782,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -31291,9 +31336,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -33829,9 +33879,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -36311,9 +36366,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -36349,9 +36409,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -40299,9 +40364,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -47652,9 +47722,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -47790,9 +47865,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
diff --git a/manifests/crd/v1/pingcap.com_dmclusters.yaml b/manifests/crd/v1/pingcap.com_dmclusters.yaml
index d152d8cd2d4..7a727484bf8 100644
--- a/manifests/crd/v1/pingcap.com_dmclusters.yaml
+++ b/manifests/crd/v1/pingcap.com_dmclusters.yaml
@@ -2866,9 +2866,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -5405,9 +5410,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -5537,9 +5547,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -8005,9 +8020,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
diff --git a/manifests/crd/v1/pingcap.com_tidbclusters.yaml b/manifests/crd/v1/pingcap.com_tidbclusters.yaml
index 57da219678d..8406b65e864 100644
--- a/manifests/crd/v1/pingcap.com_tidbclusters.yaml
+++ b/manifests/crd/v1/pingcap.com_tidbclusters.yaml
@@ -2891,9 +2891,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -5466,9 +5471,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -8000,9 +8010,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -10511,9 +10526,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -13204,9 +13224,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -15753,9 +15778,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -18291,9 +18321,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -20773,9 +20808,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -20811,9 +20851,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
diff --git a/manifests/crd/v1/pingcap.com_tidbdashboards.yaml b/manifests/crd/v1/pingcap.com_tidbdashboards.yaml
index 8651a3bbf8c..01c496859a8 100644
--- a/manifests/crd/v1/pingcap.com_tidbdashboards.yaml
+++ b/manifests/crd/v1/pingcap.com_tidbdashboards.yaml
@@ -2534,9 +2534,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
diff --git a/manifests/crd/v1/pingcap.com_tidbngmonitorings.yaml b/manifests/crd/v1/pingcap.com_tidbngmonitorings.yaml
index b3a046dda11..330e23f899e 100644
--- a/manifests/crd/v1/pingcap.com_tidbngmonitorings.yaml
+++ b/manifests/crd/v1/pingcap.com_tidbngmonitorings.yaml
@@ -4795,9 +4795,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
@@ -4933,9 +4938,14 @@ spec:
topologySpreadConstraints:
items:
properties:
+ matchLabels:
+ additionalProperties:
+ type: string
+ type: object
topologyKey:
type: string
required:
+ - matchLabels
- topologyKey
type: object
type: array
diff --git a/pkg/apis/pingcap/v1alpha1/component_spec.go b/pkg/apis/pingcap/v1alpha1/component_spec.go
index 0144def923a..db693d422b5 100644
--- a/pkg/apis/pingcap/v1alpha1/component_spec.go
+++ b/pkg/apis/pingcap/v1alpha1/component_spec.go
@@ -443,8 +443,15 @@ func (a *componentAccessorImpl) TopologySpreadConstraints() []corev1.TopologySpr
case DMClusterKind:
l = label.NewDM()
}
+ if v, ok := tsc.MatchLabels[label.ComponentLabelKey]; ok {
+ componentLabelVal = v
+ }
l[label.ComponentLabelKey] = componentLabelVal
- l[label.InstanceLabelKey] = a.name
+ instanceLabelVal := a.name
+ if v, ok := tsc.MatchLabels[label.InstanceLabelKey]; ok {
+ instanceLabelVal = v
+ }
+ l[label.InstanceLabelKey] = instanceLabelVal
ptsc.LabelSelector = &metav1.LabelSelector{
MatchLabels: map[string]string(l),
}
diff --git a/pkg/apis/pingcap/v1alpha1/types.go b/pkg/apis/pingcap/v1alpha1/types.go
index 46d2ce43a77..217332f2c27 100644
--- a/pkg/apis/pingcap/v1alpha1/types.go
+++ b/pkg/apis/pingcap/v1alpha1/types.go
@@ -21,6 +21,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
+ "github.com/pingcap/tidb-operator/pkg/apis/label"
"github.com/pingcap/tidb-operator/pkg/apis/util/config"
)
@@ -3001,7 +3002,8 @@ type TopologySpreadConstraint struct {
// WhenUnsatisfiable is default set to DoNotSchedule
// LabelSelector is generated by component type
// See pkg/apis/pingcap/v1alpha1/tidbcluster_component.go#TopologySpreadConstraints()
- TopologyKey string `json:"topologyKey"`
+ TopologyKey string `json:"topologyKey"`
+ MatchLabels label.Label `json:"matchLabels"`
}
// Failover contains the failover specification.
diff --git a/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go
index bba199a9ab4..1a4aed7b285 100644
--- a/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go
+++ b/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go
@@ -21,6 +21,7 @@ package v1alpha1
import (
time "time"
+ label "github.com/pingcap/tidb-operator/pkg/apis/label"
model "github.com/prometheus/common/model"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
@@ -981,7 +982,9 @@ func (in *ComponentSpec) DeepCopyInto(out *ComponentSpec) {
if in.TopologySpreadConstraints != nil {
in, out := &in.TopologySpreadConstraints, &out.TopologySpreadConstraints
*out = make([]TopologySpreadConstraint, len(*in))
- copy(*out, *in)
+ for i := range *in {
+ (*in)[i].DeepCopyInto(&(*out)[i])
+ }
}
if in.SuspendAction != nil {
in, out := &in.SuspendAction, &out.SuspendAction
@@ -1284,7 +1287,9 @@ func (in *DMClusterSpec) DeepCopyInto(out *DMClusterSpec) {
if in.TopologySpreadConstraints != nil {
in, out := &in.TopologySpreadConstraints, &out.TopologySpreadConstraints
*out = make([]TopologySpreadConstraint, len(*in))
- copy(*out, *in)
+ for i := range *in {
+ (*in)[i].DeepCopyInto(&(*out)[i])
+ }
}
if in.SuspendAction != nil {
in, out := &in.SuspendAction, &out.SuspendAction
@@ -9044,7 +9049,9 @@ func (in *TidbClusterSpec) DeepCopyInto(out *TidbClusterSpec) {
if in.TopologySpreadConstraints != nil {
in, out := &in.TopologySpreadConstraints, &out.TopologySpreadConstraints
*out = make([]TopologySpreadConstraint, len(*in))
- copy(*out, *in)
+ for i := range *in {
+ (*in)[i].DeepCopyInto(&(*out)[i])
+ }
}
if in.SuspendAction != nil {
in, out := &in.SuspendAction, &out.SuspendAction
@@ -9773,6 +9780,13 @@ func (in *TikvAutoScalerStatus) DeepCopy() *TikvAutoScalerStatus {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *TopologySpreadConstraint) DeepCopyInto(out *TopologySpreadConstraint) {
*out = *in
+ if in.MatchLabels != nil {
+ in, out := &in.MatchLabels, &out.MatchLabels
+ *out = make(label.Label, len(*in))
+ for key, val := range *in {
+ (*out)[key] = val
+ }
+ }
return
}