Skip to content

Commit

Permalink
Set selector and label specific to platform service (#341)
Browse files Browse the repository at this point in the history
Signed-off-by: Moti Asayag <[email protected]>
  • Loading branch information
masayag authored Jan 11, 2024
1 parent ca5a493 commit e631455
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
28 changes: 17 additions & 11 deletions controllers/platform/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
{
Expand All @@ -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{
Expand All @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions workflowproj/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down

0 comments on commit e631455

Please sign in to comment.