From 90a4b73d4e587dc8f15e74579fb4ac92a82fd7db Mon Sep 17 00:00:00 2001 From: liyang Date: Tue, 26 Nov 2024 17:14:38 +0800 Subject: [PATCH] feat: Add label for the greptimedb services and controllers (#223) --- controllers/greptimedbcluster/deployers/datanode.go | 6 ++++++ controllers/greptimedbcluster/deployers/flownode.go | 6 ++++++ controllers/greptimedbcluster/deployers/frontend.go | 7 ++++++- controllers/greptimedbcluster/deployers/meta.go | 6 ++++++ controllers/greptimedbstandalone/deployer.go | 7 ++++++- 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/controllers/greptimedbcluster/deployers/datanode.go b/controllers/greptimedbcluster/deployers/datanode.go index 4a023d9..b7832ed 100644 --- a/controllers/greptimedbcluster/deployers/datanode.go +++ b/controllers/greptimedbcluster/deployers/datanode.go @@ -324,6 +324,9 @@ func (b *datanodeBuilder) BuildService() deployer.Builder { ObjectMeta: metav1.ObjectMeta{ Namespace: b.Cluster.Namespace, Name: common.ResourceName(b.Cluster.Name, b.ComponentKind), + Labels: map[string]string{ + constant.GreptimeDBComponentName: common.ResourceName(b.Cluster.Name, b.ComponentKind), + }, }, Spec: corev1.ServiceSpec{ ClusterIP: corev1.ClusterIPNone, @@ -376,6 +379,9 @@ func (b *datanodeBuilder) BuildStatefulSet() deployer.Builder { ObjectMeta: metav1.ObjectMeta{ Name: common.ResourceName(b.Cluster.Name, b.ComponentKind), Namespace: b.Cluster.Namespace, + Labels: map[string]string{ + constant.GreptimeDBComponentName: common.ResourceName(b.Cluster.Name, b.ComponentKind), + }, }, Spec: appsv1.StatefulSetSpec{ PodManagementPolicy: appsv1.ParallelPodManagement, diff --git a/controllers/greptimedbcluster/deployers/flownode.go b/controllers/greptimedbcluster/deployers/flownode.go index cd890ab..8ee416a 100644 --- a/controllers/greptimedbcluster/deployers/flownode.go +++ b/controllers/greptimedbcluster/deployers/flownode.go @@ -130,6 +130,9 @@ func (b *flownodeBuilder) BuildService() deployer.Builder { ObjectMeta: metav1.ObjectMeta{ Namespace: b.Cluster.Namespace, Name: common.ResourceName(b.Cluster.Name, b.ComponentKind), + Labels: map[string]string{ + constant.GreptimeDBComponentName: common.ResourceName(b.Cluster.Name, b.ComponentKind), + }, }, Spec: corev1.ServiceSpec{ ClusterIP: corev1.ClusterIPNone, @@ -182,6 +185,9 @@ func (b *flownodeBuilder) BuildStatefulSet() deployer.Builder { ObjectMeta: metav1.ObjectMeta{ Name: common.ResourceName(b.Cluster.Name, b.ComponentKind), Namespace: b.Cluster.Namespace, + Labels: map[string]string{ + constant.GreptimeDBComponentName: common.ResourceName(b.Cluster.Name, b.ComponentKind), + }, }, Spec: appsv1.StatefulSetSpec{ PodManagementPolicy: appsv1.ParallelPodManagement, diff --git a/controllers/greptimedbcluster/deployers/frontend.go b/controllers/greptimedbcluster/deployers/frontend.go index e1a6d87..18e1917 100644 --- a/controllers/greptimedbcluster/deployers/frontend.go +++ b/controllers/greptimedbcluster/deployers/frontend.go @@ -127,7 +127,9 @@ func (b *frontendBuilder) BuildService() deployer.Builder { Namespace: b.Cluster.Namespace, Name: common.ResourceName(b.Cluster.Name, b.ComponentKind), Annotations: b.Cluster.Spec.Frontend.Service.Annotations, - Labels: b.Cluster.Spec.Frontend.Service.Labels, + Labels: util.MergeStringMap(b.Cluster.Spec.Frontend.Service.Labels, map[string]string{ + constant.GreptimeDBComponentName: common.ResourceName(b.Cluster.Name, b.ComponentKind), + }), }, Spec: corev1.ServiceSpec{ Type: b.Cluster.Spec.Frontend.Service.Type, @@ -161,6 +163,9 @@ func (b *frontendBuilder) BuildDeployment() deployer.Builder { ObjectMeta: metav1.ObjectMeta{ Name: common.ResourceName(b.Cluster.Name, b.ComponentKind), Namespace: b.Cluster.Namespace, + Labels: map[string]string{ + constant.GreptimeDBComponentName: common.ResourceName(b.Cluster.Name, b.ComponentKind), + }, }, Spec: appsv1.DeploymentSpec{ Replicas: b.Cluster.Spec.Frontend.Replicas, diff --git a/controllers/greptimedbcluster/deployers/meta.go b/controllers/greptimedbcluster/deployers/meta.go index fb88f7f..9a79039 100644 --- a/controllers/greptimedbcluster/deployers/meta.go +++ b/controllers/greptimedbcluster/deployers/meta.go @@ -206,6 +206,9 @@ func (b *metaBuilder) BuildService() deployer.Builder { ObjectMeta: metav1.ObjectMeta{ Namespace: b.Cluster.Namespace, Name: common.ResourceName(b.Cluster.Name, b.ComponentKind), + Labels: map[string]string{ + constant.GreptimeDBComponentName: common.ResourceName(b.Cluster.Name, b.ComponentKind), + }, }, Spec: corev1.ServiceSpec{ Type: corev1.ServiceTypeClusterIP, @@ -238,6 +241,9 @@ func (b *metaBuilder) BuildDeployment() deployer.Builder { ObjectMeta: metav1.ObjectMeta{ Name: common.ResourceName(b.Cluster.Name, b.ComponentKind), Namespace: b.Cluster.Namespace, + Labels: map[string]string{ + constant.GreptimeDBComponentName: common.ResourceName(b.Cluster.Name, b.ComponentKind), + }, }, Spec: appsv1.DeploymentSpec{ Replicas: b.Cluster.Spec.Meta.Replicas, diff --git a/controllers/greptimedbstandalone/deployer.go b/controllers/greptimedbstandalone/deployer.go index 8857d60..e05ca13 100644 --- a/controllers/greptimedbstandalone/deployer.go +++ b/controllers/greptimedbstandalone/deployer.go @@ -190,7 +190,9 @@ func (b *standaloneBuilder) BuildService() deployer.Builder { Namespace: b.standalone.Namespace, Name: common.ResourceName(b.standalone.Name, v1alpha1.StandaloneKind), Annotations: b.standalone.Spec.Service.Annotations, - Labels: b.standalone.Spec.Service.Labels, + Labels: util.MergeStringMap(b.standalone.Spec.Service.Labels, map[string]string{ + constant.GreptimeDBComponentName: common.ResourceName(b.standalone.Name, v1alpha1.StandaloneKind), + }), }, Spec: corev1.ServiceSpec{ Type: b.standalone.Spec.Service.Type, @@ -242,6 +244,9 @@ func (b *standaloneBuilder) BuildStatefulSet() deployer.Builder { ObjectMeta: metav1.ObjectMeta{ Name: common.ResourceName(b.standalone.Name, v1alpha1.StandaloneKind), Namespace: b.standalone.Namespace, + Labels: map[string]string{ + constant.GreptimeDBComponentName: common.ResourceName(b.standalone.Name, v1alpha1.StandaloneKind), + }, }, Spec: appsv1.StatefulSetSpec{ // Always set replicas to 1 for standalone mode.