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

Sync main branch with Apache main branch #61

Merged
merged 5 commits into from
Jun 11, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ Dockerfile
/.vscode/
/target/

database/index.db
e2e-test-report.xml
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ docker-buildx: generate ## Build and push docker image for the manager for cross
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
- docker buildx create --name project-v3-builder
docker buildx use project-v3-builder
- docker buildx build --build-arg SOURCE_DATE_EPOCH=$(shell git log -1 --pretty=%ct) --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross
- docker buildx build --build-arg SOURCE_DATE_EPOCH=$(shell git log -1 --pretty=%ct) --push . --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross
- docker buildx rm project-v3-builder
rm Dockerfile.cross

Expand Down Expand Up @@ -297,12 +297,16 @@ ifneq ($(origin CATALOG_BASE_IMG), undefined)
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
endif

PLATFORM ?= linux/amd64

# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
.PHONY: catalog-build
catalog-build: opm ## Build a catalog image.
$(OPM) index add --container-tool $(BUILDER) --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
$(OPM) index add --container-tool $(BUILDER) --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) --generate -d ./index.Dockerfile
$(BUILDER) build --platform $(PLATFORM) -f ./index.Dockerfile -t $(CATALOG_IMG) .
rm ./index.Dockerfile

# Push the catalog image.
.PHONY: catalog-push
Expand Down
7 changes: 3 additions & 4 deletions controllers/platform/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (d DataIndexHandler) hasPostgreSQLConfigured() bool {

func (d DataIndexHandler) ConfigurePersistence(containerSpec *corev1.Container) *corev1.Container {
if d.hasPostgreSQLConfigured() {
p := persistence.RetrieveConfiguration(d.platform.Spec.Services.DataIndex.Persistence, d.platform.Spec.Persistence, d.GetServiceName())
p := persistence.RetrievePostgreSQLConfiguration(d.platform.Spec.Services.DataIndex.Persistence, d.platform.Spec.Persistence, d.GetServiceName())
c := containerSpec.DeepCopy()
c.Image = d.GetServiceImageName(constants.PersistenceTypePostgreSQL)
c.Env = append(c.Env, persistence.ConfigurePostgreSQLEnv(p.PostgreSQL, d.GetServiceName(), d.platform.Namespace)...)
Expand Down Expand Up @@ -397,11 +397,10 @@ func (j JobServiceHandler) hasPostgreSQLConfigured() bool {
}

func (j JobServiceHandler) ConfigurePersistence(containerSpec *corev1.Container) *corev1.Container {

if j.hasPostgreSQLConfigured() {
c := containerSpec.DeepCopy()
c.Image = j.GetServiceImageName(constants.PersistenceTypePostgreSQL)
p := persistence.RetrieveConfiguration(j.platform.Spec.Services.JobService.Persistence, j.platform.Spec.Persistence, j.GetServiceName())
p := persistence.RetrievePostgreSQLConfiguration(j.platform.Spec.Services.JobService.Persistence, j.platform.Spec.Persistence, j.GetServiceName())
c.Env = append(c.Env, persistence.ConfigurePostgreSQLEnv(p.PostgreSQL, j.GetServiceName(), j.platform.Namespace)...)
// Specific to Job Service
c.Env = append(c.Env, corev1.EnvVar{Name: "QUARKUS_FLYWAY_MIGRATE_AT_START", Value: "true"})
Expand All @@ -423,7 +422,7 @@ func (j JobServiceHandler) GenerateServiceProperties() (*properties.Properties,
props.Set(constants.JobServiceKafkaSmallRyeHealthProperty, "false")
// add data source reactive URL
if j.hasPostgreSQLConfigured() {
p := persistence.RetrieveConfiguration(j.platform.Spec.Services.JobService.Persistence, j.platform.Spec.Persistence, j.GetServiceName())
p := persistence.RetrievePostgreSQLConfiguration(j.platform.Spec.Services.JobService.Persistence, j.platform.Spec.Persistence, j.GetServiceName())
dataSourceReactiveURL, err := generateReactiveURL(p.PostgreSQL, j.GetServiceName(), j.platform.Namespace, constants.DefaultDatabaseName, constants.DefaultPostgreSQLPort)
if err != nil {
return nil, err
Expand Down
27 changes: 27 additions & 0 deletions controllers/profiles/common/persistence/persistence_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2024 Apache Software Foundation (ASF)
//
// Licensed 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 persistence

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestPersistence(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Persistence Suite")
}
13 changes: 13 additions & 0 deletions controllers/profiles/common/persistence/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ func RetrieveConfiguration(primary *v1alpha08.PersistenceOptionsSpec, platformPe
if platformPersistence == nil {
return nil
}
return buildPersistenceOptionsSpec(platformPersistence, schema)
}

// RetrievePostgreSQLConfiguration return the PersistenceOptionsSpec considering that postgresql is the database manager
// to look for. Gives priority to the primary configuration.
func RetrievePostgreSQLConfiguration(primary *v1alpha08.PersistenceOptionsSpec, platformPersistence *v1alpha08.PlatformPersistenceOptionsSpec, schema string) *v1alpha08.PersistenceOptionsSpec {
if primary != nil && primary.PostgreSQL != nil {
return primary
}
return buildPersistenceOptionsSpec(platformPersistence, schema)
}

func buildPersistenceOptionsSpec(platformPersistence *v1alpha08.PlatformPersistenceOptionsSpec, schema string) *v1alpha08.PersistenceOptionsSpec {
c := &v1alpha08.PersistenceOptionsSpec{}
if platformPersistence.PostgreSQL != nil {
c.PostgreSQL = &v1alpha08.PersistencePostgreSQL{
Expand Down
146 changes: 146 additions & 0 deletions controllers/profiles/common/persistence/postgresql_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// Copyright 2024 Apache Software Foundation (ASF)
//
// Licensed 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 persistence

import (
operatorapi "github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

const (
primaryPostgreSQLJdbc = "jdbc:postgresql://host:port/database?currentSchema=primary-database"

platformPostgreSQLJdbc = "jdbc:postgresql://host:port/database?currentSchema=platform-database"
schemaName = "my-schema"
)

var (
primaryPostgreSQLSecret = operatorapi.PostgreSQLSecretOptions{
Name: "primary-secret",
}
primaryPostreSQLService = operatorapi.PostgreSQLServiceOptions{
SQLServiceOptions: &operatorapi.SQLServiceOptions{Name: "primary-service"},
DatabaseSchema: "primary-schema",
}
plaformPostgreSQLSecret = operatorapi.PostgreSQLSecretOptions{
Name: "platform-secret",
}
platformPostreSQLService = operatorapi.SQLServiceOptions{
Name: "platform-service",
}
)

var _ = Describe("RetrievePostgreSQLConfiguration", func() {
DescribeTable("calculation",
func(primary *operatorapi.PersistenceOptionsSpec,
platformPersistence *operatorapi.PlatformPersistenceOptionsSpec,
schema string,
expectedConfig *operatorapi.PersistenceOptionsSpec) {
result := RetrievePostgreSQLConfiguration(primary, platformPersistence, schema)
Expect(expectedConfig).To(Equal(result))
},
Entry("primary is postgresql with JdbcUrl", buildPrimaryIsPostgreSQLWithJdbcUrl(),
buildPlatformIsPostgreSQLWithJdbcUrl(),
schemaName,
buildPrimaryIsPostgreSQLWithJdbcUrl()),
Entry("primary is postgresql ServiceRef", buildPrimaryIsPostgreSQLWithServiceRef(),
buildPlatformIsPostgreSQLWithJdbcUrl(),
schemaName,
buildPrimaryIsPostgreSQLWithServiceRef()),
Entry("primary is nil, platform with JdbcUrl",
nil,
buildPlatformIsPostgreSQLWithJdbcUrl(),
schemaName,
&operatorapi.PersistenceOptionsSpec{
PostgreSQL: &operatorapi.PersistencePostgreSQL{
SecretRef: plaformPostgreSQLSecret,
JdbcUrl: platformPostgreSQLJdbc,
},
}),
Entry("primary is empty, platform with JdbcUrl",
&operatorapi.PersistenceOptionsSpec{},
buildPlatformIsPostgreSQLWithJdbcUrl(),
schemaName,
&operatorapi.PersistenceOptionsSpec{
PostgreSQL: &operatorapi.PersistencePostgreSQL{
SecretRef: plaformPostgreSQLSecret,
JdbcUrl: platformPostgreSQLJdbc,
},
}),
Entry("primary is nil, platform with ServiceRef",
nil,
buildPlatformIsPostgreSQLWithServiceRef(),
schemaName,
&operatorapi.PersistenceOptionsSpec{
PostgreSQL: &operatorapi.PersistencePostgreSQL{
ServiceRef: &operatorapi.PostgreSQLServiceOptions{
SQLServiceOptions: &platformPostreSQLService,
DatabaseSchema: schemaName,
},
SecretRef: plaformPostgreSQLSecret,
},
}),
Entry("primary is empty, platform with ServiceRef",
&operatorapi.PersistenceOptionsSpec{},
buildPlatformIsPostgreSQLWithServiceRef(),
schemaName,
&operatorapi.PersistenceOptionsSpec{
PostgreSQL: &operatorapi.PersistencePostgreSQL{
ServiceRef: &operatorapi.PostgreSQLServiceOptions{
SQLServiceOptions: &platformPostreSQLService,
DatabaseSchema: schemaName,
},
SecretRef: plaformPostgreSQLSecret,
},
}),
)
})

func buildPrimaryIsPostgreSQLWithJdbcUrl() *operatorapi.PersistenceOptionsSpec {
return &operatorapi.PersistenceOptionsSpec{
PostgreSQL: &operatorapi.PersistencePostgreSQL{
JdbcUrl: primaryPostgreSQLJdbc,
SecretRef: primaryPostgreSQLSecret,
},
}
}

func buildPrimaryIsPostgreSQLWithServiceRef() *operatorapi.PersistenceOptionsSpec {
return &operatorapi.PersistenceOptionsSpec{
PostgreSQL: &operatorapi.PersistencePostgreSQL{
ServiceRef: &primaryPostreSQLService,
SecretRef: primaryPostgreSQLSecret,
},
}
}

func buildPlatformIsPostgreSQLWithJdbcUrl() *operatorapi.PlatformPersistenceOptionsSpec {
return &operatorapi.PlatformPersistenceOptionsSpec{
PostgreSQL: &operatorapi.PlatformPersistencePostgreSQL{
JdbcUrl: platformPostgreSQLJdbc,
SecretRef: plaformPostgreSQLSecret,
},
}
}

func buildPlatformIsPostgreSQLWithServiceRef() *operatorapi.PlatformPersistenceOptionsSpec {
return &operatorapi.PlatformPersistenceOptionsSpec{
PostgreSQL: &operatorapi.PlatformPersistencePostgreSQL{
ServiceRef: &platformPostreSQLService,
SecretRef: plaformPostgreSQLSecret,
},
}
}
21 changes: 16 additions & 5 deletions images/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
# Requirements for cekit 4.11.0 build
# see: https://pip.pypa.io/en/stable/reference/requirements-file-format/
docker-squash
odcs
docker

requests<2.32.0
cekit==4.11.0
behave==1.2.6
lxml==5.2.1
docker==7.0.0
docker-squash==1.2.0
python-docker
elementpath==4.4.0
pyyaml==6.0.1
ruamel.yaml==0.18.6
python-dateutil==2.9.0.post0
Jinja2==3.1.4
pykwalify==1.8.0
colorlog==6.8.2
click==8.1.7
odcs
behave
lxml
krb5
cekit == 4.11.0
6 changes: 6 additions & 0 deletions workflowproj/workflowproj.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ type WorkflowProjectHandler interface {
SaveAsKubernetesManifests(path string) error
// AsObjects returns a reference to the WorkflowProject holding the Kubernetes Manifests based on your files.
AsObjects() (*WorkflowProject, error)
// Image overrides the default image in the generated SonataFlow manifest
Image(image string) WorkflowProjectHandler
}

// WorkflowProject is a structure to hold every Kubernetes object generated by the given WorkflowProjectHandler handler.
Expand Down Expand Up @@ -301,6 +303,10 @@ func (w *workflowProjectHandler) addResourceConfigMapToProject(cm *corev1.Config
}
return nil
}
func (w *workflowProjectHandler) Image(image string) WorkflowProjectHandler {
w.project.Workflow.Spec.PodTemplate.Container.Image = image
return w
}

// IsDevProfile detects if the workflow is using the Dev profile or not
func IsDevProfile(workflow *operatorapi.SonataFlow) bool {
Expand Down
8 changes: 8 additions & 0 deletions workflowproj/workflowproj_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ func Test_Handler_WorkflowService_SaveAs(t *testing.T) {
})
}

func TestWorkflowProjectHandler_Image(t *testing.T) {
handler := New("default").WithWorkflow(getWorkflowService())
proj, err := handler.AsObjects()
handler.Image("quay.io/kiegroup/kogito-service:latest")
assert.NoError(t, err)
assert.Equal(t, "quay.io/kiegroup/kogito-service:latest", proj.Workflow.Spec.PodTemplate.Container.Image)
}

func getWorkflowMinimalInvalid() io.Reader {
return mustGetFile("testdata/workflows/workflow-minimal-invalid.sw.json")
}
Expand Down
Loading