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 6c70c4cb KOGITO-9856: [Operator] Operator calculated
kogito.service.url don't have protocol (#270)
6c70c4cb is described below
commit 6c70c4cbfa805aad96e491e7f2e0699c2214b0ed
Author: Walter Medvedeo <[email protected]>
AuthorDate: Tue Oct 3 18:50:54 2023 +0200
KOGITO-9856: [Operator] Operator calculated kogito.service.url don't have
protocol (#270)
- Adds the missing protocol.
- Introduces the ability to have set of properties that the operator
generates by default,
but the user has the chance to override with their own values if
needed.
---
controllers/profiles/common/app_properties.go | 64 ++++++++++++++--------
controllers/profiles/common/app_properties_test.go | 42 +++++++++++++-
go.work.sum | 1 +
3 files changed, 83 insertions(+), 24 deletions(-)
diff --git a/controllers/profiles/common/app_properties.go
b/controllers/profiles/common/app_properties.go
index 54586936..31181b1b 100644
--- a/controllers/profiles/common/app_properties.go
+++ b/controllers/profiles/common/app_properties.go
@@ -27,6 +27,7 @@ import (
const (
ConfigMapWorkflowPropsVolumeName = "workflow-properties"
kogitoServiceUrlProperty = "kogito.service.url"
+ kogitoServiceUrlProtocol = "http"
)
var immutableApplicationProperties = "quarkus.http.port=" +
defaultHTTPWorkflowPortIntStr.String() + "\n" +
@@ -45,52 +46,69 @@ type AppPropertyHandler interface {
}
type appPropertyHandler struct {
- workflow *operatorapi.SonataFlow
- properties string
+ workflow *operatorapi.SonataFlow
+ userProperties string
+ defaultMutableProperties string
}
-func (a *appPropertyHandler) WithUserProperties(userProperties string)
AppPropertyHandler {
- if len(userProperties) == 0 {
- return a
+func (a *appPropertyHandler) WithUserProperties(properties string)
AppPropertyHandler {
+ a.userProperties = properties
+ return a
+}
+
+func (a *appPropertyHandler) Build() string {
+ var props *properties.Properties
+ var propErr error = nil
+ if len(a.userProperties) == 0 {
+ props = properties.NewProperties()
+ } else {
+ props, propErr = properties.LoadString(a.userProperties)
}
- props, propErr := properties.LoadString(userProperties)
if propErr != nil {
// can't load user's properties, ignore it
- klog.V(log.D).InfoS("Can't load user's property", "workflow",
a.workflow.Name, "namespace", a.workflow.Namespace, "properties",
userProperties)
- return a
+ klog.V(log.D).InfoS("Can't load user's property", "workflow",
a.workflow.Name, "namespace", a.workflow.Namespace, "properties",
a.userProperties)
+ props = properties.NewProperties()
}
- defaultProps := properties.MustLoadString(a.properties)
- // we overwrite with the defaults
- props.Merge(defaultProps)
// 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
- a.properties = props.String()
- return a
-}
-
-func (a *appPropertyHandler) Build() string {
- return a.properties
+ defaultMutableProps :=
properties.MustLoadString(a.defaultMutableProperties)
+ for _, k := range defaultMutableProps.Keys() {
+ if _, ok := props.Get(k); ok {
+ defaultMutableProps.Delete(k)
+ }
+ }
+ // overwrite with the default mutable properties provided by the
operator that are not set by the user.
+ props.Merge(defaultMutableProps)
+ defaultImmutableProps :=
properties.MustLoadString(immutableApplicationProperties)
+ // finally overwrite with the defaults immutable properties.
+ props.Merge(defaultImmutableProps)
+ return props.String()
}
// withKogitoServiceUrl adds the property kogitoServiceUrlProperty to the
application properties.
// See Service Discovery
https://kubernetes.io/docs/concepts/services-networking/service/#dns
func (a *appPropertyHandler) withKogitoServiceUrl() AppPropertyHandler {
+ var kogitoServiceUrl string
if len(a.workflow.Namespace) > 0 {
- a.properties = a.properties +
- fmt.Sprintf("%s=%s.%s\n", kogitoServiceUrlProperty,
a.workflow.Name, a.workflow.Namespace)
+ kogitoServiceUrl = fmt.Sprintf("%s://%s.%s",
kogitoServiceUrlProtocol, a.workflow.Name, a.workflow.Namespace)
} else {
- a.properties = a.properties +
- fmt.Sprintf("%s=%s\n", kogitoServiceUrlProperty,
a.workflow.Name)
+ kogitoServiceUrl = fmt.Sprintf("%s://%s",
kogitoServiceUrlProtocol, a.workflow.Name)
}
+ return a.addDefaultMutableProperty(kogitoServiceUrlProperty,
kogitoServiceUrl)
+}
+
+func (a *appPropertyHandler) addDefaultMutableProperty(name string, value
string) AppPropertyHandler {
+ a.defaultMutableProperties = a.defaultMutableProperties +
fmt.Sprintf("%s=%s\n", name, value)
return a
}
// NewAppPropertyHandler creates the default workflow configurations property
handler
+// The set of properties is initialized with the operator provided immutable
properties.
+// The set of defaultMutableProperties is initialized with the operator
provided properties that the user might override.
func NewAppPropertyHandler(workflow *operatorapi.SonataFlow)
AppPropertyHandler {
handler := &appPropertyHandler{
- workflow: workflow,
- properties: immutableApplicationProperties,
+ workflow: workflow,
}
return handler.withKogitoServiceUrl()
}
diff --git a/controllers/profiles/common/app_properties_test.go
b/controllers/profiles/common/app_properties_test.go
index 64291f5f..c2551eea 100644
--- a/controllers/profiles/common/app_properties_test.go
+++ b/controllers/profiles/common/app_properties_test.go
@@ -17,6 +17,8 @@ package common
import (
"testing"
+ "github.com/magiconair/properties"
+
"github.com/stretchr/testify/assert"
"github.com/kiegroup/kogito-serverless-operator/test"
@@ -26,5 +28,43 @@ func Test_appPropertyHandler_WithKogitoServiceUrl(t
*testing.T) {
workflow := test.GetBaseSonataFlow("default")
props := ImmutableApplicationProperties(workflow)
assert.Contains(t, props, kogitoServiceUrlProperty)
- assert.Contains(t, props, workflow.Name+"."+workflow.Namespace)
+ assert.Contains(t, props,
"http://"+workflow.Name+"."+workflow.Namespace)
+}
+
+func Test_appPropertyHandler_WithUserPropertiesWithNoUserOverrides(t
*testing.T) {
+ //just add some user provided properties, no overrides.
+ userProperties := "property1=value1\nproperty2=value2"
+ workflow := test.GetBaseSonataFlow("default")
+ props :=
NewAppPropertyHandler(workflow).WithUserProperties(userProperties).Build()
+ generatedProps, propsErr := properties.LoadString(props)
+ assert.NoError(t, propsErr)
+ assert.Equal(t, 8, len(generatedProps.Keys()))
+ assert.Equal(t, "value1", generatedProps.GetString("property1", ""))
+ assert.Equal(t, "value2", generatedProps.GetString("property2", ""))
+ assert.Equal(t, "http://greeting.default",
generatedProps.GetString("kogito.service.url", ""))
+ assert.Equal(t, "8080", generatedProps.GetString("quarkus.http.port",
""))
+ assert.Equal(t, "0.0.0.0",
generatedProps.GetString("quarkus.http.host", ""))
+ assert.Equal(t, "false",
generatedProps.GetString("org.kie.kogito.addons.knative.eventing.health-enabled",
""))
+ assert.Equal(t, "false",
generatedProps.GetString("quarkus.devservices.enabled", ""))
+ assert.Equal(t, "false",
generatedProps.GetString("quarkus.kogito.devservices.enabled", ""))
+}
+
+func Test_appPropertyHandler_WithUserPropertiesWithUserOverrides(t *testing.T)
{
+ //try to override kogito.service.url and quarkus.http.port
+ userProperties :=
"property1=value1\nproperty2=value2\nquarkus.http.port=9090\nkogito.service.url=http://myUrl.override.com\nquarkus.http.port=9090"
+ workflow := test.GetBaseSonataFlow("default")
+ props :=
NewAppPropertyHandler(workflow).WithUserProperties(userProperties).Build()
+ generatedProps, propsErr := properties.LoadString(props)
+ assert.NoError(t, propsErr)
+ assert.Equal(t, 8, len(generatedProps.Keys()))
+ assert.Equal(t, "value1", generatedProps.GetString("property1", ""))
+ assert.Equal(t, "value2", generatedProps.GetString("property2", ""))
+ //kogito.service.url takes the user provided value since it's a default
mutable property.
+ assert.Equal(t, "http://myUrl.override.com",
generatedProps.GetString("kogito.service.url", ""))
+ //quarkus.http.port remains with the default value since it's immutable.
+ assert.Equal(t, "8080", generatedProps.GetString("quarkus.http.port",
""))
+ assert.Equal(t, "0.0.0.0",
generatedProps.GetString("quarkus.http.host", ""))
+ assert.Equal(t, "false",
generatedProps.GetString("org.kie.kogito.addons.knative.eventing.health-enabled",
""))
+ assert.Equal(t, "false",
generatedProps.GetString("quarkus.devservices.enabled", ""))
+ assert.Equal(t, "false",
generatedProps.GetString("quarkus.kogito.devservices.enabled", ""))
}
diff --git a/go.work.sum b/go.work.sum
index 0d0dd56b..3fb28a45 100644
--- a/go.work.sum
+++ b/go.work.sum
@@ -495,6 +495,7 @@ golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod
h1:3jZMyOhIsHpP37uCMk
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod
h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod
h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod
h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
+golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3
h1:XQyxROzUlZH+WIQwySDgnISgOivlhjIEwaQaJEJrrN0=
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod
h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod
h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de
h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]