Skip to content

Commit

Permalink
Merge pull request #40 from rgdoliveira/sync_main_1
Browse files Browse the repository at this point in the history
Sync main branch with Apache main branch
  • Loading branch information
rgdoliveira authored May 9, 2024
2 parents 3516ba3 + a11aae4 commit e662f27
Show file tree
Hide file tree
Showing 71 changed files with 1,833 additions and 758 deletions.
28 changes: 28 additions & 0 deletions api/metadata/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,31 @@ const (
// Ideally used in production use cases
GitOpsProfile ProfileType = "gitops"
)

const (
DefaultProfile = PreviewProfile
)

// deprecated prod profile is deprecate and not supported, use preview profile
var supportedProfiles = map[ProfileType]ProfileType{DevProfile: DevProfile, PreviewProfile: PreviewProfile, GitOpsProfile: GitOpsProfile}

func GetProfileOrDefault(annotation map[string]string) ProfileType {
if annotation == nil {
return DefaultProfile
}
if profile, ok := supportedProfiles[ProfileType(annotation[Profile])]; !ok {
return DefaultProfile
} else {
return profile
}
}

func IsDevProfile(annotation map[string]string) bool {
if annotation == nil {
return false
}
if len(annotation[Profile]) == 0 {
return false
}
return ProfileType(annotation[Profile]) == DevProfile
}
43 changes: 43 additions & 0 deletions api/metadata/annotations_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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 metadata

import (
"testing"
)

func TestGetProfile(t *testing.T) {
type args struct {
annotation map[string]string
}
tests := []struct {
name string
args args
want ProfileType
}{
{"Empty Annotations", args{annotation: nil}, DefaultProfile},
{"Non-existent Profile", args{annotation: map[string]string{Profile: "IDontExist"}}, DefaultProfile},
{"Regular Annotation", args{annotation: map[string]string{Profile: GitOpsProfile.String()}}, GitOpsProfile},
{"Deprecated Annotation", args{annotation: map[string]string{Profile: ProdProfile.String()}}, DefaultProfile},
{"Dev Annotation", args{annotation: map[string]string{Profile: DevProfile.String()}}, DevProfile},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetProfileOrDefault(tt.args.annotation); got != tt.want {
t.Errorf("GetProfileOrDefault() = %v, want %v", got, tt.want)
}
})
}
}
545 changes: 545 additions & 0 deletions api/v1alpha08/podtemplate_types.go

Large diffs are not rendered by default.

