This is an automated email from the ASF dual-hosted git repository.

ricardozanini pushed a commit to branch main
in repository 
https://gitbox.apache.org/repos/asf/incubator-kie-kogito-serverless-operator.git


The following commit(s) were added to refs/heads/main by this push:
     new 75a33581 Generate stable names for workflow resources (#473)
75a33581 is described below

commit 75a335817942eae8e1e89a608a542a145ced80ea
Author: Roy Golan <[email protected]>
AuthorDate: Mon Jun 17 20:54:42 2024 +0300

    Generate stable names for workflow resources (#473)
---
 workflowproj/workflowproj.go      | 19 ++++++++++++++++---
 workflowproj/workflowproj_test.go | 10 +++++-----
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/workflowproj/workflowproj.go b/workflowproj/workflowproj.go
index 44fe83a6..8a7a2772 100644
--- a/workflowproj/workflowproj.go
+++ b/workflowproj/workflowproj.go
@@ -23,6 +23,7 @@ import (
        "context"
        "fmt"
        "io"
+       "sort"
        "strings"
 
        "github.com/pkg/errors"
@@ -266,13 +267,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
diff --git a/workflowproj/workflowproj_test.go 
b/workflowproj/workflowproj_test.go
index 6e9c876b..2570802f 100644
--- a/workflowproj/workflowproj_test.go
+++ b/workflowproj/workflowproj_test.go
@@ -85,7 +85,7 @@ func Test_Handler_WorkflowMinimalAndPropsAndSpec(t 
*testing.T) {
        assert.Equal(t, "hello-props", proj.Properties.Name)
        assert.NotEmpty(t, proj.Properties.Data)
        assert.Equal(t, 1, len(proj.Resources))
-       assert.Equal(t, "01-hello-resources", proj.Resources[0].Name)
+       assert.Equal(t, "01-hello-resources-specs", proj.Resources[0].Name)
        assert.Equal(t, 
proj.Workflow.Spec.Resources.ConfigMaps[0].ConfigMap.Name, 
proj.Resources[0].Name)
 
 }
@@ -114,8 +114,8 @@ func 
Test_Handler_WorkflowMinimalAndPropsAndSpecAndGeneric(t *testing.T) {
        assert.Equal(t, "hello-props", proj.Properties.Name)
        assert.NotEmpty(t, proj.Properties.Data)
        assert.Equal(t, 2, len(proj.Resources))
-       assert.Equal(t, "01-hello-resources", proj.Resources[0].Name)
-       assert.Equal(t, "02-hello-resources", proj.Resources[1].Name)
+       assert.Equal(t, "01-hello-resources-files", proj.Resources[0].Name)
+       assert.Equal(t, "02-hello-resources-specs", proj.Resources[1].Name)
        assert.Equal(t, 
proj.Workflow.Spec.Resources.ConfigMaps[0].ConfigMap.Name, 
proj.Resources[0].Name)
        assert.Equal(t, 
proj.Workflow.Spec.Resources.ConfigMaps[1].ConfigMap.Name, 
proj.Resources[1].Name)
        data, err := getResourceDataWithFileName(proj.Resources, 
"myopenapi.json")
@@ -158,8 +158,8 @@ func Test_Handler_WorklflowServiceAndPropsAndSpec_SaveAs(t 
*testing.T) {
 
        expectedFiles := []string{
                "01-configmap_service-props.yaml",
-               "02-configmap_01-service-resources.yaml",
-               "03-configmap_02-service-resources.yaml",
+               "02-configmap_01-service-resources-files.yaml",
+               "03-configmap_02-service-resources-specs.yaml",
                "04-sonataflow_service.yaml",
        }
        expectedKinds := []schema.GroupVersionKind{


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to