Skip to content

Commit

Permalink
kogito-serverless-operator: generate stable names for workflow resources
Browse files Browse the repository at this point in the history
Motivation:
Workflowproj generates a configmap per schema or subflow or specs in a
separate file for each one, however the name is not deterministic. In
one iteration you can get the specs in
01-configmap-FLOWNAME-resources.yaml and in the next iteration the same
content will go in 02-configmap-FLOWNAME-resources.yaml.

While the flow spec file will be updated accordingly and stay correct,
the behaviour generates lots of changes when tracking changes in git.

Modification:
This fix will make the generation behaviour deterministic by sorting the
resources iteration prior to generating them and also add the related
schemas|specs/subflows to the generated file name:

Result:
old schema configmap manifest:
0x-configmap-FLOWNAME-resources.yaml

new schema configmap manifest:
01-configmap-FLOWNAME-resources-schemas.yaml

old specs config map manifest:
0x-configmap-FLOWNAME-resources.yaml

new specs configmap manifest:
02-configmap-FLOWNAME-resources-specs.yaml

old subflows config map manifest:
0x-configmap-FLOWNAME-resources.yaml

new subflows configmap manifest:
01-configmap-FLOWNAME-resources-subflows.yaml

Also the name of the config map itself will get the name related to the
content like: '03-FLOWNAME-resources-schemas'

Signed-off-by: Roy Golan <[email protected]>
  • Loading branch information
rgolangh committed May 27, 2024
1 parent 326a19b commit a4fa9cf
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions packages/sonataflow-operator/workflowproj/workflowproj.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ package workflowproj
import (
"context"
"fmt"
"io"
"strings"

"github.com/pkg/errors"
"github.com/serverlessworkflow/sdk-go/v2/model"
"github.com/serverlessworkflow/sdk-go/v2/parser"
"io"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/kubernetes/scheme"
"sort"
"strings"

"github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/metadata"
operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
Expand Down Expand Up @@ -264,13 +264,25 @@ func (w *workflowProjectHandler) parseRawResources() error {
}

resourceCount := 1
for path, resources := range w.rawResources {
paths := []string{}
for k := range w.rawResources {
paths = append(paths, k)
}
// Sort the paths to generate a deterministric list of files.
// Without sorting Golang map iteration on the strings is inconsistent because
// iteration order is not specified, so each time we could get 01-configmap-NAME-resources.yaml
// with schemas, and the next time with subflows, or other way round.
sort.Strings(paths)
for _, path := range paths {
// For better usability also convenience we add the 'path' from which the config map is taken
// so the config map file will have a meaningful name like
// 01-configmap-NAME-resources-specs.yaml or -subflow.yaml or -schemas.yaml
cm := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Namespace: w.namespace, Name: fmt.Sprintf("%02d-%s-resources", resourceCount, w.name)},
ObjectMeta: metav1.ObjectMeta{Namespace: w.namespace, Name: fmt.Sprintf("%02d-%s-resources-%s", resourceCount, w.name, path)},
Data: map[string]string{},
}

for _, r := range resources {
for _, r := range w.rawResources[path] {
contents, err := io.ReadAll(r.contents)
if err != nil {
return err
Expand Down

0 comments on commit a4fa9cf

Please sign in to comment.