Skip to content

Commit

Permalink
Issue #402 - Move profiles check to workflowproj module
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo Zanini <[email protected]>
  • Loading branch information
ricardozanini committed Feb 19, 2024
1 parent a41121a commit 5dcd50a
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 32 deletions.
6 changes: 3 additions & 3 deletions controllers/platform/services/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import (
"strings"

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

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

operatorapi "github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles/common/constants"

"github.com/magiconair/properties"
Expand Down Expand Up @@ -163,7 +163,7 @@ func GenerateDataIndexWorkflowProperties(workflow *operatorapi.SonataFlow, platf
props.Set(constants.KogitoProcessDefinitionsEventsEnabled, "false")
props.Set(constants.KogitoProcessInstancesEventsEnabled, "false")
di := NewDataIndexHandler(platform)
if workflow != nil && !profiles.IsDevProfile(workflow) && di.IsServiceEnabled() {
if workflow != nil && !workflowproj.IsDevProfile(workflow) && di.IsServiceEnabled() {
props.Set(constants.KogitoProcessDefinitionsEventsEnabled, "true")
props.Set(constants.KogitoProcessDefinitionsEventsErrorsEnabled, "true")
props.Set(constants.KogitoProcessInstancesEventsEnabled, "true")
Expand All @@ -189,7 +189,7 @@ func GenerateJobServiceWorkflowProperties(workflow *operatorapi.SonataFlow, plat
props.Set(constants.JobServiceRequestEventsConnector, constants.QuarkusHTTP)
props.Set(constants.JobServiceRequestEventsURL, fmt.Sprintf("%s://localhost/v2/jobs/events", constants.JobServiceURLProtocol))
js := NewJobServiceHandler(platform)
if workflow != nil && !profiles.IsDevProfile(workflow) && js.IsServiceEnabled() {
if workflow != nil && !workflowproj.IsDevProfile(workflow) && js.IsServiceEnabled() {
if workflowdef.HasTimeouts(workflow) {
props.Set(constants.KogitoJobServiceHealthCheckEnabled, "true")
}
Expand Down
3 changes: 1 addition & 2 deletions controllers/profiles/dev/object_creators_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

operatorapi "github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles/common"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/workflowdef"
kubeutil "github.com/apache/incubator-kie-kogito-serverless-operator/utils/kubernetes"
Expand All @@ -48,7 +47,7 @@ func serviceCreator(workflow *operatorapi.SonataFlow) (client.Object, error) {
object, _ := common.ServiceCreator(workflow)
service := object.(*corev1.Service)
// Let's double-check that the workflow is using the Dev Profile we would like to expose it via NodePort
if profiles.IsDevProfile(workflow) {
if workflowproj.IsDevProfile(workflow) {
service.Spec.Type = corev1.ServiceTypeNodePort
}
return service, nil
Expand Down
2 changes: 1 addition & 1 deletion controllers/profiles/dev/profile_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
package dev

import (
"github.com/apache/incubator-kie-kogito-serverless-operator/api/metadata"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/discovery"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/apache/incubator-kie-kogito-serverless-operator/api/metadata"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles/common"
"github.com/apache/incubator-kie-kogito-serverless-operator/log"
Expand Down
2 changes: 1 addition & 1 deletion controllers/profiles/prod/profile_prod.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ package prod
import (
"time"

"github.com/apache/incubator-kie-kogito-serverless-operator/api/metadata"
"k8s.io/client-go/rest"

"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/discovery"
"k8s.io/client-go/tools/record"

"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/apache/incubator-kie-kogito-serverless-operator/api/metadata"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles/common"
)
Expand Down
20 changes: 1 addition & 19 deletions controllers/profiles/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ package profiles
import (
"context"

"github.com/apache/incubator-kie-kogito-serverless-operator/api/metadata"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/apache/incubator-kie-kogito-serverless-operator/api/metadata"
operatorapi "github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08"
)

Expand Down Expand Up @@ -72,21 +72,3 @@ type ReconciliationState interface {
// PostReconcile performs the actions to perform after the reconciliation that are not mandatory
PostReconcile(ctx context.Context, workflow *operatorapi.SonataFlow) error
}

// IsDevProfile detects if the workflow is using the Dev profile or not
func IsDevProfile(workflow *operatorapi.SonataFlow) bool {
profile := workflow.Annotations[metadata.Profile]
if len(profile) == 0 {
return false
}
return metadata.ProfileType(profile) == metadata.DevProfile
}

// IsProdProfile detects if the workflow is using the Prod profile or not
func IsProdProfile(workflow *operatorapi.SonataFlow) bool {
profile := workflow.Annotations[metadata.Profile]
if len(profile) == 0 {
return false
}
return metadata.ProfileType(profile) == metadata.ProdProfile
}
7 changes: 4 additions & 3 deletions controllers/profiles/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ package profiles
import (
"testing"

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

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

func Test_workflowIsDevProfile(t *testing.T) {
workflowWithDevProfile := test.GetBaseSonataFlowWithDevProfile(t.Name())
assert.True(t, IsDevProfile(workflowWithDevProfile))
assert.True(t, workflowproj.IsDevProfile(workflowWithDevProfile))

workflowWithNoProfile := test.GetBaseSonataFlow(t.Name())
assert.False(t, IsDevProfile(workflowWithNoProfile))
assert.False(t, workflowproj.IsDevProfile(workflowWithNoProfile))

workflowWithProdProfile := test.GetBaseSonataFlowWithProdProfile(t.Name())
assert.False(t, IsDevProfile(workflowWithProdProfile))
assert.False(t, workflowproj.IsDevProfile(workflowWithProdProfile))
}
5 changes: 2 additions & 3 deletions workflowproj/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (

"github.com/apache/incubator-kie-kogito-serverless-operator/api/metadata"
operatorapi "github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08"
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles"
)

const (
Expand Down Expand Up @@ -74,10 +73,10 @@ func GetWorkflowManagedPropertiesConfigMapName(workflow *operatorapi.SonataFlow)
return workflow.Name + workflowManagedConfigMapNameSuffix
}

// GetWorkflowManagedPropertiesConfigMapName gets the default ConfigMap name that holds the managed application property for the given workflow
// GetManagedPropertiesFileName gets the default ConfigMap name that holds the managed application property for the given workflow
func GetManagedPropertiesFileName(workflow *operatorapi.SonataFlow) string {
profile := metadata.ProdProfile
if profiles.IsDevProfile(workflow) {
if IsDevProfile(workflow) {
profile = metadata.DevProfile
}
return fmt.Sprintf("application-%s.properties", profile)
Expand Down
9 changes: 9 additions & 0 deletions workflowproj/workflowproj.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,12 @@ func (w *workflowProjectHandler) addResourceConfigMapToProject(cm *corev1.Config
}
return nil
}

// IsDevProfile detects if the workflow is using the Dev profile or not
func IsDevProfile(workflow *operatorapi.SonataFlow) bool {
profile := workflow.Annotations[metadata.Profile]
if len(profile) == 0 {
return false
}
return metadata.ProfileType(profile) == metadata.DevProfile
}

0 comments on commit 5dcd50a

Please sign in to comment.