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 #26

Merged
merged 16 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
68 changes: 53 additions & 15 deletions .ci/jenkins/Jenkinsfile.e2e.cluster
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

helper = null

minikubeClusterPlatform = 'minikube'
KIND_VERSION = "v0.20.0"
kindClusterPlatform = 'kind'
openshiftClusterPlatform = 'openshift'

kindLogsFolder = "/tmp/kind-logs"

pipeline {
agent {
label "${env.AGENT_LABEL ?: "rhel8"} && podman && !built-in"
Expand Down Expand Up @@ -54,6 +57,31 @@ pipeline {
}
}
}
stage('Load image into Kind') {
when {
expression {
return getClusterName() == kindClusterPlatform
}
}
steps {
script {
kind.loadImage(getTestImage())
}
}
}
stage('Deploy the operator') {
when {
expression {
return getClusterName() == kindClusterPlatform
}
}
steps {
script {
sh "make deploy IMG=${getTestImage()}"
sh "kubectl wait pod -A -l control-plane=sonataflow-operator --for condition=Ready --timeout=120s"
}
}
}
stage('Prepare for e2e tests') {
when {
expression {
Expand Down Expand Up @@ -90,16 +118,25 @@ pipeline {
make test-e2e
"""
} catch (err) {
kind.exportLogs(kindLogsFolder)
sh 'make undeploy'
deleteKindCluster()
throw err
}
sh 'kubectl get pods -A'
deleteKindCluster()
}
}
}
}
}
post {
always {
script {
archiveArtifacts(artifacts: "**${kindLogsFolder}/**/*.*,**/e2e-test-report.xml")
junit '**/e2e-test-report.xml'
}
}
cleanup {
script {
clean()
Expand All @@ -111,7 +148,6 @@ pipeline {
void clean() {
helper.cleanGoPath()
util.cleanNode(containerEngine)
cleanupCluster()
}

String getTestImage() {
Expand All @@ -128,24 +164,25 @@ String getOperatorVersion() {

void setupCluster() {
switch (getClusterName()) {
case minikubeClusterPlatform:
setupMinikube()
case kindClusterPlatform:
echo 'Creating kind cluster'
createKindCluster()
break
case openshiftClusterPlatform:
echo 'Setting up Openshift'
setupOpenshift()
break
default:
error "Unknown cluster name ${getClusterName()}. Cannot prepare for it ..."
}
}

void setupMinikube() {
// Start minikube
minikube.minikubeMemory = '12g'
minikube.start()
void createKindCluster() {
sh(script: "make KIND_VERSION=${KIND_VERSION} create-cluster", returnStdout: true)
}

minikube.waitForMinikubeStarted()
minikube.waitForMinikubeRegistry()
void deleteKindCluster() {
sh(script: "make delete-cluster", returnStdout: true)
}

void setupOpenshift() {
Expand All @@ -155,8 +192,9 @@ void setupOpenshift() {

void cleanupCluster() {
switch (getClusterName()) {
case minikubeClusterPlatform:
minikube.stop()
case kindClusterPlatform:
echo 'Deleting kind cluster'
deleteKindCluster()
break
case openshiftClusterPlatform:
echo 'Nothing to cleanup on openshift. All good !'
Expand All @@ -168,8 +206,8 @@ void cleanupCluster() {

void executeInCluster(Closure executeClosure) {
switch (getClusterName()) {
case minikubeClusterPlatform:
echo "Execute in minikube"
case kindClusterPlatform:
echo "Execute in kind"
executeClosure()
break
case openshiftClusterPlatform:
Expand All @@ -185,7 +223,7 @@ void executeInCluster(Closure executeClosure) {

void getPlatformCRFilePath() {
switch (getClusterName()) {
case minikubeClusterPlatform:
case kindClusterPlatform:
return 'test/testdata/sonataflow.org_v1alpha08_sonataflowplatform_withCache_minikube.yaml'
case openshiftClusterPlatform:
return 'test/testdata/sonataflow.org_v1alpha08_sonataflowplatform_openshift.yaml'
Expand Down
4 changes: 2 additions & 2 deletions .ci/jenkins/scripts/helper.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openshift = null
container = null
properties = null
minikube = null
kind = null

defaultImageParamsPrefix = 'IMAGE'
baseImageParamsPrefix = 'BASE_IMAGE'
Expand All @@ -19,7 +19,7 @@ void initPipeline() {
container.containerEngineTlsOptions = env.CONTAINER_ENGINE_TLS_OPTIONS ?: ''
container.containerOpenshift = openshift

minikube = load '.ci/jenkins/scripts/minikube.groovy'
kind = load '.ci/jenkins/scripts/kind.groovy'
}

void updateDisplayName() {
Expand Down
32 changes: 32 additions & 0 deletions .ci/jenkins/scripts/kind.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.
*/

void exportLogs(String destination) {
println "Exporting kind logs to ${destination}"
def exportKindLogs = sh(returnStatus: true, script: """
mkdir -p .${destination}
kind export logs --loglevel=debug .${destination}
""")
}

void loadImage(String imageName) {
sh "kind load docker-image ${imageName}"
}

return this
3 changes: 2 additions & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ jobs:
# Packages for testing with Podman
- name: Install package
run: |
sudo apt-get -y install \
sudo apt-get update &&\
sudo apt-get -y install --no-install-recommends \
btrfs-progs \
libgpgme-dev \
libbtrfs-dev \
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ jobs:
steps:
- name: Install package
run: |
sudo apt-get -y install \
sudo apt-get update &&\
sudo apt-get -y install --no-install-recommends \
btrfs-progs \
libgpgme-dev \
libbtrfs-dev \
Expand Down Expand Up @@ -76,6 +77,12 @@ jobs:
run: |
make test-e2e

- name: Retrieve cluster events and list pods
if: failure()
run: |
kubectl get events
kubectl get pod -A

- name: Export kind logs
if: always()
run: |
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# To re-generate a bundle for another specific version without changing the standard setup, you can:
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
VERSION ?= 2.0.0-snapshot
VERSION ?= 999.0.0-snapshot
REDUCED_VERSION ?= latest

# CHANNELS define the bundle channels used in the bundle.
Expand Down Expand Up @@ -347,7 +347,7 @@ generate-all: generate generate-deploy bundle addheaders vet fmt

.PHONY: test-e2e # You will need to have a Minikube/Kind cluster up in running to run this target, and run container-builder before the test
test-e2e: install-operator-sdk
go test ./test/e2e/* -v -ginkgo.v -timeout 30m
go test ./test/e2e/* -v -ginkgo.v -ginkgo.no-color -ginkgo.junit-report=./e2e-test-report.xml -timeout 60m

.PHONY: before-pr
before-pr: test generate-all
Expand Down
102 changes: 102 additions & 0 deletions api/v1alpha08/sonataflow_persistence_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// 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 v1alpha08

// PlatformPersistenceOptionsSpec configures the DataBase in the platform spec. This specification can
// be used by workflows and platform services when they don't provide one of their own.
// +optional
// +kubebuilder:validation:MaxProperties=1
type PlatformPersistenceOptionsSpec struct {
// Connect configured services to a postgresql database.
// +optional
PostgreSQL *PlatformPersistencePostgreSQL `json:"postgresql,omitempty"`
}

// PlatformPersistencePostgreSQL configure postgresql connection in a platform to be shared
// by platform services and workflows when required.
// +kubebuilder:validation:MinProperties=2
// +kubebuilder:validation:MaxProperties=2
type PlatformPersistencePostgreSQL struct {
// Secret reference to the database user credentials
SecretRef PostgreSQLSecretOptions `json:"secretRef"`
// Service reference to postgresql datasource. Mutually exclusive to jdbcUrl.
// +optional
ServiceRef *SQLServiceOptions `json:"serviceRef,omitempty"`
// PostgreSql JDBC URL. Mutually exclusive to serviceRef.
// e.g. "jdbc:postgresql://host:port/database?currentSchema=data-index-service"
// +optional
JdbcUrl string `json:"jdbcUrl,omitempty"`
}

// PersistenceOptionsSpec configures the DataBase support for both platform services and workflows. For services, it allows
// configuring a generic database connectivity if the service does not come with its own configured. In case of workflows,
// the operator will add the necessary JDBC properties to in the workflow's application.properties so that it can communicate
// with the persistence service based on the spec provided here.
// +optional
// +kubebuilder:validation:MaxProperties=1
type PersistenceOptionsSpec struct {
// Connect configured services to a postgresql database.
// +optional
PostgreSQL *PersistencePostgreSQL `json:"postgresql,omitempty"`
}

// PersistencePostgreSQL configure postgresql connection for service(s).
// +kubebuilder:validation:MinProperties=2
// +kubebuilder:validation:MaxProperties=2
type PersistencePostgreSQL struct {
// Secret reference to the database user credentials
SecretRef PostgreSQLSecretOptions `json:"secretRef"`
// Service reference to postgresql datasource. Mutually exclusive to jdbcUrl.
// +optional
ServiceRef *PostgreSQLServiceOptions `json:"serviceRef,omitempty"`
// PostgreSql JDBC URL. Mutually exclusive to serviceRef.
// e.g. "jdbc:postgresql://host:port/database?currentSchema=data-index-service"
// +optional
JdbcUrl string `json:"jdbcUrl,omitempty"`
}

// PostgreSQLSecretOptions use credential secret for postgresql connection.
type PostgreSQLSecretOptions struct {
// Name of the postgresql credentials secret.
Name string `json:"name"`
// Defaults to POSTGRESQL_USER
// +optional
UserKey string `json:"userKey,omitempty"`
// Defaults to POSTGRESQL_PASSWORD
// +optional
PasswordKey string `json:"passwordKey,omitempty"`
}

type SQLServiceOptions struct {
// Name of the postgresql k8s service.
Name string `json:"name"`
// Namespace of the postgresql k8s service. Defaults to the SonataFlowPlatform's local namespace.
// +optional
Namespace string `json:"namespace,omitempty"`
// Port to use when connecting to the postgresql k8s service. Defaults to 5432.
// +optional
Port *int `json:"port,omitempty"`
// Name of postgresql database to be used. Defaults to "sonataflow"
// +optional
DatabaseName string `json:"databaseName,omitempty"`
}

// PostgreSQLServiceOptions use k8s service to configure postgresql jdbc url.
type PostgreSQLServiceOptions struct {
*SQLServiceOptions `json:",inline"`
// Schema of postgresql database to be used. Defaults to "data-index-service"
// +optional
DatabaseSchema string `json:"databaseSchema,omitempty"`
}
8 changes: 5 additions & 3 deletions api/v1alpha08/sonataflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,11 @@ type SonataFlowSpec struct {
// PodTemplate describes the deployment details of this SonataFlow instance.
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="podTemplate"
PodTemplate PodTemplateSpec `json:"podTemplate,omitempty"`
// Persists service to a datasource of choice. Ephemeral by default.
// +optional
Persistence *PersistenceOptions `json:"persistence,omitempty"`
// Persistence defines the database persistence configuration for the workflow
Persistence *PersistenceOptionsSpec `json:"persistence,omitempty"`
// Sink describes the sinkBinding details of this SonataFlow instance.
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="sink"
Sink *duckv1.Destination `json:"sink,omitempty"`
}

// SonataFlowStatus defines the observed state of SonataFlow
Expand Down
15 changes: 15 additions & 0 deletions api/v1alpha08/sonataflowclusterplatform_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,23 @@ const (

// SonataFlowClusterPlatformSpec defines the desired state of SonataFlowClusterPlatform
type SonataFlowClusterPlatformSpec struct {
// PlatformRef defines which existing SonataFlowPlatform's supporting services should be used cluster-wide.
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="PlatformRef"
PlatformRef SonataFlowPlatformRef `json:"platformRef"`
// Capabilities defines which platform capabilities should be applied cluster-wide. If nil, defaults to `capabilities.workflows["services"]`
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Capabilities"
Capabilities *SonataFlowClusterPlatformCapSpec `json:"capabilities,omitempty"`
}

// SonataFlowClusterPlatformCapSpec defines which platform capabilities should be applied cluster-wide
type SonataFlowClusterPlatformCapSpec struct {
// Workflows defines which platform capabilities should be applied to workflows cluster-wide.
Workflows []WorkFlowCapability `json:"workflows,omitempty"`
}

// +kubebuilder:validation:Enum=services
type WorkFlowCapability string

// SonataFlowPlatformRef defines which existing SonataFlowPlatform's supporting services should be used cluster-wide.
type SonataFlowPlatformRef struct {
// Name of the SonataFlowPlatform
Expand Down Expand Up @@ -78,6 +92,7 @@ func (in *SonataFlowClusterPlatformStatus) IsDuplicated() bool {
// +kubebuilder:printcolumn:name="Platform_NS",type=string,JSONPath=`.spec.platformRef.namespace`
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=='Succeed')].status`
// +kubebuilder:printcolumn:name="Reason",type=string,JSONPath=`.status.conditions[?(@.type=='Succeed')].reason`
// +operator-sdk:csv:customresourcedefinitions:resources={{SonataFlowPlatform,sonataflow.org/v1alpha08,"A SonataFlow Platform"}}
type SonataFlowClusterPlatform struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
Loading
Loading