This is an automated email from the ASF dual-hosted git repository.

ricardozanini pushed a commit to branch main
in repository 
https://gitbox.apache.org/repos/asf/incubator-kie-kogito-serverless-operator.git


The following commit(s) were added to refs/heads/main by this push:
     new b2a01bc2 [KOGITO-9857] Fix podTemplate struct to json inline (#269)
b2a01bc2 is described below

commit b2a01bc2d1360f0c3d7c3b51051e85f2ade4ed82
Author: Ricardo Zanini <[email protected]>
AuthorDate: Tue Oct 3 08:37:51 2023 -0300

    [KOGITO-9857] Fix podTemplate struct to json inline (#269)
    
    * [KOGITO-9857] Fix podTemplate struct to json inline
    
    Signed-off-by: Ricardo Zanini <[email protected]>
    
    * Updating OSL meta
    
    Signed-off-by: Ricardo Zanini <[email protected]>
    
    * Fix SHA from OSL images
    
    Signed-off-by: Ricardo Zanini <[email protected]>
    
    ---------
    
    Signed-off-by: Ricardo Zanini <[email protected]>
---
 api/v1alpha08/sonataflow_types.go                  |  4 ++-
 api/v1alpha08/zz_generated.deepcopy.go             |  2 +-
 ...logic-operator-rhel8.clusterserviceversion.yaml |  3 ++
 .../sonataflow-operator.clusterserviceversion.yaml |  4 +++
 .../sonataflow-operator.clusterserviceversion.yaml |  4 +++
 ...logic-operator-rhel8.clusterserviceversion.yaml |  4 +++
 controllers/profiles/common/object_creators.go     |  2 +-
 .../profiles/common/object_creators_test.go        |  4 +--
 controllers/profiles/prod/profile_prod_test.go     | 34 ++++++++++++++++++++++
 hack/local/run-e2e.sh                              |  2 +-
 hack/local/run-operator.sh                         | 10 +++++--
 11 files changed, 64 insertions(+), 9 deletions(-)

diff --git a/api/v1alpha08/sonataflow_types.go 
b/api/v1alpha08/sonataflow_types.go
index 02dc1c98..f22155cd 100644
--- a/api/v1alpha08/sonataflow_types.go
+++ b/api/v1alpha08/sonataflow_types.go
@@ -548,7 +548,8 @@ type FlowPodTemplateSpec struct {
        // One can change this attribute in order to override the defaults 
provided by the operator.
        // +optional
        Container FlowContainer `json:"container,omitempty"`
-       PodSpec   FlowPodSpec   `json:",omitempty"`
+       // +optional
+       FlowPodSpec `json:",inline"`
        // +optional
        Replicas *int32 `json:"replicas,omitempty"`
 }
@@ -649,6 +650,7 @@ type SonataFlowSpec struct {
        
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="resources"
        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"`
 }
 
diff --git a/api/v1alpha08/zz_generated.deepcopy.go 
b/api/v1alpha08/zz_generated.deepcopy.go
index 489cde64..98ce2354 100644
--- a/api/v1alpha08/zz_generated.deepcopy.go
+++ b/api/v1alpha08/zz_generated.deepcopy.go
@@ -485,7 +485,7 @@ func (in *FlowPodSpec) DeepCopy() *FlowPodSpec {
 func (in *FlowPodTemplateSpec) DeepCopyInto(out *FlowPodTemplateSpec) {
        *out = *in
        in.Container.DeepCopyInto(&out.Container)
-       in.PodSpec.DeepCopyInto(&out.PodSpec)
+       in.FlowPodSpec.DeepCopyInto(&out.FlowPodSpec)
        if in.Replicas != nil {
                in, out := &in.Replicas, &out.Replicas
                *out = new(int32)
diff --git 
a/bundle.osl/manifests/logic-operator-rhel8.clusterserviceversion.yaml 
b/bundle.osl/manifests/logic-operator-rhel8.clusterserviceversion.yaml
index 7957e080..753fd795 100644
--- a/bundle.osl/manifests/logic-operator-rhel8.clusterserviceversion.yaml
+++ b/bundle.osl/manifests/logic-operator-rhel8.clusterserviceversion.yaml
@@ -222,6 +222,9 @@ spec:
           - description: Flow the workflow definition.
             displayName: flow
             path: flow
+          - description: PodTemplate describes the deployment details of this 
SonataFlow instance.
+            displayName: podTemplate
+            path: podTemplate
           - description: Resources workflow resources that are linked to this 
workflow definition. For example, a collection of OpenAPI specification files.
             displayName: resources
             path: resources
diff --git a/bundle/manifests/sonataflow-operator.clusterserviceversion.yaml 
b/bundle/manifests/sonataflow-operator.clusterserviceversion.yaml
index 762a5598..ef4a6738 100644
--- a/bundle/manifests/sonataflow-operator.clusterserviceversion.yaml
+++ b/bundle/manifests/sonataflow-operator.clusterserviceversion.yaml
@@ -243,6 +243,10 @@ spec:
       - description: Flow the workflow definition.
         displayName: flow
         path: flow
+      - description: PodTemplate describes the deployment details of this 
SonataFlow
+          instance.
+        displayName: podTemplate
+        path: podTemplate
       - description: Resources workflow resources that are linked to this 
workflow
           definition. For example, a collection of OpenAPI specification files.
         displayName: resources
diff --git 
a/config/manifests/bases/sonataflow-operator.clusterserviceversion.yaml 
b/config/manifests/bases/sonataflow-operator.clusterserviceversion.yaml
index c52816fb..26107722 100644
--- a/config/manifests/bases/sonataflow-operator.clusterserviceversion.yaml
+++ b/config/manifests/bases/sonataflow-operator.clusterserviceversion.yaml
@@ -140,6 +140,10 @@ spec:
       - description: Flow the workflow definition.
         displayName: flow
         path: flow
+      - description: PodTemplate describes the deployment details of this 
SonataFlow
+          instance.
+        displayName: podTemplate
+        path: podTemplate
       - description: Resources workflow resources that are linked to this 
workflow
           definition. For example, a collection of OpenAPI specification files.
         displayName: resources
diff --git 
a/config/manifests/osl/bases/logic-operator-rhel8.clusterserviceversion.yaml 
b/config/manifests/osl/bases/logic-operator-rhel8.clusterserviceversion.yaml
index 348bc71a..5630abc4 100644
--- a/config/manifests/osl/bases/logic-operator-rhel8.clusterserviceversion.yaml
+++ b/config/manifests/osl/bases/logic-operator-rhel8.clusterserviceversion.yaml
@@ -141,6 +141,10 @@ spec:
       - description: Flow the workflow definition.
         displayName: flow
         path: flow
+      - description: PodTemplate describes the deployment details of this 
SonataFlow
+          instance.
+        displayName: podTemplate
+        path: podTemplate
       - description: Resources workflow resources that are linked to this 
workflow
           definition. For example, a collection of OpenAPI specification files.
         displayName: resources
diff --git a/controllers/profiles/common/object_creators.go 
b/controllers/profiles/common/object_creators.go
index 15e5b7c0..a8c8c029 100644
--- a/controllers/profiles/common/object_creators.go
+++ b/controllers/profiles/common/object_creators.go
@@ -80,7 +80,7 @@ func DeploymentCreator(workflow *operatorapi.SonataFlow) 
(client.Object, error)
                },
        }
 
-       if err := mergo.Merge(&deployment.Spec.Template.Spec, 
workflow.Spec.PodTemplate.PodSpec.ToPodSpec(), mergo.WithOverride); err != nil {
+       if err := mergo.Merge(&deployment.Spec.Template.Spec, 
workflow.Spec.PodTemplate.FlowPodSpec.ToPodSpec(), mergo.WithOverride); err != 
nil {
                return nil, err
        }
 
diff --git a/controllers/profiles/common/object_creators_test.go 
b/controllers/profiles/common/object_creators_test.go
index 32bca25d..10a1f32e 100644
--- a/controllers/profiles/common/object_creators_test.go
+++ b/controllers/profiles/common/object_creators_test.go
@@ -96,7 +96,7 @@ func TestMergePodSpec(t *testing.T) {
                                {Name: "myvolume", ReadOnly: true, MountPath: 
"/tmp/any/path"},
                        },
                },
-               PodSpec: v1alpha08.FlowPodSpec{
+               FlowPodSpec: v1alpha08.FlowPodSpec{
                        ServiceAccountName: "superuser",
                        Containers: []corev1.Container{
                                {
@@ -134,7 +134,7 @@ func TestMergePodSpec(t *testing.T) {
 func TestMergePodSpec_OverrideContainers(t *testing.T) {
        workflow := test.GetBaseSonataFlow(t.Name())
        workflow.Spec.PodTemplate = v1alpha08.FlowPodTemplateSpec{
-               PodSpec: v1alpha08.FlowPodSpec{
+               FlowPodSpec: v1alpha08.FlowPodSpec{
                        // Try to override the workflow container via the 
podspec
                        Containers: []corev1.Container{
                                {
diff --git a/controllers/profiles/prod/profile_prod_test.go 
b/controllers/profiles/prod/profile_prod_test.go
index ab81e8e5..25349bbe 100644
--- a/controllers/profiles/prod/profile_prod_test.go
+++ b/controllers/profiles/prod/profile_prod_test.go
@@ -34,6 +34,11 @@ import (
 
 func Test_Reconciler_ProdOps(t *testing.T) {
        workflow := test.GetBaseSonataFlowWithProdOpsProfile(t.Name())
+       workflow.Spec.PodTemplate.FlowPodSpec.InitContainers = 
append(workflow.Spec.PodTemplate.FlowPodSpec.InitContainers, corev1.Container{
+               Name:    "check-postgres",
+               Image:   "registry.access.redhat.com/ubi9/ubi-minimal:latest",
+               Command: []string{"sh", "-c", "until (echo 1 > 
/dev/tcp/postgres.$(cat 
/var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local/5432)
 >/dev/null 2>&1; do echo \"Waiting for postgres server\"; sleep 3; done;"},
+       })
        client := test.NewKogitoClientBuilder().
                WithRuntimeObjects(workflow).
                WithStatusSubresource(workflow, 
&operatorapi.SonataFlowBuild{}).Build()
@@ -58,6 +63,35 @@ func Test_Reconciler_ProdOps(t *testing.T) {
 
        assert.Len(t, deployment.Spec.Template.Spec.Volumes, 1)
        assert.Len(t, deployment.Spec.Template.Spec.Containers, 1)
+       assert.Len(t, deployment.Spec.Template.Spec.InitContainers, 1)
+       assert.Len(t, deployment.Spec.Template.Spec.Containers[0].VolumeMounts, 
1)
+}
+
+func Test_Reconciler_ProdCustomPod(t *testing.T) {
+       workflow := test.GetBaseSonataFlowWithProdProfile(t.Name())
+       workflow.Spec.PodTemplate.FlowPodSpec.InitContainers = 
append(workflow.Spec.PodTemplate.FlowPodSpec.InitContainers, corev1.Container{
+               Name:    "check-postgres",
+               Image:   "registry.access.redhat.com/ubi9/ubi-minimal:latest",
+               Command: []string{"sh", "-c", "until (echo 1 > 
/dev/tcp/postgres.$(cat 
/var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local/5432)
 >/dev/null 2>&1; do echo \"Waiting for postgres server\"; sleep 3; done;"},
+       })
+       workflow.Status.Manager().MarkTrue(api.BuiltConditionType)
+       workflow.Status.Manager().MarkTrue(api.RunningConditionType)
+       build := test.GetLocalSucceedSonataFlowBuild(workflow.Name, 
workflow.Namespace)
+       platform := test.GetBasePlatformInReadyPhase(workflow.Namespace)
+       client := test.NewKogitoClientBuilder().
+               WithRuntimeObjects(workflow, build, platform).
+               WithStatusSubresource(workflow, build, platform).Build()
+       _, err := NewProfileReconciler(client).Reconcile(context.TODO(), 
workflow)
+       assert.NoError(t, err)
+
+       // Let's check for the right creation of the workflow (one CM volume, 
one container with a custom image)
+       deployment := &appsv1.Deployment{}
+       err = client.Get(context.TODO(), 
clientruntime.ObjectKeyFromObject(workflow), deployment)
+       assert.NoError(t, err)
+
+       assert.Len(t, deployment.Spec.Template.Spec.Volumes, 1)
+       assert.Len(t, deployment.Spec.Template.Spec.Containers, 1)
+       assert.Len(t, deployment.Spec.Template.Spec.InitContainers, 1)
        assert.Len(t, deployment.Spec.Template.Spec.Containers[0].VolumeMounts, 
1)
 }
 
diff --git a/hack/local/run-e2e.sh b/hack/local/run-e2e.sh
index bbfae023..b8ce82b8 100755
--- a/hack/local/run-e2e.sh
+++ b/hack/local/run-e2e.sh
@@ -19,7 +19,7 @@ MINIKUBE_PROFILE=${1:-minikube}
 echo "Using minikube profile ${MINIKUBE_PROFILE}"
 
 # clean up previous runs
-make undeploy
+make undeploy ignore-not-found=true
 
 export OPERATOR_IMAGE_NAME=localhost/kogito-serverless-operator:0.0.1
 eval "$(minikube -p "${MINIKUBE_PROFILE}" docker-env)"
diff --git a/hack/local/run-operator.sh b/hack/local/run-operator.sh
index 8b3ed077..ebb2e31e 100755
--- a/hack/local/run-operator.sh
+++ b/hack/local/run-operator.sh
@@ -15,9 +15,13 @@
 
 # Runs the operator locally via go main
 
-kubectl apply -f ./bundle/manifests/sonataflow.org_sonataflowplatforms.yaml
-kubectl apply -f ./bundle/manifests/sonataflow.org_sonataflowbuilds.yaml
-kubectl apply -f ./bundle/manifests/sonataflow.org_sonataflows.yaml
+kubectl delete --ignore-not-found=true -f 
./bundle/manifests/sonataflow.org_sonataflowplatforms.yaml
+kubectl delete --ignore-not-found=true -f 
./bundle/manifests/sonataflow.org_sonataflowbuilds.yaml
+kubectl delete --ignore-not-found=true -f 
./bundle/manifests/sonataflow.org_sonataflows.yaml
+
+kubectl create -f ./bundle/manifests/sonataflow.org_sonataflowplatforms.yaml
+kubectl create -f ./bundle/manifests/sonataflow.org_sonataflowbuilds.yaml
+kubectl create -f ./bundle/manifests/sonataflow.org_sonataflows.yaml
 kubectl apply -f 
./bundle/manifests/sonataflow-operator-builder-config_v1_configmap.yaml
 
 make debug
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to