Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.

Commit f01d5fd

Browse files
committed
kie-kogito-serverless-operator-536: Adjust cors configuration for the dev profile deployments, and JS and DI deployments
1 parent 645b09f commit f01d5fd

File tree

8 files changed

+215
-159
lines changed

8 files changed

+215
-159
lines changed

config/manager/manager.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ spec:
5656
resources:
5757
limits:
5858
cpu: 500m
59-
memory: 128Mi
59+
memory: 500Mi
6060
requests:
61-
cpu: 10m
62-
memory: 64Mi
61+
cpu: 100m
62+
memory: 200Mi
6363
serviceAccountName: controller-manager
6464
terminationGracePeriodSeconds: 10

internal/controller/discovery/discovery_openshift_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ import (
3333
)
3434

3535
func Test_QueryOpenShiftRoute(t *testing.T) {
36-
doTestQueryOpenShiftRoute(t, false, "http://openshiftroutehost1:80")
36+
doTestQueryOpenShiftRoute(t, false, "http://openshiftroutehost1")
3737
}
3838

3939
func Test_QueryOpenShiftRouteWithTLS(t *testing.T) {
40-
doTestQueryOpenShiftRoute(t, true, "https://openshiftroutehost1:443")
40+
doTestQueryOpenShiftRoute(t, true, "https://openshiftroutehost1")
4141
}
4242

4343
func doTestQueryOpenShiftRoute(t *testing.T, tls bool, expectedUri string) {

internal/controller/discovery/openshift_catalog.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,11 @@ func (c openShiftServiceCatalog) resolveOpenShiftRouteQuery(ctx context.Context,
107107
return "", err
108108
} else {
109109
scheme := httpProtocol
110-
port := defaultHttpPort
111110
if route.Spec.TLS != nil {
112111
scheme = httpsProtocol
113-
port = defaultHttpsPort
114112
}
115-
return buildURI(scheme, route.Spec.Host, port), nil
113+
// the OpenShift routes are only opened at the http/https standard ports.
114+
return fmt.Sprintf("%s://%s", scheme, route.Spec.Host), nil
116115
}
117116
}
118117

internal/controller/platform/services/services.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,6 @@ func (d *DataIndexHandler) GetEnvironmentVariables() []corev1.EnvVar {
197197
Name: "KOGITO_DATA_INDEX_QUARKUS_PROFILE",
198198
Value: "http-events-support",
199199
},
200-
{
201-
Name: "QUARKUS_HTTP_CORS",
202-
Value: "true",
203-
},
204-
{
205-
Name: "QUARKUS_HTTP_CORS_ORIGINS",
206-
Value: "/.*/",
207-
},
208200
}
209201
}
210202

@@ -373,16 +365,7 @@ func (j *JobServiceHandler) GetLocalServiceBaseUrl() string {
373365
}
374366

375367
func (j *JobServiceHandler) GetEnvironmentVariables() []corev1.EnvVar {
376-
return []corev1.EnvVar{
377-
{
378-
Name: "QUARKUS_HTTP_CORS",
379-
Value: "true",
380-
},
381-
{
382-
Name: "QUARKUS_HTTP_CORS_ORIGINS",
383-
Value: "/.*/",
384-
},
385-
}
368+
return []corev1.EnvVar{}
386369
}
387370

388371
func (j *JobServiceHandler) GetPodResourceRequirements() corev1.ResourceRequirements {

internal/controller/profiles/common/constants/workflows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ const (
2323
KnativeHealthEnabled = "org.kie.kogito.addons.knative.eventing.health-enabled"
2424
KnativeInjectedEnvVar = "${K_SINK}"
2525
TriggerFinalizer = "trigger-deletion"
26+
QuarkusDevUICorsEnabled = "quarkus.dev-ui.cors.enabled"
27+
QuarkusHttpCors = "quarkus.http.cors"
28+
QuarkusHttpCorsOrigins = "quarkus.http.cors.origins"
2629
)

internal/controller/profiles/common/properties/managed.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"context"
2424
"fmt"
2525

26+
"github.com/apache/incubator-kie-kogito-serverless-operator/internal/controller/profiles"
27+
2628
"github.com/apache/incubator-kie-kogito-serverless-operator/internal/controller/profiles/common/persistence"
2729

2830
"github.com/apache/incubator-kie-kogito-serverless-operator/utils"
@@ -96,6 +98,10 @@ func (a *managedPropertyHandler) Build() string {
9698
// produce the MicroProfileConfigServiceCatalog properties for the service discovery property values if any.
9799
discoveryProps.Merge(generateDiscoveryProperties(a.ctx, a.catalog, userProps, a.workflow))
98100
}
101+
if profiles.IsDevProfile(a.workflow) && a.requireServiceDiscovery() {
102+
// produce dev profile properties that must be calculated at service discovery time.
103+
setDevProfileDiscoveryProperties(a.ctx, a.catalog, a.defaultManagedProperties, a.workflow)
104+
}
99105
userProps = utils.NewApplicationPropertiesBuilder().
100106
WithInitialProperties(discoveryProps).
101107
WithImmutableProperties(properties.MustLoadString(immutableApplicationProperties)).
@@ -148,6 +154,9 @@ func NewManagedPropertyHandler(workflow *operatorapi.SonataFlow, platform *opera
148154
platform: platform,
149155
}
150156
props := properties.NewProperties()
157+
if profiles.IsDevProfile(workflow) {
158+
setDevProfileProperties(props)
159+
}
151160
props.Set(constants.KogitoUserTasksEventsEnabled, "false")
152161
if platform != nil {
153162
p, err := resolvePlatformWorkflowProperties(platform)
@@ -183,6 +192,30 @@ func NewManagedPropertyHandler(workflow *operatorapi.SonataFlow, platform *opera
183192
return handler.withKogitoServiceUrl(), nil
184193
}
185194

195+
func setDevProfileProperties(props *properties.Properties) {
196+
props.Set(constants.QuarkusDevUICorsEnabled, "false")
197+
}
198+
199+
func setDevProfileDiscoveryProperties(ctx context.Context, catalog discovery.ServiceCatalog, props *properties.Properties, workflow *operatorapi.SonataFlow) {
200+
if utils.IsOpenShift() {
201+
// in OpenShift deployments the route is created before the workflow, at this point it can be queried safely.
202+
routeUrl, err := catalog.Query(ctx, *discovery.NewResourceUriBuilder(discovery.OpenshiftScheme).
203+
Kind("routes").
204+
Group("route.openshift.io").
205+
Version("v1").
206+
Namespace(workflow.Namespace).
207+
Name(workflow.Name).
208+
Build(),
209+
discovery.KubernetesDNSAddress)
210+
if err != nil {
211+
klog.V(log.E).ErrorS(err, "An error was produced while getting workflow route url. ", "workflow", workflow.Name)
212+
} else {
213+
props.Set(constants.QuarkusHttpCors, "true")
214+
props.Set(constants.QuarkusHttpCorsOrigins, routeUrl)
215+
}
216+
}
217+
}
218+
186219
// ApplicationManagedProperties immutable default application properties that can be used with any workflow based on Quarkus.
187220
// Alias for NewManagedPropertyHandler(workflow).Build()
188221
func ApplicationManagedProperties(workflow *operatorapi.SonataFlow, platform *operatorapi.SonataFlowPlatform) (string, error) {

0 commit comments

Comments
 (0)