Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.101x-prod] kie-kogito-serverless-operator-520: Error when deploying a WF with the dev profile in a SPF that has persistence configured (#531) #71

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions controllers/profiles/common/object_creators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
181 changes: 181 additions & 0 deletions controllers/profiles/common/object_creators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}
20 changes: 20 additions & 0 deletions images/tools/sonataflow-db-migrator/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

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.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading