Skip to content

Commit

Permalink
Issue #402 - Move profiles check to workflowproj module (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardozanini authored Feb 19, 2024
1 parent eadb4ae commit 5ebaf85
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 26 deletions.
3 changes: 1 addition & 2 deletions controllers/platform/services/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ import (
"net/url"
"strings"

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

"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
2 changes: 1 addition & 1 deletion controllers/profiles/dev/object_creators_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ package dev
import (
"path"

"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"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 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
22 changes: 4 additions & 18 deletions controllers/profiles/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ package profiles
import (
"context"

"github.com/apache/incubator-kie-kogito-serverless-operator/api/metadata"
"github.com/apache/incubator-kie-kogito-serverless-operator/workflowproj"
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 @@ -73,20 +74,5 @@ type ReconciliationState interface {
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
}
// IsDevProfile is an alias for workflowproj.IsDevProfile
var IsDevProfile = workflowproj.IsDevProfile
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 5ebaf85

Please sign in to comment.