From 8c9d7e0f258836b2375b02f68fcf7c0071da11ad Mon Sep 17 00:00:00 2001 From: Moti Asayag Date: Thu, 11 Jan 2024 17:01:50 +0200 Subject: [PATCH] Set selector and label specific to platform service (#341) Signed-off-by: Moti Asayag --- controllers/platform/k8s.go | 28 +++++++++++++++++----------- workflowproj/operator.go | 2 ++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/controllers/platform/k8s.go b/controllers/platform/k8s.go index c21b200fe..d66155bf2 100644 --- a/controllers/platform/k8s.go +++ b/controllers/platform/k8s.go @@ -135,12 +135,10 @@ func createDeployment(ctx context.Context, client client.Client, platform *opera dataDeployContainer.Name = ps.GetContainerName() replicas := ps.GetReplicaCount() - lbl := map[string]string{ - workflowproj.LabelApp: platform.Name, - } + lbl, selectorLbl := getLabels(platform, ps) dataDeploySpec := appsv1.DeploymentSpec{ Selector: &metav1.LabelSelector{ - MatchLabels: lbl, + MatchLabels: selectorLbl, }, Replicas: &replicas, Template: corev1.PodTemplateSpec{ @@ -195,9 +193,7 @@ func createDeployment(ctx context.Context, client client.Client, platform *opera } func createService(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, ps services.Platform) error { - lbl := map[string]string{ - workflowproj.LabelApp: platform.Name, - } + lbl, selectorLbl := getLabels(platform, ps) dataSvcSpec := corev1.ServiceSpec{ Ports: []corev1.ServicePort{ { @@ -207,7 +203,7 @@ func createService(ctx context.Context, client client.Client, platform *operator TargetPort: common.DefaultHTTPWorkflowPortIntStr, }, }, - Selector: lbl, + Selector: selectorLbl, } dataSvc := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -233,18 +229,28 @@ func createService(ctx context.Context, client client.Client, platform *operator return nil } +func getLabels(platform *operatorapi.SonataFlowPlatform, ps services.Platform) (map[string]string, map[string]string) { + lbl := map[string]string{ + workflowproj.LabelApp: platform.Name, + workflowproj.LabelService: ps.GetServiceName(), + } + selectorLbl := map[string]string{ + workflowproj.LabelService: ps.GetServiceName(), + } + return lbl, selectorLbl +} + func createConfigMap(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, ps services.Platform) error { handler, err := services.NewServiceAppPropertyHandler(ps) if err != nil { return err } + lbl, _ := getLabels(platform, ps) configMap := &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: ps.GetServiceCmName(), Namespace: platform.Namespace, - Labels: map[string]string{ - workflowproj.LabelApp: platform.Name, - }, + Labels: lbl, }, Data: map[string]string{ workflowproj.ApplicationPropertiesFileName: handler.Build(), diff --git a/workflowproj/operator.go b/workflowproj/operator.go index 3509d7c30..46ff7ba34 100644 --- a/workflowproj/operator.go +++ b/workflowproj/operator.go @@ -34,6 +34,8 @@ const ( ApplicationPropertiesFileName = "application.properties" // LabelApp key to use among object selectors, "app" is used among k8s applications to group objects in some UI consoles LabelApp = "app" + // LabelService key to use among object selectors + LabelService = "sonataflow.org/service" // LabelWorkflow specialized label managed by the controller LabelWorkflow = metadata.Domain + "/workflow-app" )