540 changes: 22 additions & 518 deletions api/v1alpha08/sonataflow_types.go

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions api/v1alpha08/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ data:
sonataFlowDevModeImageTag: ""
# The default name of the builder configMap in the operator's namespace
builderConfigMapName: "sonataflow-operator-builder-config"
# Quarkus extensions required for workflows persistence. These extensions are used by the SonataFlow build system,
# in cases where the workflow being built has configured postgresql persistence.
postgreSQLPersistenceExtensions:
- groupId: io.quarkus
artifactId: quarkus-jdbc-postgresql
version: 3.2.10.Final
- groupId: io.quarkus
artifactId: quarkus-agroal
version: 3.2.10.Final
- groupId: org.kie
artifactId: kie-addons-quarkus-persistence-jdbc
version: 999-SNAPSHOT
kind: ConfigMap
metadata:
name: sonataflow-operator-controllers-config
19 changes: 19 additions & 0 deletions bundle/manifests/sonataflow-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ spec:
- kind: Deployment
name: A Deployment for the Flow
version: apps/v1
- kind: Service
name: A Knative Serving Service for the Flow
version: serving.knative.dev/v1
- kind: Service
name: A Service for the Flow
version: v1
Expand Down Expand Up @@ -437,6 +440,22 @@ spec:
- patch
- update
- watch
- apiGroups:
- serving.knative.dev
resources:
- service
- services
- services/status
- services/finalizers
verbs:
- create
- delete
- deletecollection
- get
- list
- patch
- update
- watch
- apiGroups:
- coordination.k8s.io
resources:
Expand Down
9 changes: 9 additions & 0 deletions bundle/manifests/sonataflow.org_sonataflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5626,6 +5626,13 @@ spec:
- name
type: object
type: array
deploymentModel:
description: Defines the kind of deployment model for this pod
spec. In dev profile, only "kubernetes" is valid.
enum:
- kubernetes
- knative
type: string
dnsConfig:
description: Specifies the DNS parameters of a pod. Parameters
specified here will be merged to the generated DNS configuration
Expand Down Expand Up @@ -7153,6 +7160,8 @@ spec:
type: object
type: array
replicas:
description: Replicas define the number of pods to start by default
for this deployment model. Ignored in "knative" deployment model.
format: int32
type: integer
resourceClaims:
Expand Down
9 changes: 9 additions & 0 deletions config/crd/bases/sonataflow.org_sonataflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5627,6 +5627,13 @@ spec:
- name
type: object
type: array
deploymentModel:
description: Defines the kind of deployment model for this pod
spec. In dev profile, only "kubernetes" is valid.
enum:
- kubernetes
- knative
type: string
dnsConfig:
description: Specifies the DNS parameters of a pod. Parameters
specified here will be merged to the generated DNS configuration
Expand Down Expand Up @@ -7154,6 +7161,8 @@ spec:
type: object
type: array
replicas:
description: Replicas define the number of pods to start by default
for this deployment model. Ignored in "knative" deployment model.
format: int32
type: integer
resourceClaims:
Expand Down
12 changes: 12 additions & 0 deletions config/manager/controllers_cfg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,15 @@ sonataFlowBaseBuilderImageTag: ""
sonataFlowDevModeImageTag: ""
# The default name of the builder configMap in the operator's namespace
builderConfigMapName: "sonataflow-operator-builder-config"
# Quarkus extensions required for workflows persistence. These extensions are used by the SonataFlow build system,
# in cases where the workflow being built has configured postgresql persistence.
postgreSQLPersistenceExtensions:
- groupId: io.quarkus
artifactId: quarkus-jdbc-postgresql
version: 3.2.10.Final
- groupId: io.quarkus
artifactId: quarkus-agroal
version: 3.2.10.Final
- groupId: org.kie
artifactId: kie-addons-quarkus-persistence-jdbc
version: 999-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ spec:
- kind: Deployment
name: A Deployment for the Flow
version: apps/v1
- kind: Service
name: A Knative Serving Service for the Flow
version: serving.knative.dev/v1
- kind: Service
name: A Service for the Flow
version: v1
Expand Down
30 changes: 0 additions & 30 deletions config/rbac/builder_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,3 @@ rules:
- patch
- update
- watch
- apiGroups:
- eventing.knative.dev
resources:
- triggers
- triggers/status
- triggers/finalizers
verbs:
- create
- delete
- deletecollection
- get
- list
- patch
- update
- watch
- apiGroups:
- sources.knative.dev
resources:
- sinkbindings
- sinkbindings/status
- sinkbindings/finalizers
verbs:
- create
- delete
- deletecollection
- get
- list
- patch
- update
- watch
52 changes: 52 additions & 0 deletions config/rbac/knative_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: knative-manager-role
rules:
- apiGroups:
- eventing.knative.dev
resources:
- triggers
- triggers/status
- triggers/finalizers
verbs:
- create
- delete
- deletecollection
- get
- list
- patch
- update
- watch
- apiGroups:
- sources.knative.dev
resources:
- sinkbindings
- sinkbindings/status
- sinkbindings/finalizers
verbs:
- create
- delete
- deletecollection
- get
- list
- patch
- update
- watch
- apiGroups:
- serving.knative.dev
resources:
- service
- services
- services/status
- services/finalizers
verbs:
- create
- delete
- deletecollection
- get
- list
- patch
- update
- watch
13 changes: 13 additions & 0 deletions config/rbac/knative_role_binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: knative-manager-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: knative-manager-role
subjects:
- kind: ServiceAccount
name: controller-manager
namespace: system
2 changes: 2 additions & 0 deletions config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ resources:
- operator_role_binding_leases.yaml
- service_discovery_role.yaml
- service_discovery_role_binding.yaml
- knative_role.yaml
- knative_role_binding.yaml
# Comment the following 4 lines if you want to disable
# the auth proxy (https://github.com/brancz/kube-rbac-proxy)
# which protects your /metrics endpoint.
Expand Down
18 changes: 18 additions & 0 deletions controllers/builder/containerbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ package builder
import (
"time"

"github.com/apache/incubator-kie-kogito-serverless-operator/workflowproj"

corev1 "k8s.io/api/core/v1"

"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/cfg"
"k8s.io/klog/v2"

Expand Down Expand Up @@ -52,6 +56,7 @@ type kanikoBuildInput struct {
task *api.KanikoTask
workflowDefinition []byte
workflow *operatorapi.SonataFlow
workflowProperties []operatorapi.ConfigMapWorkflowResource
dockerfile string
imageTag string
}
Expand Down Expand Up @@ -139,6 +144,7 @@ func (c *containerBuilderManager) scheduleNewKanikoBuildWithContainerFile(build
task: task,
workflowDefinition: workflowDef,
workflow: workflow,
workflowProperties: buildWorkflowPropertyResources(workflow),
dockerfile: platform.GetCustomizedBuilderDockerfile(c.builderConfigMap.Data[defaultBuilderResourceName], *c.platform),
imageTag: buildNamespacedImageTag(workflow),
}
Expand Down Expand Up @@ -200,6 +206,11 @@ func newBuild(buildInput kanikoBuildInput, platform api.PlatformContainerBuild,
newBuilder.AddConfigMapResource(res.ConfigMap, res.WorkflowPath)
}

//make the workflow properties available to the kaniko build.
for _, props := range buildInput.workflowProperties {
newBuilder.AddConfigMapResource(props.ConfigMap, props.WorkflowPath)
}

return newBuilder.Scheduler().
WithAdditionalArgs(buildInput.task.AdditionalFlags).
WithResourceRequirements(buildInput.task.Resources).
Expand All @@ -213,3 +224,10 @@ func newBuild(buildInput kanikoBuildInput, platform api.PlatformContainerBuild,
func buildNamespacedImageTag(workflow *operatorapi.SonataFlow) string {
return workflow.Namespace + "/" + workflowdef.GetWorkflowAppImageNameTag(workflow)
}

func buildWorkflowPropertyResources(workflow *operatorapi.SonataFlow) []operatorapi.ConfigMapWorkflowResource {
return []operatorapi.ConfigMapWorkflowResource{
{ConfigMap: corev1.LocalObjectReference{Name: workflowproj.GetWorkflowUserPropertiesConfigMapName(workflow)}, WorkflowPath: ""},
{ConfigMap: corev1.LocalObjectReference{Name: workflowproj.GetWorkflowManagedPropertiesConfigMapName(workflow)}, WorkflowPath: ""},
}
}
Loading

0 comments on commit e662f27

Please sign in to comment.