Skip to content

Commit

Permalink
Updates based on latest changes and revert some unwanted changes that…
Browse files Browse the repository at this point in the history
… came in by accident

Signed-off-by: Jordi Gil <[email protected]>
  • Loading branch information
jordigilh committed Feb 5, 2024
1 parent 071796c commit f61ee98
Show file tree
Hide file tree
Showing 21 changed files with 105 additions and 81 deletions.
12 changes: 12 additions & 0 deletions api/v1alpha08/sonataflow_persistence_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@

package v1alpha08

// 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
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha08/sonataflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ type SonataFlowSpec struct {
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="podTemplate"
PodTemplate PodTemplateSpec `json:"podTemplate,omitempty"`
// Persistence defines the database persistence configuration for the workflow
Persistence *PersistencePlatformSpec `json:"persistence,omitempty"`
Persistence *PersistenceOptionsSpec `json:"persistence,omitempty"`
}

// SonataFlowStatus defines the observed state of SonataFlow
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha08/sonataflowplatform_services_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type ServiceSpec struct {
Enabled *bool `json:"enabled,omitempty"`
// Persists service to a datasource of choice. Ephemeral by default.
// +optional
Persistence *PersistencePlatformSpec `json:"persistence,omitempty"`
Persistence *PersistenceOptionsSpec `json:"persistence,omitempty"`
// PodTemplate describes the deployment details of this platform service instance.
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="podTemplate"
PodTemplate PodTemplateSpec `json:"podTemplate,omitempty"`
Expand Down
15 changes: 2 additions & 13 deletions api/v1alpha08/sonataflowplatform_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,12 @@ type SonataFlowPlatformSpec struct {
// Only workflows without the `sonataflow.org/profile: dev` annotation will be configured to use these service(s).
// Setting this will override the use of any cluster-scoped services that might be defined via `SonataFlowClusterPlatform`.
// +optional
Services ServicesPlatformSpec `json:"services,omitempty"`
Services *ServicesPlatformSpec `json:"services,omitempty"`
// Persistence defines the platform persistence configuration. When this field is set,
// the configuration is used as the persistence for platform services and sonataflow instances
// that don't provide one of their own.
// +optional
Persistence *PersistencePlatformSpec `json:"persistence,omitempty"`
}

// PersistencePlatformSpec 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
type PersistencePlatformSpec struct {
// Connect configured services to a postgresql database.
// +optional
PostgreSQL *PersistencePostgreSQL `json:"postgresql,omitempty"`
Persistence *PersistenceOptionsSpec `json:"persistence,omitempty"`
}

// PlatformCluster is the kind of orchestration cluster the platform is installed into
Expand Down
20 changes: 12 additions & 8 deletions api/v1alpha08/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions bundle/manifests/sonataflow.org_sonataflowplatforms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ spec:
When this field is set, the configuration is used as the persistence
for platform services and sonataflow instances that don't provide
one of their own.
maxProperties: 1
properties:
postgresql:
description: Connect configured services to a postgresql database.
Expand Down Expand Up @@ -498,6 +499,7 @@ spec:
persistence:
description: Persists service to a datasource of choice. Ephemeral
by default.
maxProperties: 1
properties:
postgresql:
description: Connect configured services to a postgresql
Expand Down Expand Up @@ -8369,6 +8371,7 @@ spec:
persistence:
description: Persists service to a datasource of choice. Ephemeral
by default.
maxProperties: 1
properties:
postgresql:
description: Connect configured services to a postgresql
Expand Down
1 change: 1 addition & 0 deletions bundle/manifests/sonataflow.org_sonataflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,7 @@ spec:
persistence:
description: Persistence defines the database persistence configuration
for the workflow
maxProperties: 1
properties:
postgresql:
description: Connect configured services to a postgresql database.
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/sonataflow.org_sonataflowplatforms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ spec:
When this field is set, the configuration is used as the persistence
for platform services and sonataflow instances that don't provide
one of their own.
maxProperties: 1
properties:
postgresql:
description: Connect configured services to a postgresql database.
Expand Down Expand Up @@ -499,6 +500,7 @@ spec:
persistence:
description: Persists service to a datasource of choice. Ephemeral
by default.
maxProperties: 1
properties:
postgresql:
description: Connect configured services to a postgresql
Expand Down Expand Up @@ -8370,6 +8372,7 @@ spec:
persistence:
description: Persists service to a datasource of choice. Ephemeral
by default.
maxProperties: 1
properties:
postgresql:
description: Connect configured services to a postgresql
Expand Down
1 change: 1 addition & 0 deletions config/crd/bases/sonataflow.org_sonataflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2106,6 +2106,7 @@ spec:
persistence:
description: Persistence defines the database persistence configuration
for the workflow
maxProperties: 1
properties:
postgresql:
description: Connect configured services to a postgresql database.
Expand Down
16 changes: 9 additions & 7 deletions controllers/platform/platformutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ func setPlatformDefaults(p *operatorapi.SonataFlowPlatform, verbose bool) error
}

