diff --git a/controllers/profiles/common/object_creators.go b/controllers/profiles/common/object_creators.go index 8b72a2343..94a0d21da 100644 --- a/controllers/profiles/common/object_creators.go +++ b/controllers/profiles/common/object_creators.go @@ -23,6 +23,8 @@ import ( "fmt" "strings" + "github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles" + "github.com/apache/incubator-kie-kogito-serverless-operator/controllers/workflowdef" servingv1 "knative.dev/serving/pkg/apis/serving/v1" @@ -200,12 +202,14 @@ func defaultContainer(workflow *operatorapi.SonataFlow, plf *operatorapi.SonataF if err := mergo.Merge(defaultFlowContainer, workflow.Spec.PodTemplate.Container.ToContainer(), mergo.WithOverride); err != nil { return nil, err } - var pper *operatorapi.PlatformPersistenceOptionsSpec - if plf != nil && plf.Spec.Persistence != nil { - pper = plf.Spec.Persistence - } - if p := persistence.RetrieveConfiguration(workflow.Spec.Persistence, pper, workflow.Name); p != nil { - defaultFlowContainer = persistence.ConfigurePersistence(defaultFlowContainer, p, workflow.Name, workflow.Namespace) + if !profiles.IsDevProfile(workflow) { + var pper *operatorapi.PlatformPersistenceOptionsSpec + if plf != nil && plf.Spec.Persistence != nil { + pper = plf.Spec.Persistence + } + if p := persistence.RetrieveConfiguration(workflow.Spec.Persistence, pper, workflow.Name); p != nil { + defaultFlowContainer = persistence.ConfigurePersistence(defaultFlowContainer, p, workflow.Name, workflow.Namespace) + } } // immutable defaultFlowContainer.Name = operatorapi.DefaultContainerName diff --git a/controllers/profiles/common/object_creators_test.go b/controllers/profiles/common/object_creators_test.go index 074547e82..d0733d97e 100644 --- a/controllers/profiles/common/object_creators_test.go +++ b/controllers/profiles/common/object_creators_test.go @@ -23,6 +23,9 @@ import ( "context" "testing" + "github.com/apache/incubator-kie-kogito-serverless-operator/api/metadata" + "k8s.io/apimachinery/pkg/util/intstr" + sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1" "github.com/magiconair/properties" @@ -609,3 +612,181 @@ func TestMergePodSpec_WithServicedPostgreSQL_In_Platform_But_Workflow_CR_Not_Req assert.Equal(t, int32(8080), flowContainer.Ports[0].ContainerPort) assert.Nil(t, flowContainer.Env) } + +func TestDefaultContainer_WithPlatformPersistenceWorkflowWithDefaultProfile(t *testing.T) { + workflow := test.GetBaseSonataFlow(t.Name()) + doTestDefaultContainer_WithPlatformPersistence(t, workflow, true) +} + +func TestDefaultContainer_WithPlatformPersistenceWorkflowWithPreviewProfile(t *testing.T) { + workflow := test.GetBaseSonataFlow(t.Name()) + workflowproj.SetWorkflowProfile(workflow, metadata.PreviewProfile) + doTestDefaultContainer_WithPlatformPersistence(t, workflow, true) +} + +func TestDefaultContainer_WithPlatformPersistenceWorkflowWithGitOpsProfile(t *testing.T) { + workflow := test.GetBaseSonataFlow(t.Name()) + workflowproj.SetWorkflowProfile(workflow, metadata.GitOpsProfile) + doTestDefaultContainer_WithPlatformPersistence(t, workflow, true) +} + +func TestDefaultContainer_WithPlatformPersistenceWorkflowWithDevProfile(t *testing.T) { + workflow := test.GetBaseSonataFlow(t.Name()) + workflowproj.SetWorkflowProfile(workflow, metadata.DevProfile) + doTestDefaultContainer_WithPlatformPersistence(t, workflow, false) +} + +func doTestDefaultContainer_WithPlatformPersistence(t *testing.T, workflow *v1alpha08.SonataFlow, checkPersistence bool) { + platform := &v1alpha08.SonataFlowPlatform{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "default", + }, + Spec: v1alpha08.SonataFlowPlatformSpec{ + Persistence: &v1alpha08.PlatformPersistenceOptionsSpec{ + PostgreSQL: &v1alpha08.PlatformPersistencePostgreSQL{ + SecretRef: v1alpha08.PostgreSQLSecretOptions{ + Name: "foo_secret", + UserKey: "username", + PasswordKey: "password", + }, + ServiceRef: &v1alpha08.SQLServiceOptions{ + Name: "service_name", + Namespace: "service_namespace", + Port: &postgreSQLPort, + DatabaseName: "foo", + }, + }, + }, + }, + } + + container, err := defaultContainer(workflow, platform) + assert.Nil(t, err) + assert.NotNil(t, container) + assert.Equal(t, "workflow", container.Name) + + //verify default container port. + assert.Equal(t, 1, len(container.Ports)) + assert.Equal(t, "h2c", container.Ports[0].Name) + assert.Equal(t, int32(0), container.Ports[0].HostPort) + assert.Equal(t, int32(8080), container.Ports[0].ContainerPort) + assert.Equal(t, corev1.Protocol("TCP"), container.Ports[0].Protocol) + assert.Equal(t, "", container.Ports[0].HostIP) + + //verify default container health checks + assert.Equal(t, &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + Exec: nil, + HTTPGet: &corev1.HTTPGetAction{ + Path: "/q/health/live", + Port: intstr.IntOrString{ + Type: 0, + IntVal: 8080, + StrVal: "", + }, + Host: "", + Scheme: "", + HTTPHeaders: nil, + }, + TCPSocket: nil, + GRPC: nil, + }, + InitialDelaySeconds: 0, + TimeoutSeconds: 3, + PeriodSeconds: 15, + SuccessThreshold: 0, + FailureThreshold: 0, + TerminationGracePeriodSeconds: nil, + }, container.LivenessProbe) + + assert.Equal(t, &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + Exec: nil, + HTTPGet: &corev1.HTTPGetAction{ + Path: "/q/health/ready", + Port: intstr.IntOrString{ + Type: 0, + IntVal: 8080, + StrVal: "", + }, + Host: "", + Scheme: "", + HTTPHeaders: nil, + }, + TCPSocket: nil, + GRPC: nil, + }, + InitialDelaySeconds: 0, + TimeoutSeconds: 3, + PeriodSeconds: 15, + SuccessThreshold: 0, + FailureThreshold: 0, + TerminationGracePeriodSeconds: nil, + }, container.ReadinessProbe) + + assert.Equal(t, &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + Exec: nil, + HTTPGet: &corev1.HTTPGetAction{ + Path: "/q/health/started", + Port: intstr.IntOrString{ + Type: 0, + IntVal: 8080, + StrVal: "", + }, + Host: "", + Scheme: "", + HTTPHeaders: nil, + }, + TCPSocket: nil, + GRPC: nil, + }, + InitialDelaySeconds: 10, + TimeoutSeconds: 3, + PeriodSeconds: 15, + SuccessThreshold: 0, + FailureThreshold: 5, + TerminationGracePeriodSeconds: nil, + }, container.StartupProbe) + + //verify the persistence configuration is present if requested. + if checkPersistence { + expectedEnvVars := []corev1.EnvVar{ + { + Name: "QUARKUS_DATASOURCE_USERNAME", + Value: "", + ValueFrom: &corev1.EnvVarSource{ + SecretKeyRef: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{Name: "foo_secret"}, Key: "username", + }, + }, + }, + { + Name: "QUARKUS_DATASOURCE_PASSWORD", + Value: "", + ValueFrom: &corev1.EnvVarSource{ + SecretKeyRef: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{Name: "foo_secret"}, Key: "password", + }, + }, + }, + { + Name: "QUARKUS_DATASOURCE_DB_KIND", + Value: "postgresql", + }, + { + Name: "QUARKUS_DATASOURCE_JDBC_URL", + Value: "jdbc:postgresql://service_name.service_namespace:5432/foo?currentSchema=greeting", + }, + { + Name: "KOGITO_PERSISTENCE_TYPE", + Value: "jdbc", + }, + } + assert.Equal(t, expectedEnvVars, container.Env) + } else { + //no persistence + assert.Nil(t, container.Env) + } +} diff --git a/images/tools/sonataflow-db-migrator/pom.xml b/images/tools/sonataflow-db-migrator/pom.xml index 2afc373d7..575b439df 100644 --- a/images/tools/sonataflow-db-migrator/pom.xml +++ b/images/tools/sonataflow-db-migrator/pom.xml @@ -1,4 +1,24 @@ + 4.0.0 diff --git a/images/tools/sonataflow-db-migrator/src/test/java/org/kie/kogito/postgresql/migrator/DBConnectionCheckerTest.java b/images/tools/sonataflow-db-migrator/src/test/java/org/kie/kogito/postgresql/migrator/DBConnectionCheckerTest.java index 0b5032a34..3ac0be5ec 100644 --- a/images/tools/sonataflow-db-migrator/src/test/java/org/kie/kogito/postgresql/migrator/DBConnectionCheckerTest.java +++ b/images/tools/sonataflow-db-migrator/src/test/java/org/kie/kogito/postgresql/migrator/DBConnectionCheckerTest.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.kie.kogito.postgresql.migrator; import io.quarkus.test.Mock; diff --git a/images/tools/sonataflow-db-migrator/src/test/java/org/kie/kogito/postgresql/migrator/DBMigratorTest.java b/images/tools/sonataflow-db-migrator/src/test/java/org/kie/kogito/postgresql/migrator/DBMigratorTest.java index f88f960af..09df4c964 100644 --- a/images/tools/sonataflow-db-migrator/src/test/java/org/kie/kogito/postgresql/migrator/DBMigratorTest.java +++ b/images/tools/sonataflow-db-migrator/src/test/java/org/kie/kogito/postgresql/migrator/DBMigratorTest.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.kie.kogito.postgresql.migrator; import io.quarkus.test.Mock; diff --git a/images/tools/sonataflow-db-migrator/src/test/java/org/kie/kogito/postgresql/migrator/MigrationServiceTest.java b/images/tools/sonataflow-db-migrator/src/test/java/org/kie/kogito/postgresql/migrator/MigrationServiceTest.java index 71a81681b..8cf96f6d7 100644 --- a/images/tools/sonataflow-db-migrator/src/test/java/org/kie/kogito/postgresql/migrator/MigrationServiceTest.java +++ b/images/tools/sonataflow-db-migrator/src/test/java/org/kie/kogito/postgresql/migrator/MigrationServiceTest.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.kie.kogito.postgresql.migrator; import io.quarkus.test.Mock;