Skip to content

Commit

Permalink
Set recommended kubernetes labels on services and workflows
Browse files Browse the repository at this point in the history
Motivation:
There's a need to select efficiently workflows and their respective
services. Having the common kubernetes labels allow a single selector:

   podSelector:
     matchExpressions:
       - { key: app.kubernetes.io/component, operator: In, values:
         ["data-index-service", "jobs-service", "serverless-workflow"] }

Modification:
Make the v1.Deployment for services and the deployment or knative
services to contain at common labels

Result:
A workflow deployment or knative serving labels:
    app.kubernetes.io/name: ${workflow name}
    app.kubernetes.io/component: serverless-workflow
    app.kubernetes.io/part-of: ${platform url set by status}
    app.kubernetes.io/managed-by: sonataflow-operator

Data index or Jobs services Deployment.v1 labels:

    app.kubernetes.io/name: ${service name}
    app.kubernetes.io/component: data-index-service|jobs-service
    app.kubernetes.io/part-of: ${platform name}
    app.kubernetes.io/managed-by: sonataflow-operator

Reference: https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/#labels

Signed-off-by: Roy Golan <[email protected]>
  • Loading branch information
rgolangh committed Jun 18, 2024
1 parent e9fce09 commit 7a62159
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha08/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions api/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion container-builder/api/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions controllers/platform/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,12 @@ func createOrUpdateService(ctx context.Context, client client.Client, platform *

func getLabels(platform *operatorapi.SonataFlowPlatform, psh services.PlatformServiceHandler) (map[string]string, map[string]string) {
lbl := map[string]string{
workflowproj.LabelApp: platform.Name,
workflowproj.LabelService: psh.GetServiceName(),
workflowproj.LabelApp: platform.Name,
workflowproj.LabelService: psh.GetServiceName(),
workflowproj.LabelK8SName: psh.GetContainerName(),
workflowproj.LabelK8SComponent: psh.GetServiceName(),
workflowproj.LabelK8SPartOF: platform.Name,
workflowproj.LabelK8SManagedBy: "sonataflow-operator",
}
selectorLbl := map[string]string{
workflowproj.LabelService: psh.GetServiceName(),
Expand Down
2 changes: 2 additions & 0 deletions controllers/profiles/common/object_creators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import (
"github.com/apache/incubator-kie-kogito-serverless-operator/workflowproj"
)

const platformName = "test-platform"

func Test_ensureWorkflowPropertiesConfigMapMutator(t *testing.T) {
workflow := test.GetBaseSonataFlowWithDevProfile(t.Name())
platform := test.GetBasePlatform()
Expand Down
20 changes: 16 additions & 4 deletions workflowproj/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ const (
// LabelService key to use among object selectors
LabelService = metadata.Domain + "/service"
// LabelWorkflow specialized label managed by the controller
LabelWorkflow = metadata.Domain + "/workflow-app"
LabelWorkflow = metadata.Domain + "/workflow-app"
LabelK8SName = "app.kubernetes.io/name"
LabelK8SComponent = "app.kubernetes.io/component"
LabelK8SPartOF = "app.kubernetes.io/part-of"
LabelK8SManagedBy = "app.kubernetes.io/managed-by"
)

// SetTypeToObject sets the Kind and ApiVersion to a given object since the default constructor won't do it.
Expand Down Expand Up @@ -84,10 +88,18 @@ func GetManagedPropertiesFileName(workflow *operatorapi.SonataFlow) string {

// GetDefaultLabels gets the default labels based on the given workflow.
func GetDefaultLabels(workflow *operatorapi.SonataFlow) map[string]string {
return map[string]string{
LabelApp: workflow.Name,
LabelWorkflow: workflow.Name,
labels := map[string]string{
LabelApp: workflow.Name,
LabelWorkflow: workflow.Name,
LabelK8SName: workflow.Name,
LabelK8SComponent: "serverless-workflow",
LabelK8SManagedBy: "sonataflow-operator",
}
if workflow.Status.Platform != nil {
labels[LabelK8SPartOF] = workflow.Status.Platform.Name
}
return labels

}

// SetMergedLabels adds the merged labels to the given object.
Expand Down

0 comments on commit 7a62159

Please sign in to comment.