// When dataIndex object set, default to enabled if bool not set
var enable = true
if p.Spec.Services.DataIndex != nil && p.Spec.Services.DataIndex.Enabled == nil {
p.Spec.Services.DataIndex.Enabled = &enable
}
// When the JobService field has a value, default to enabled if the `Enabled` field's value is nil
if p.Spec.Services.JobService != nil && p.Spec.Services.JobService.Enabled == nil {
p.Spec.Services.JobService.Enabled = &enable
if p.Spec.Services != nil {
var enable = true
if p.Spec.Services.DataIndex != nil && p.Spec.Services.DataIndex.Enabled == nil {
p.Spec.Services.DataIndex.Enabled = &enable
}
// When the JobService field has a value, default to enabled if the `Enabled` field's value is nil
if p.Spec.Services.JobService != nil && p.Spec.Services.JobService.Enabled == nil {
p.Spec.Services.JobService.Enabled = &enable
}
}
setStatusAdditionalInfo(p)

Expand Down
22 changes: 20 additions & 2 deletions controllers/platform/services/properties_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ func generatePlatform(opts ...plfmOptionFn) *operatorapi.SonataFlowPlatform {

func setJobServiceEnabledValue(v *bool) plfmOptionFn {
return func(p *operatorapi.SonataFlowPlatform) {
if p.Spec.Services == nil {
p.Spec.Services = &operatorapi.ServicesPlatformSpec{}
}
if p.Spec.Services.JobService == nil {
p.Spec.Services.JobService = &operatorapi.ServiceSpec{}
}
Expand All @@ -182,6 +185,9 @@ func setJobServiceEnabledValue(v *bool) plfmOptionFn {

func setDataIndexEnabledValue(v *bool) plfmOptionFn {
return func(p *operatorapi.SonataFlowPlatform) {
if p.Spec.Services == nil {
p.Spec.Services = &operatorapi.ServicesPlatformSpec{}
}
if p.Spec.Services.DataIndex == nil {
p.Spec.Services.DataIndex = &operatorapi.ServiceSpec{}
}
Expand All @@ -191,6 +197,9 @@ func setDataIndexEnabledValue(v *bool) plfmOptionFn {

func emptyDataIndexServiceSpec() plfmOptionFn {
return func(p *operatorapi.SonataFlowPlatform) {
if p.Spec.Services == nil {
p.Spec.Services = &operatorapi.ServicesPlatformSpec{}
}
if p.Spec.Services.DataIndex == nil {
p.Spec.Services.DataIndex = &operatorapi.ServiceSpec{}
}
Expand All @@ -199,6 +208,9 @@ func emptyDataIndexServiceSpec() plfmOptionFn {

func emptyJobServiceSpec() plfmOptionFn {
return func(p *operatorapi.SonataFlowPlatform) {
if p.Spec.Services == nil {
p.Spec.Services = &operatorapi.ServicesPlatformSpec{}
}
if p.Spec.Services.JobService == nil {
p.Spec.Services.JobService = &operatorapi.ServiceSpec{}
}
Expand All @@ -219,11 +231,14 @@ func setPlatformName(name string) plfmOptionFn {

func setJobServiceJDBC(jdbc string) plfmOptionFn {
return func(p *operatorapi.SonataFlowPlatform) {
if p.Spec.Services == nil {
p.Spec.Services = &operatorapi.ServicesPlatformSpec{}
}
if p.Spec.Services.JobService == nil {
p.Spec.Services.JobService = &operatorapi.ServiceSpec{}
}
if p.Spec.Services.JobService.Persistence == nil {
p.Spec.Services.JobService.Persistence = &operatorapi.PersistencePlatformSpec{}
p.Spec.Services.JobService.Persistence = &operatorapi.PersistenceOptionsSpec{}
}
if p.Spec.Services.JobService.Persistence.PostgreSQL == nil {
p.Spec.Services.JobService.Persistence.PostgreSQL = &operatorapi.PersistencePostgreSQL{}
Expand All @@ -234,11 +249,14 @@ func setJobServiceJDBC(jdbc string) plfmOptionFn {

func setDataIndexJDBC(jdbc string) plfmOptionFn {
return func(p *operatorapi.SonataFlowPlatform) {
if p.Spec.Services == nil {
p.Spec.Services = &operatorapi.ServicesPlatformSpec{}
}
if p.Spec.Services.DataIndex == nil {
p.Spec.Services.DataIndex = &operatorapi.ServiceSpec{}
}
if p.Spec.Services.DataIndex.Persistence == nil {
p.Spec.Services.DataIndex.Persistence = &operatorapi.PersistencePlatformSpec{}
p.Spec.Services.DataIndex.Persistence = &operatorapi.PersistenceOptionsSpec{}
}
if p.Spec.Services.DataIndex.Persistence.PostgreSQL == nil {
p.Spec.Services.DataIndex.Persistence.PostgreSQL = &operatorapi.PersistencePostgreSQL{}
Expand Down
2 changes: 1 addition & 1 deletion controllers/platform/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ func isJobServiceSet(platform *operatorapi.SonataFlowPlatform) bool {
}

func isServicesSet(platform *operatorapi.SonataFlowPlatform) bool {
return platform != nil && (platform.Spec.Services.JobService != nil || platform.Spec.Services.DataIndex != nil)
return platform != nil && platform.Spec.Services != nil
}

func generateServiceURL(protocol string, namespace string, name string) string {
Expand Down
16 changes: 8 additions & 8 deletions controllers/profiles/common/object_creators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func TestMergePodSpec_WithPostgreSQL_and_JDBC_URL_field(t *testing.T) {
},
},
},
Persistence: &v1alpha08.PersistencePlatformSpec{
Persistence: &v1alpha08.PersistenceOptionsSpec{
PostgreSQL: &v1alpha08.PersistencePostgreSQL{
SecretRef: v1alpha08.PostgreSQLSecretOptions{Name: "test"},
JdbcUrl: "jdbc:postgresql://host:port/database?currentSchema=workflow",
Expand Down Expand Up @@ -304,7 +304,7 @@ func TestMergePodSpec_OverrideContainers_WithPostgreSQL_In_Workflow_CR(t *testin
},
},
},
Persistence: &v1alpha08.PersistencePlatformSpec{
Persistence: &v1alpha08.PersistenceOptionsSpec{
PostgreSQL: &v1alpha08.PersistencePostgreSQL{
SecretRef: v1alpha08.PostgreSQLSecretOptions{Name: "test"},
ServiceRef: &v1alpha08.PostgreSQLServiceOptions{
Expand Down Expand Up @@ -375,7 +375,7 @@ func TestMergePodSpec_WithServicedPostgreSQL_In_Platform_CR_And_Worflow_Requesti
Namespace: "default",
},
Spec: v1alpha08.SonataFlowPlatformSpec{
Persistence: &v1alpha08.PersistencePlatformSpec{
Persistence: &v1alpha08.PersistenceOptionsSpec{
PostgreSQL: &v1alpha08.PersistencePostgreSQL{
SecretRef: v1alpha08.PostgreSQLSecretOptions{
Name: "foo_secret",
Expand All @@ -396,7 +396,7 @@ func TestMergePodSpec_WithServicedPostgreSQL_In_Platform_CR_And_Worflow_Requesti

workflow := test.GetBaseSonataFlow(t.Name())
workflow.Spec = v1alpha08.SonataFlowSpec{
Persistence: &v1alpha08.PersistencePlatformSpec{},
Persistence: &v1alpha08.PersistenceOptionsSpec{},
}
object, err := DeploymentCreator(workflow, p)
assert.NoError(t, err)
Expand Down Expand Up @@ -456,7 +456,7 @@ func TestMergePodSpec_WithServicedPostgreSQL_In_Platform_And_In_Workflow_CR(t *t
Namespace: "default",
},
Spec: v1alpha08.SonataFlowPlatformSpec{
Persistence: &v1alpha08.PersistencePlatformSpec{
Persistence: &v1alpha08.PersistenceOptionsSpec{
PostgreSQL: &v1alpha08.PersistencePostgreSQL{
SecretRef: v1alpha08.PostgreSQLSecretOptions{
Name: "foo_secret",
Expand Down Expand Up @@ -493,7 +493,7 @@ func TestMergePodSpec_WithServicedPostgreSQL_In_Platform_And_In_Workflow_CR(t *t
},
},
},
Persistence: &v1alpha08.PersistencePlatformSpec{
Persistence: &v1alpha08.PersistenceOptionsSpec{
PostgreSQL: &v1alpha08.PersistencePostgreSQL{
SecretRef: v1alpha08.PostgreSQLSecretOptions{Name: "test"},
ServiceRef: &v1alpha08.PostgreSQLServiceOptions{
Expand Down Expand Up @@ -563,7 +563,7 @@ func TestMergePodSpec_WithServicedPostgreSQL_In_Platform_But_Workflow_CR_Not_Req
Namespace: "default",
},
Spec: v1alpha08.SonataFlowPlatformSpec{
Persistence: &v1alpha08.PersistencePlatformSpec{
Persistence: &v1alpha08.PersistenceOptionsSpec{
PostgreSQL: &v1alpha08.PersistencePostgreSQL{
SecretRef: v1alpha08.PostgreSQLSecretOptions{
Name: "foo_secret",
Expand Down Expand Up @@ -605,7 +605,7 @@ func TestMergePodSpec_WithEphemeralPostgreSQL_And_Undefined_PostgreSQL_Image_In_
}
workflow := test.GetBaseSonataFlow(t.Name())
workflow.Spec = v1alpha08.SonataFlowSpec{
Persistence: &v1alpha08.PersistencePlatformSpec{},
Persistence: &v1alpha08.PersistenceOptionsSpec{},
}
_, err := DeploymentCreator(workflow, p)
assert.Error(t, err)
Expand Down
6 changes: 2 additions & 4 deletions controllers/profiles/common/persistence/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import (
)

const (
defaultSchemaName = "default"
defaultDatabaseName = "sonataflow"

defaultDatabaseName = "sonataflow"
timeoutSeconds = 3
failureThreshold = 5
initialPeriodSeconds = 15
Expand Down Expand Up @@ -114,7 +112,7 @@ func ConfigurePostgreSQLEnv(postgresql *operatorapi.PersistencePostgreSQL, datab
}
}

func ConfigurePersistence(serviceContainer *corev1.Container, config *operatorapi.PersistencePlatformSpec, defaultSchema, namespace string) (*corev1.Container, error) {
func ConfigurePersistence(serviceContainer *corev1.Container, config *operatorapi.PersistenceOptionsSpec, defaultSchema, namespace string) (*corev1.Container, error) {
if config == nil {
return nil, fmt.Errorf("no persistence specification found")
}
Expand Down
Loading

0 comments on commit f61ee98

Please sign in to comment.