From f8fe41cb7f21fe9b58364c34c01ab01ec64254be Mon Sep 17 00:00:00 2001 From: John Maguire Date: Wed, 20 Dec 2023 11:46:41 -0500 Subject: [PATCH] [NET-6809] Add chart related labels for mesh gateway deployments (#3396) * use set labels for setting labels on deployments * incorporate changes for setting labels --- control-plane/gateways/deployment_test.go | 44 ++++++++++++++++++++--- control-plane/gateways/service_test.go | 28 +++++++++++++-- 2 files changed, 65 insertions(+), 7 deletions(-) diff --git a/control-plane/gateways/deployment_test.go b/control-plane/gateways/deployment_test.go index 4f682a16ec..328d6b2026 100644 --- a/control-plane/gateways/deployment_test.go +++ b/control-plane/gateways/deployment_test.go @@ -42,6 +42,16 @@ func Test_meshGatewayBuilder_Deployment(t *testing.T) { config: GatewayConfig{}, gcc: &meshv2beta1.GatewayClassConfig{ Spec: meshv2beta1.GatewayClassConfigSpec{ + GatewayClassAnnotationsAndLabels: meshv2beta1.GatewayClassAnnotationsAndLabels{ + Labels: meshv2beta1.GatewayClassAnnotationsLabelsConfig{ + Set: map[string]string{ + "app": "consul", + "chart": "consul-helm", + "heritage": "Helm", + "release": "consul", + }, + }, + }, Deployment: meshv2beta1.GatewayClassDeploymentConfig{ Container: &meshv2beta1.GatewayClassContainerConfig{ HostPort: 8080, @@ -67,17 +77,37 @@ func Test_meshGatewayBuilder_Deployment(t *testing.T) { }, want: &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ - Labels: defaultLabels, + Labels: map[string]string{ + labelManagedBy: "consul-k8s", + "app": "consul", + "chart": "consul-helm", + "heritage": "Helm", + "release": "consul", + }, + Annotations: map[string]string{}, }, Spec: appsv1.DeploymentSpec{ Replicas: pointer.Int32(1), Selector: &metav1.LabelSelector{ - MatchLabels: defaultLabels, + MatchLabels: map[string]string{ + labelManagedBy: "consul-k8s", + "app": "consul", + "chart": "consul-helm", + "heritage": "Helm", + "release": "consul", + }, }, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ - Labels: defaultLabels, + Labels: map[string]string{ + labelManagedBy: "consul-k8s", + "app": "consul", + "chart": "consul-helm", + "heritage": "Helm", + "release": "consul", + }, + Annotations: map[string]string{ constants.AnnotationGatewayKind: meshGatewayAnnotationKind, constants.AnnotationMeshInject: "false", @@ -281,7 +311,13 @@ func Test_meshGatewayBuilder_Deployment(t *testing.T) { Weight: 1, PodAffinityTerm: corev1.PodAffinityTerm{ LabelSelector: &metav1.LabelSelector{ - MatchLabels: defaultLabels, + MatchLabels: map[string]string{ + labelManagedBy: "consul-k8s", + "app": "consul", + "chart": "consul-helm", + "heritage": "Helm", + "release": "consul", + }, }, TopologyKey: "kubernetes.io/hostname", }, diff --git a/control-plane/gateways/service_test.go b/control-plane/gateways/service_test.go index 3ec9251b83..3796e5ea56 100644 --- a/control-plane/gateways/service_test.go +++ b/control-plane/gateways/service_test.go @@ -39,6 +39,16 @@ func Test_meshGatewayBuilder_Service(t *testing.T) { config: GatewayConfig{}, gcc: &meshv2beta1.GatewayClassConfig{ Spec: meshv2beta1.GatewayClassConfigSpec{ + GatewayClassAnnotationsAndLabels: meshv2beta1.GatewayClassAnnotationsAndLabels{ + Labels: meshv2beta1.GatewayClassAnnotationsLabelsConfig{ + Set: map[string]string{ + "app": "consul", + "chart": "consul-helm", + "heritage": "Helm", + "release": "consul", + }, + }, + }, Deployment: meshv2beta1.GatewayClassDeploymentConfig{ Container: &meshv2beta1.GatewayClassContainerConfig{ PortModifier: 8000, @@ -52,12 +62,24 @@ func Test_meshGatewayBuilder_Service(t *testing.T) { }, want: &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ - Labels: defaultLabels, + Labels: map[string]string{ + labelManagedBy: "consul-k8s", + "app": "consul", + "chart": "consul-helm", + "heritage": "Helm", + "release": "consul", + }, Annotations: map[string]string{}, }, Spec: corev1.ServiceSpec{ - Selector: defaultLabels, - Type: corev1.ServiceTypeLoadBalancer, + Selector: map[string]string{ + labelManagedBy: "consul-k8s", + "app": "consul", + "chart": "consul-helm", + "heritage": "Helm", + "release": "consul", + }, + Type: corev1.ServiceTypeLoadBalancer, Ports: []corev1.ServicePort{ { Name: "wan",