From bedb0e816347a6e56a0a94d70489cc19f29c747f Mon Sep 17 00:00:00 2001 From: Ricardo Zanini <1538000+ricardozanini@users.noreply.github.com> Date: Fri, 8 Sep 2023 16:36:32 -0300 Subject: [PATCH] Fix property expansion problem (#248) * Fix property expansion problem Signed-off-by: Ricardo Zanini * :rewind: adding back old test Signed-off-by: Ricardo Zanini --------- Signed-off-by: Ricardo Zanini --- controllers/profiles/object_creators.go | 3 +++ controllers/profiles/object_creators_test.go | 23 +++++++++++++++++-- .../04_v1_configmap_properties.yaml | 2 +- test/testdata/order-processing/README.md | 3 +++ 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 test/testdata/order-processing/README.md diff --git a/controllers/profiles/object_creators.go b/controllers/profiles/object_creators.go index 127012be4..f9c355655 100644 --- a/controllers/profiles/object_creators.go +++ b/controllers/profiles/object_creators.go @@ -256,6 +256,9 @@ func ensureWorkflowPropertiesConfigMapMutator(workflow *operatorapi.SonataFlow, originalProps := properties.MustLoadString(original.(*corev1.ConfigMap).Data[workflowproj.ApplicationPropertiesFileName]) // we overwrite with the defaults props.Merge(originalProps) + // Disable expansions since it's not our responsibility + // Property expansion means resolving ${} within the properties and environment context. Quarkus will do that in runtime. + props.DisableExpansion = true cm.Data[workflowproj.ApplicationPropertiesFileName] = props.String() } diff --git a/controllers/profiles/object_creators_test.go b/controllers/profiles/object_creators_test.go index 1e5b4bb0b..a2819153e 100644 --- a/controllers/profiles/object_creators_test.go +++ b/controllers/profiles/object_creators_test.go @@ -20,10 +20,10 @@ import ( "github.com/magiconair/properties" "github.com/stretchr/testify/assert" v1 "k8s.io/api/core/v1" - - "github.com/kiegroup/kogito-serverless-operator/workflowproj" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/kiegroup/kogito-serverless-operator/test" + "github.com/kiegroup/kogito-serverless-operator/workflowproj" ) func Test_ensureWorkflowPropertiesConfigMapMutator(t *testing.T) { @@ -54,3 +54,22 @@ func Test_ensureWorkflowPropertiesConfigMapMutator(t *testing.T) { assert.Equal(t, "0.0.0.0", props.GetString("quarkus.http.host", "")) assert.Equal(t, "1", props.GetString("my.new.prop", "")) } + +func Test_ensureWorkflowPropertiesConfigMapMutator_DollarReplacement(t *testing.T) { + workflow := test.GetBaseSonataFlowWithDevProfile(t.Name()) + existingCM := &v1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: workflow.Name, + Namespace: workflow.Namespace, + UID: "0000-0001-0002-0003", + }, + Data: map[string]string{ + workflowproj.ApplicationPropertiesFileName: "mp.messaging.outgoing.kogito_outgoing_stream.url=${kubernetes:services.v1/event-listener}", + }, + } + mutateVisitorFn := ensureWorkflowPropertiesConfigMapMutator(workflow, defaultProdApplicationProperties) + + err := mutateVisitorFn(existingCM)() + assert.NoError(t, err) + assert.Contains(t, existingCM.Data[workflowproj.ApplicationPropertiesFileName], "${kubernetes:services.v1/event-listener}") +} diff --git a/test/testdata/order-processing/04_v1_configmap_properties.yaml b/test/testdata/order-processing/04_v1_configmap_properties.yaml index 58592dcc9..ce77601f0 100644 --- a/test/testdata/order-processing/04_v1_configmap_properties.yaml +++ b/test/testdata/order-processing/04_v1_configmap_properties.yaml @@ -19,4 +19,4 @@ metadata: data: application.properties: | quarkus.log.level = INFO - mp.messaging.outgoing.kogito_outgoing_stream.url = kubernetes:services.v1/event-listener + mp.messaging.outgoing.kogito_outgoing_stream.url = ${kubernetes:services.v1/event-listener} diff --git a/test/testdata/order-processing/README.md b/test/testdata/order-processing/README.md new file mode 100644 index 000000000..450761ded --- /dev/null +++ b/test/testdata/order-processing/README.md @@ -0,0 +1,3 @@ +# Order Processing Example + +See: https://github.com/kiegroup/kogito-examples/tree/main/serverless-workflow-examples/serverless-workflow-order-processing