Skip to content

Commit 6941259

Browse files
fix: preserve legacy DM app label (#6925)
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 839a3fc commit 6941259

5 files changed

Lines changed: 19 additions & 1 deletion

File tree

pkg/controllers/dm/tasks/pod.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ func newPod(cluster *v1alpha1.Cluster, dm *v1alpha1.DM) *corev1.Pod {
161161
},
162162
// TODO: remove it
163163
k8s.LabelsK8sApp(cluster.Name, v1alpha1.LabelValComponentDMMaster),
164+
map[string]string{
165+
// Keep the legacy DM app name for user monitoring collectors that select DM metrics by this label.
166+
k8s.LabelKeyK8sAppName: k8s.LabelValK8sAppNameDMCluster,
167+
},
164168
),
165169
OwnerReferences: []metav1.OwnerReference{
166170
*metav1.NewControllerRef(dm, v1alpha1.SchemeGroupVersion.WithKind("DM")),

pkg/controllers/dm/tasks/pod_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/pingcap/tidb-operator/api/v2/core/v1alpha1"
2828
"github.com/pingcap/tidb-operator/v2/pkg/client"
2929
"github.com/pingcap/tidb-operator/v2/pkg/utils/fake"
30+
"github.com/pingcap/tidb-operator/v2/pkg/utils/k8s"
3031
"github.com/pingcap/tidb-operator/v2/pkg/utils/task/v3"
3132
)
3233

@@ -118,6 +119,7 @@ func TestTaskPod(t *testing.T) {
118119
require.Len(t, pod.Spec.Containers, 1)
119120
assert.Equal(t, []string{"/dm-master", "--config", "/etc/dm-master/config.toml"}, pod.Spec.Containers[0].Command)
120121
assert.Equal(t, v1alpha1.LabelValComponentDMMaster, pod.Labels[v1alpha1.LabelKeyComponent])
122+
assert.Equal(t, k8s.LabelValK8sAppNameDMCluster, pod.Labels[k8s.LabelKeyK8sAppName])
121123
assert.Len(t, pod.Spec.Containers[0].Ports, 2)
122124
assert.Equal(t, int32(8261), pod.Spec.Containers[0].Ports[0].ContainerPort)
123125
assert.Equal(t, int32(8291), pod.Spec.Containers[0].Ports[1].ContainerPort)

pkg/controllers/dmworker/tasks/pod.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ func newPod(cluster *v1alpha1.Cluster, dw *v1alpha1.DMWorker) *corev1.Pod {
161161
v1alpha1.LabelKeyClusterID: cluster.Status.ID,
162162
},
163163
k8s.LabelsK8sApp(cluster.Name, v1alpha1.LabelValComponentDMWorker),
164+
map[string]string{
165+
// Keep the legacy DM app name for user monitoring collectors that select DM metrics by this label.
166+
k8s.LabelKeyK8sAppName: k8s.LabelValK8sAppNameDMCluster,
167+
},
164168
),
165169
OwnerReferences: []metav1.OwnerReference{
166170
*metav1.NewControllerRef(dw, v1alpha1.SchemeGroupVersion.WithKind("DMWorker")),

pkg/controllers/dmworker/tasks/pod_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/pingcap/tidb-operator/api/v2/core/v1alpha1"
2828
"github.com/pingcap/tidb-operator/v2/pkg/client"
2929
"github.com/pingcap/tidb-operator/v2/pkg/utils/fake"
30+
"github.com/pingcap/tidb-operator/v2/pkg/utils/k8s"
3031
"github.com/pingcap/tidb-operator/v2/pkg/utils/task/v3"
3132
)
3233

@@ -93,6 +94,7 @@ func TestTaskPod(t *testing.T) {
9394
require.Len(t, pod.Spec.Containers, 1)
9495
assert.Equal(t, []string{"/dm-worker", "--config", "/etc/dm-worker/config.toml"}, pod.Spec.Containers[0].Command)
9596
assert.Equal(t, v1alpha1.LabelValComponentDMWorker, pod.Labels[v1alpha1.LabelKeyComponent])
97+
assert.Equal(t, k8s.LabelValK8sAppNameDMCluster, pod.Labels[k8s.LabelKeyK8sAppName])
9698
require.Len(t, pod.Spec.Containers[0].Ports, 1)
9799
assert.Equal(t, int32(8262), pod.Spec.Containers[0].Ports[0].ContainerPort)
98100
})

pkg/utils/k8s/pod.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ import (
2323
"github.com/pingcap/tidb-operator/api/v2/core/v1alpha1"
2424
)
2525

26+
const (
27+
LabelKeyK8sAppName = "app.kubernetes.io/name"
28+
LabelValK8sAppNameTiDB = "tidb-cluster"
29+
LabelValK8sAppNameDMCluster = "dm-cluster"
30+
)
31+
2632
func GetResourceRequirements(req v1alpha1.ResourceRequirements) corev1.ResourceRequirements {
2733
if req.CPU == nil && req.Memory == nil {
2834
return corev1.ResourceRequirements{}
@@ -68,6 +74,6 @@ func LabelsK8sApp(cluster, component string) map[string]string {
6874
"app.kubernetes.io/component": component,
6975
"app.kubernetes.io/instance": cluster,
7076
"app.kubernetes.io/managed-by": "tidb-operator",
71-
"app.kubernetes.io/name": "tidb-cluster",
77+
LabelKeyK8sAppName: LabelValK8sAppNameTiDB,
7278
}
7379
}

0 commit comments

Comments
 (0)