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 553477c8 leverage app property handler for data index (#299)
553477c8 is described below
commit 553477c8f00d3afec816b5574d16ae735eba81a7
Author: Tommy Hughes IV <[email protected]>
AuthorDate: Mon Nov 13 12:44:17 2023 -0600
leverage app property handler for data index (#299)
Signed-off-by: Tommy Hughes <[email protected]>
---
controllers/platform/services.go | 18 ++++++------
controllers/profiles/common/app_properties.go | 33 +++++++++++++++++++++-
controllers/profiles/common/app_properties_test.go | 13 ++++++++-
3 files changed, 53 insertions(+), 11 deletions(-)
diff --git a/controllers/platform/services.go b/controllers/platform/services.go
index ca4484a0..9c1fba6e 100644
--- a/controllers/platform/services.go
+++ b/controllers/platform/services.go
@@ -105,10 +105,6 @@ func createDataIndexDeployment(ctx context.Context, client
client.Client, platfo
Name: "KOGITO_DATA_INDEX_QUARKUS_PROFILE",
Value: "http-events-support",
},
- {
- Name: "QUARKUS_HTTP_PORT",
- Value: "8080",
- },
{
Name: "QUARKUS_HTTP_CORS",
Value: "true",
@@ -171,7 +167,7 @@ func createDataIndexDeployment(ctx context.Context, client
client.Client, platfo
VolumeSource:
corev1.VolumeSource{
ConfigMap:
&corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
- Name:
common.GetDataIndexName(platform),
+ Name:
common.GetDataIndexCmName(platform),
},
},
},
@@ -331,12 +327,15 @@ func createDataIndexService(ctx context.Context, client
client.Client, platform
func createDataIndexConfigMap(ctx context.Context, client client.Client,
platform *operatorapi.SonataFlowPlatform) error {
configMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
- Name: common.GetDataIndexName(platform),
+ Name: common.GetDataIndexCmName(platform),
Namespace: platform.Namespace,
Labels: map[string]string{
workflowproj.LabelApp: platform.Name,
},
},
+ Data: map[string]string{
+ workflowproj.ApplicationPropertiesFileName:
common.NewServiceAppPropertyHandler(platform).Build(),
+ },
}
if err := controllerutil.SetControllerReference(platform, configMap,
client.Scheme()); err != nil {
return err
@@ -344,9 +343,10 @@ func createDataIndexConfigMap(ctx context.Context, client
client.Client, platfor
// Create or Update the service
if op, err := controllerutil.CreateOrUpdate(ctx, client, configMap,
func() error {
- configMap.Data = map[string]string{
- "application.properties":
"quarkus.smallrye-health.check.\"io.quarkus.kafka.client.health.KafkaHealthCheck\".enabled=false\n",
- }
+ configMap.Data[workflowproj.ApplicationPropertiesFileName] =
+ common.NewServiceAppPropertyHandler(platform).
+
WithUserProperties(configMap.Data[workflowproj.ApplicationPropertiesFileName]).
+ Build()
return nil
}); err != nil {
diff --git a/controllers/profiles/common/app_properties.go
b/controllers/profiles/common/app_properties.go
index 25c45198..5b2bbd12 100644
--- a/controllers/profiles/common/app_properties.go
+++ b/controllers/profiles/common/app_properties.go
@@ -30,6 +30,7 @@ const (
kogitoServiceUrlProperty = "kogito.service.url"
kogitoServiceUrlProtocol = "http"
dataIndexServiceUrlProperty =
"mp.messaging.outgoing.kogito-processinstances-events.url"
+ kafkaSmallRyeHealthProperty =
"quarkus.smallrye-health.check.\"io.quarkus.kafka.client.health.KafkaHealthCheck\".enabled"
dataIndexServiceUrlProtocol = "http"
DataIndexImageBase = "quay.io/kiegroup/kogito-data-index-"
@@ -59,6 +60,7 @@ type appPropertyHandler struct {
platform *operatorapi.SonataFlowPlatform
userProperties string
defaultMutableProperties string
+ isService bool
}
func (a *appPropertyHandler) WithUserProperties(properties string)
AppPropertyHandler {
@@ -76,7 +78,11 @@ func (a *appPropertyHandler) Build() string {
}
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",
a.userProperties)
+ if a.isService && a.platform != nil {
+ klog.V(log.D).InfoS("Can't load user's property",
"platform", a.platform.Name, "namespace", a.platform.Namespace, "properties",
a.userProperties)
+ } else {
+ 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()
}
// Disable expansions since it's not our responsibility
@@ -121,6 +127,16 @@ func (a *appPropertyHandler) withDataIndexServiceUrl()
AppPropertyHandler {
return a
}
+// withKafkaHealthCheckDisabled adds the property kafkaSmallRyeHealthProperty
to the application properties.
+// See Service Discovery
https://kubernetes.io/docs/concepts/services-networking/service/#dns
+func (a *appPropertyHandler) withKafkaHealthCheckDisabled() AppPropertyHandler
{
+ a.addDefaultMutableProperty(
+ kafkaSmallRyeHealthProperty,
+ "false",
+ )
+ return a
+}
+
func (a *appPropertyHandler) addDefaultMutableProperty(name string, value
string) AppPropertyHandler {
a.defaultMutableProperties = a.defaultMutableProperties +
fmt.Sprintf("%s=%s\n", name, value)
return a
@@ -143,6 +159,17 @@ func NewAppPropertyHandler(workflow
*operatorapi.SonataFlow, platform *operatora
return handler.withKogitoServiceUrl()
}
+// NewServicePropertyHandler creates the default service 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 NewServiceAppPropertyHandler(platform *operatorapi.SonataFlowPlatform)
AppPropertyHandler {
+ handler := &appPropertyHandler{
+ platform: platform,
+ isService: true,
+ }
+ return handler.withKafkaHealthCheckDisabled()
+}
+
// ImmutableApplicationProperties immutable default application properties
that can be used with any workflow based on Quarkus.
// Alias for NewAppPropertyHandler(workflow).Build()
func ImmutableApplicationProperties(workflow *operatorapi.SonataFlow, platform
*operatorapi.SonataFlowPlatform) string {
@@ -152,3 +179,7 @@ func ImmutableApplicationProperties(workflow
*operatorapi.SonataFlow, platform *
func GetDataIndexName(platform *operatorapi.SonataFlowPlatform) string {
return platform.Name + "-" + DataIndexName
}
+
+func GetDataIndexCmName(platform *operatorapi.SonataFlowPlatform) string {
+ return GetDataIndexName(platform) + "-props"
+}
diff --git a/controllers/profiles/common/app_properties_test.go
b/controllers/profiles/common/app_properties_test.go
index 251913e3..918c782f 100644
--- a/controllers/profiles/common/app_properties_test.go
+++ b/controllers/profiles/common/app_properties_test.go
@@ -89,7 +89,7 @@ func Test_appPropertyHandler_WithServicesWithUserOverrides(t
*testing.T) {
generatedProps, propsErr = properties.LoadString(props)
assert.NoError(t, propsErr)
assert.Equal(t, 9, len(generatedProps.Keys()))
- assert.Equal(t,
"http://"+platform.Name+"-data-index-service."+platform.Namespace+"/processes",
generatedProps.GetString(dataIndexServiceUrlProperty, ""))
+ assert.Equal(t,
"http://"+platform.Name+"-"+DataIndexName+"."+platform.Namespace+"/processes",
generatedProps.GetString(dataIndexServiceUrlProperty, ""))
// disabling data index bypasses config of outgoing events url
platform.Spec.Services.DataIndex.Enabled = nil
@@ -98,4 +98,15 @@ func Test_appPropertyHandler_WithServicesWithUserOverrides(t
*testing.T) {
assert.NoError(t, propsErr)
assert.Equal(t, 8, len(generatedProps.Keys()))
assert.Equal(t, "",
generatedProps.GetString(dataIndexServiceUrlProperty, ""))
+
+ // check that service app properties are being properly set
+ props =
NewServiceAppPropertyHandler(platform).WithUserProperties(userProperties).Build()
+ generatedProps, propsErr = properties.LoadString(props)
+ assert.NoError(t, propsErr)
+ assert.Equal(t, 9, len(generatedProps.Keys()))
+ assert.Equal(t, "false",
generatedProps.GetString(kafkaSmallRyeHealthProperty, ""))
+ assert.Equal(t, "value1", generatedProps.GetString("property1", ""))
+ assert.Equal(t, "value2", generatedProps.GetString("property2", ""))
+ //quarkus.http.port remains with the default value since it's immutable.
+ assert.Equal(t, "8080", generatedProps.GetString("quarkus.http.port",
""))
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]