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 778ed10  [KOGITO-9776] Make the workflow definition mount point to 
root path in devmode (#258)
778ed10 is described below

commit 778ed103f534970d2d8e90586b56d6752243ecf3
Author: Ricardo Zanini <[email protected]>
AuthorDate: Thu Sep 21 15:16:28 2023 -0300

    [KOGITO-9776] Make the workflow definition mount point to root path in 
devmode (#258)
    
    Signed-off-by: Ricardo Zanini <[email protected]>
---
 controllers/profiles/reconciler_dev.go      |  6 ++---
 controllers/profiles/reconciler_dev_test.go | 38 +++++++++++++----------------
 controllers/workflowdef/configmap.go        |  7 +++++-
 3 files changed, 25 insertions(+), 26 deletions(-)

diff --git a/controllers/profiles/reconciler_dev.go 
b/controllers/profiles/reconciler_dev.go
index 342e81a..557a189 100644
--- a/controllers/profiles/reconciler_dev.go
+++ b/controllers/profiles/reconciler_dev.go
@@ -48,8 +48,6 @@ import (
 )
 
 const (
-       configMapWorkflowDefVolumeName             = "workflow-definition"
-       configMapWorkflowDefMountPath              = 
"/home/kogito/serverless-workflow-project/src/main/resources/workflows"
        configMapResourcesVolumeName               = "resources"
        configMapExternalResourcesVolumeNamePrefix = 
configMapResourcesVolumeName + "-"
 
@@ -354,13 +352,13 @@ func mountDevConfigMapsMutateVisitor(flowDefCM, propsCM 
*corev1.ConfigMap, workf
 
                        volumes := make([]corev1.Volume, 0)
                        volumeMounts := []corev1.VolumeMount{
-                               
kubeutil.VolumeMount(configMapWorkflowDefVolumeName, true, 
configMapWorkflowDefMountPath),
                                
kubeutil.VolumeMount(configMapResourcesVolumeName, true, 
quarkusDevConfigMountPath),
                        }
 
                        // defaultResourcesVolume holds every ConfigMap mount 
required on src/main/resources
                        defaultResourcesVolume := corev1.Volume{Name: 
configMapResourcesVolumeName, VolumeSource: corev1.VolumeSource{Projected: 
&corev1.ProjectedVolumeSource{}}}
                        
kubeutil.VolumeProjectionAddConfigMap(defaultResourcesVolume.Projected, 
propsCM.Name, corev1.KeyToPath{Key: workflowproj.ApplicationPropertiesFileName, 
Path: workflowproj.ApplicationPropertiesFileName})
+                       
kubeutil.VolumeProjectionAddConfigMap(defaultResourcesVolume.Projected, 
flowDefCM.Name)
 
                        // resourceVolumes holds every resource that needs to 
be mounted on src/main/resources/<specific_dir>
                        resourceVolumes := make([]corev1.Volume, 0)
@@ -378,7 +376,7 @@ func mountDevConfigMapsMutateVisitor(flowDefCM, propsCM 
*corev1.ConfigMap, workf
                                resourceVolumes = 
kubeutil.VolumeAddVolumeProjectionConfigMap(resourceVolumes, 
workflowResCM.ConfigMap.Name, volumeMountName)
                        }
 
-                       volumes = append(volumes, defaultResourcesVolume, 
kubeutil.VolumeConfigMap(configMapWorkflowDefVolumeName, flowDefCM.Name))
+                       volumes = append(volumes, defaultResourcesVolume)
                        volumes = append(volumes, resourceVolumes...)
 
                        deployment.Spec.Template.Spec.Volumes = 
make([]corev1.Volume, 0)
diff --git a/controllers/profiles/reconciler_dev_test.go 
b/controllers/profiles/reconciler_dev_test.go
index 79c8832..7914320 100644
--- a/controllers/profiles/reconciler_dev_test.go
+++ b/controllers/profiles/reconciler_dev_test.go
@@ -131,15 +131,14 @@ func Test_newDevProfile(t *testing.T) {
 
        defCM := test.MustGetConfigMap(t, client, workflow)
        assert.NotEmpty(t, 
defCM.Data[workflow.Name+workflowdef.KogitoWorkflowJSONFileExt])
-       assert.Equal(t, configMapWorkflowDefMountPath, 
deployment.Spec.Template.Spec.Containers[0].VolumeMounts[0].MountPath)
+       assert.Equal(t, quarkusDevConfigMountPath, 
deployment.Spec.Template.Spec.Containers[0].VolumeMounts[0].MountPath)
        assert.Equal(t, "", 
deployment.Spec.Template.Spec.Containers[0].VolumeMounts[0].SubPath) 
//https://kubernetes.io/docs/concepts/configuration/configmap/#mounted-configmaps-are-updated-automatically
-       assert.Equal(t, quarkusDevConfigMountPath+"/workflows", 
deployment.Spec.Template.Spec.Containers[0].VolumeMounts[0].MountPath)
 
        propCM := &v1.ConfigMap{}
        _ = client.Get(context.TODO(), types.NamespacedName{Namespace: 
workflow.Namespace, Name: 
workflowproj.GetWorkflowPropertiesConfigMapName(workflow)}, propCM)
        assert.NotEmpty(t, 
propCM.Data[workflowproj.ApplicationPropertiesFileName])
-       assert.Equal(t, quarkusDevConfigMountPath, 
deployment.Spec.Template.Spec.Containers[0].VolumeMounts[1].MountPath)
-       assert.Equal(t, "", 
deployment.Spec.Template.Spec.Containers[0].VolumeMounts[1].SubPath) 
//https://kubernetes.io/docs/concepts/configuration/configmap/#mounted-configmaps-are-updated-automatically
+       assert.Equal(t, quarkusDevConfigMountPath, 
deployment.Spec.Template.Spec.Containers[0].VolumeMounts[0].MountPath)
+       assert.Equal(t, "", 
deployment.Spec.Template.Spec.Containers[0].VolumeMounts[0].SubPath) 
//https://kubernetes.io/docs/concepts/configuration/configmap/#mounted-configmaps-are-updated-automatically
        assert.Contains(t, 
propCM.Data[workflowproj.ApplicationPropertiesFileName], "quarkus.http.port")
 
        service := test.MustGetService(t, client, workflow)
@@ -298,16 +297,13 @@ func Test_newDevProfileWithExternalConfigMaps(t 
*testing.T) {
 
        // check if the objects have been created
        deployment := test.MustGetDeployment(t, client, workflow)
-       assert.Equal(t, 3, 
len(deployment.Spec.Template.Spec.Containers[0].VolumeMounts))
-       assert.Equal(t, 3, len(deployment.Spec.Template.Spec.Volumes))
+       assert.Equal(t, 2, 
len(deployment.Spec.Template.Spec.Containers[0].VolumeMounts))
+       assert.Equal(t, 2, len(deployment.Spec.Template.Spec.Volumes))
 
        wd := deployment.Spec.Template.Spec.Containers[0].VolumeMounts[0]
-       props := deployment.Spec.Template.Spec.Containers[0].VolumeMounts[1]
-       extCamel := deployment.Spec.Template.Spec.Containers[0].VolumeMounts[2]
-       assert.Equal(t, configMapWorkflowDefVolumeName, wd.Name)
-       assert.Equal(t, configMapWorkflowDefMountPath, wd.MountPath)
-       assert.Equal(t, configMapResourcesVolumeName, props.Name)
-       assert.Equal(t, quarkusDevConfigMountPath, props.MountPath)
+       extCamel := deployment.Spec.Template.Spec.Containers[0].VolumeMounts[1]
+       assert.Equal(t, configMapResourcesVolumeName, wd.Name)
+       assert.Equal(t, quarkusDevConfigMountPath, wd.MountPath)
        assert.Equal(t, configMapExternalResourcesVolumeNamePrefix+"routes", 
extCamel.Name)
        assert.Equal(t, extCamel.MountPath, quarkusDevConfigMountPath+"/routes")
 
@@ -326,10 +322,10 @@ func Test_newDevProfileWithExternalConfigMaps(t 
*testing.T) {
 
        //Now we expect 4 volumes mount wd, props  camelroute.xml and 
camelroute.yaml
        deployment = test.MustGetDeployment(t, client, workflow)
-       assert.Equal(t, 3, 
len(deployment.Spec.Template.Spec.Containers[0].VolumeMounts))
-       assert.Equal(t, 3, len(deployment.Spec.Template.Spec.Volumes))
+       assert.Equal(t, 2, 
len(deployment.Spec.Template.Spec.Containers[0].VolumeMounts))
+       assert.Equal(t, 2, len(deployment.Spec.Template.Spec.Volumes))
 
-       extCamelRouteOne := 
deployment.Spec.Template.Spec.Containers[0].VolumeMounts[2]
+       extCamelRouteOne := 
deployment.Spec.Template.Spec.Containers[0].VolumeMounts[1]
        assert.Equal(t, configMapExternalResourcesVolumeNamePrefix+"routes", 
extCamelRouteOne.Name)
        assert.Equal(t, quarkusDevConfigMountPath+"/routes", 
extCamelRouteOne.MountPath)
 
@@ -342,8 +338,8 @@ func Test_newDevProfileWithExternalConfigMaps(t *testing.T) 
{
        assert.NotNil(t, result)
 
        deployment = test.MustGetDeployment(t, client, workflow)
-       assert.Equal(t, 3, 
len(deployment.Spec.Template.Spec.Containers[0].VolumeMounts))
-       assert.Equal(t, 3, len(deployment.Spec.Template.Spec.Volumes))
+       assert.Equal(t, 2, 
len(deployment.Spec.Template.Spec.Containers[0].VolumeMounts))
+       assert.Equal(t, 2, len(deployment.Spec.Template.Spec.Volumes))
 
        // remove the external configmaps without removing the labels
        errDel := client.Delete(context.Background(), cmUser)
@@ -366,11 +362,11 @@ func Test_newDevProfileWithExternalConfigMaps(t 
*testing.T) {
        assert.NotNil(t, result)
 
        deployment = test.MustGetDeployment(t, client, workflow)
-       assert.Equal(t, 2, len(deployment.Spec.Template.Spec.Volumes))
-       assert.Equal(t, 2, 
len(deployment.Spec.Template.Spec.Containers[0].VolumeMounts))
+       assert.Equal(t, 1, len(deployment.Spec.Template.Spec.Volumes))
+       assert.Equal(t, 1, 
len(deployment.Spec.Template.Spec.Containers[0].VolumeMounts))
        wd = deployment.Spec.Template.Spec.Containers[0].VolumeMounts[0]
-       assert.Equal(t, wd.Name, configMapWorkflowDefVolumeName)
-       assert.Equal(t, wd.MountPath, configMapWorkflowDefMountPath)
+       assert.Equal(t, wd.Name, configMapResourcesVolumeName)
+       assert.Equal(t, wd.MountPath, quarkusDevConfigMountPath)
 }
 
 func createConfigMapBase(namespace string, name string, cmData 
map[string]string) clientruntime.Object {
diff --git a/controllers/workflowdef/configmap.go 
b/controllers/workflowdef/configmap.go
index f21298f..e8a7393 100644
--- a/controllers/workflowdef/configmap.go
+++ b/controllers/workflowdef/configmap.go
@@ -43,10 +43,15 @@ func CreateNewConfigMap(workflow *operatorapi.SonataFlow) 
(*corev1.ConfigMap, er
                        Name:      workflow.Name,
                        Namespace: workflow.Namespace,
                },
-               Data: map[string]string{workflow.Name + 
KogitoWorkflowJSONFileExt: string(workflowDef)},
+               Data: map[string]string{GetWorkflowDefFileName(workflow): 
string(workflowDef)},
        }, nil
 }
 
+// GetWorkflowDefFileName returns the default workflow file definition that 
should be injected/mounted to a workflow application given a SonataFlow CR.
+func GetWorkflowDefFileName(workflow *operatorapi.SonataFlow) string {
+       return workflow.Name + KogitoWorkflowJSONFileExt
+}
+
 // FetchExternalResourcesConfigMapsRef fetches the Resource ConfigMaps into a 
LocalObjectReference that a client can mount to the workflow application.
 // The map format is map[<resource_type>]<ConfigMap_reference>. For example 
map["resource-openapi"]{MyOpenApisConfigMap}
 func FetchExternalResourcesConfigMapsRef(client client.Client, workflow 
*operatorapi.SonataFlow) ([]operatorapi.ConfigMapWorkflowResource, error) {


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

Reply via email to