Skip to content

Commit

Permalink
[KOGITO-9895] Add Data Index Deployment to SonataFlowPlatform (#287)
Browse files Browse the repository at this point in the history
* data index schema

Signed-off-by: Tommy Hughes <[email protected]>

* rename structs to PodSpec and ContainerSpec

Signed-off-by: Tommy Hughes <[email protected]>

* addtl fixes

Signed-off-by: Tommy Hughes <[email protected]>

* add jdbc url option to postgresql config

Signed-off-by: Tommy Hughes <[email protected]>

* more fixes

Signed-off-by: Tommy Hughes <[email protected]>

* move persistence into DI service object

Signed-off-by: Tommy Hughes <[email protected]>

* isolate PodSpec

Signed-off-by: Tommy Hughes <[email protected]>

* PodTemplateSpec fixes

Signed-off-by: Tommy Hughes <[email protected]>

---------

Signed-off-by: Tommy Hughes <[email protected]>
  • Loading branch information
tchughesiv authored Nov 8, 2023
1 parent e37b935 commit a96add5
Show file tree
Hide file tree
Showing 29 changed files with 24,633 additions and 161 deletions.
28 changes: 14 additions & 14 deletions api/v1alpha08/sonataflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (

const DefaultContainerName = "workflow"

// FlowContainer is the container for the internal workflow deployment based on the default Kubernetes Container API
type FlowContainer struct {
// ContainerSpec is the container for the internal deployments based on the default Kubernetes Container API
type ContainerSpec struct {
// Container image name.
// More info: https://kubernetes.io/docs/concepts/containers/images
// This field is optional to allow higher level config management to default or override
Expand Down Expand Up @@ -183,7 +183,7 @@ type FlowContainer struct {
}

// ToContainer converts to Kubernetes Container API.
func (f *FlowContainer) ToContainer() corev1.Container {
func (f *ContainerSpec) ToContainer() corev1.Container {
return corev1.Container{
Name: DefaultContainerName,
Image: f.Image,
Expand All @@ -210,8 +210,8 @@ func (f *FlowContainer) ToContainer() corev1.Container {
}
}

// FlowPodSpec describes the PodSpec for the internal workflow deployment based on the default Kubernetes PodSpec API
type FlowPodSpec struct {
// PodSpec describes the PodSpec for the internal deployments based on the default Kubernetes PodSpec API
type PodSpec struct {
// List of volumes that can be mounted by containers belonging to the pod.
// More info: https://kubernetes.io/docs/concepts/storage/volumes
// +optional
Expand Down Expand Up @@ -497,7 +497,7 @@ type FlowPodSpec struct {
ResourceClaims []corev1.PodResourceClaim `json:"resourceClaims,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"name" protobuf:"bytes,39,rep,name=resourceClaims"`
}

func (f *FlowPodSpec) ToPodSpec() corev1.PodSpec {
func (f *PodSpec) ToPodSpec() corev1.PodSpec {
return corev1.PodSpec{
Volumes: f.Volumes,
InitContainers: f.InitContainers,
Expand Down Expand Up @@ -539,17 +539,17 @@ func (f *FlowPodSpec) ToPodSpec() corev1.PodSpec {
}
}

// FlowPodTemplateSpec describes the desired custom Kubernetes PodTemplate definition for the deployed flow.
// PodTemplateSpec describes the desired custom Kubernetes PodTemplate definition for the deployed flow or service.
//
// The FlowContainer describes the container where the actual flow is running. It will override any default definitions.
// The ContainerSpec describes the container where the actual flow or service is running. It will override any default definitions.
// For example, to override the image one can use `.spec.podTemplate.container.image = my/image:tag`.
type FlowPodTemplateSpec struct {
// Container is the Kubernetes container where the workflow application should run.
type PodTemplateSpec struct {
// Container is the Kubernetes container where the application should run.
// One can change this attribute in order to override the defaults provided by the operator.
// +optional
Container FlowContainer `json:"container,omitempty"`
Container ContainerSpec `json:"container,omitempty"`
// +optional
FlowPodSpec `json:",inline"`
PodSpec `json:",inline"`
// +optional
Replicas *int32 `json:"replicas,omitempty"`
}
Expand Down Expand Up @@ -651,7 +651,7 @@ type SonataFlowSpec struct {
Resources WorkflowResources `json:"resources,omitempty"`
// PodTemplate describes the deployment details of this SonataFlow instance.
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="podTemplate"
PodTemplate FlowPodTemplateSpec `json:"podTemplate,omitempty"`
PodTemplate PodTemplateSpec `json:"podTemplate,omitempty"`
}

// SonataFlowStatus defines the observed state of SonataFlow
Expand Down Expand Up @@ -750,7 +750,7 @@ type SonataFlow struct {
Status SonataFlowStatus `json:"status,omitempty"`
}

func (s *SonataFlow) HasFlowContainerImage() bool {
func (s *SonataFlow) HasContainerSpecImage() bool {
return len(s.Spec.PodTemplate.Container.Image) > 0
}

Expand Down
89 changes: 89 additions & 0 deletions api/v1alpha08/sonataflowplatform_services_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2023 Red Hat, Inc. and/or its affiliates
//
// 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

// ServicesPlatformSpec describes the desired service configuration for "prod" workflows.
type ServicesPlatformSpec struct {
// Deploys the Data Index service for use by "prod" profile workflows.
// +optional
DataIndex *ServiceSpec `json:"dataIndex,omitempty"`
}

// ServiceSpec defines the desired state of a platform service
// +k8s:openapi-gen=true
type ServiceSpec struct {
// Determines whether "prod" profile workflows should be configured to use this service
// +optional
Enabled *bool `json:"enabled,omitempty"`
// Persists service to a datasource of choice. Ephemeral by default.
// +optional
Persistence *PersistenceOptions `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"`
}

// PersistenceOptions configure the services to persist to a datasource of choice
// +kubebuilder:validation:MaxProperties=1
type PersistenceOptions 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"`
}

// PostgreSqlServiceOptions use k8s service to configure postgresql jdbc url.
type PostgreSqlServiceOptions 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"`
// Schema of postgresql database to be used. Defaults to "data-index-service"
// +optional
DatabaseSchema string `json:"databaseSchema,omitempty"`
}
5 changes: 5 additions & 0 deletions api/v1alpha08/sonataflowplatform_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ type SonataFlowPlatformSpec struct {
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="DevMode"
DevMode DevModePlatformSpec `json:"devMode,omitempty"`
// Services attributes for deploying supporting applications like Data Index.
// Only workflows with the proper annotation will be configured to use these service(s).
// `sonataflow.org/profile: prod`
// +optional
Services ServicesPlatformSpec `json:"services,omitempty"`
}

// PlatformCluster is the kind of orchestration cluster the platform is installed into
Expand Down
Loading

0 comments on commit a96add5

Please sign in to comment.