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 e7443bad [KOGITO-8524] Enable toggle dev/prod profiles (#293)
e7443bad is described below
commit e7443badbc01fe78ebf25111022c5ddf52e067ea
Author: Ricardo Zanini <[email protected]>
AuthorDate: Wed Nov 1 12:36:56 2023 -0300
[KOGITO-8524] Enable toggle dev/prod profiles (#293)
Signed-off-by: Ricardo Zanini <[email protected]>
---
api/v1alpha08/sonataflow_types.go | 5 +++
.../builder/kogitoserverlessbuild_manager.go | 2 +-
controllers/platform/defaults.go | 35 +++++++++++++++++++--
controllers/platform/initialize.go | 2 +-
controllers/platform/platform.go | 36 ++++++++++++----------
controllers/platform/platformutils.go | 4 +--
controllers/profiles/prod/states_prod.go | 7 ++++-
test/e2e/workflow_test.go | 10 ------
8 files changed, 68 insertions(+), 33 deletions(-)
diff --git a/api/v1alpha08/sonataflow_types.go
b/api/v1alpha08/sonataflow_types.go
index a569876c..028ecf6d 100644
--- a/api/v1alpha08/sonataflow_types.go
+++ b/api/v1alpha08/sonataflow_types.go
@@ -716,6 +716,11 @@ func (s *SonataFlowStatus) IsBuildRunningOrUnknown() bool {
return cond.IsUnknown() || (cond.IsFalse() && cond.Reason ==
api.BuildIsRunningReason)
}
+func (s *SonataFlowStatus) IsBuildRunning() bool {
+ cond := s.GetCondition(api.BuiltConditionType)
+ return cond.IsFalse() && cond.Reason == api.BuildIsRunningReason
+}
+
func (s *SonataFlowStatus) IsBuildFailed() bool {
cond := s.GetCondition(api.BuiltConditionType)
return cond.IsFalse() && cond.Reason == api.BuildFailedReason
diff --git a/controllers/builder/kogitoserverlessbuild_manager.go
b/controllers/builder/kogitoserverlessbuild_manager.go
index e6dca650..50f9acb8 100644
--- a/controllers/builder/kogitoserverlessbuild_manager.go
+++ b/controllers/builder/kogitoserverlessbuild_manager.go
@@ -67,7 +67,7 @@ func (k *sonataFlowBuildManager) GetOrCreateBuild(workflow
*operatorapi.SonataFl
type SonataFlowBuildManager interface {
// GetOrCreateBuild gets or creates a new instance of SonataFlowBuild
for the given SonataFlow.
//
- // Only one build is allowed per workflow instance
+ // Only one build is allowed per workflow instance.
GetOrCreateBuild(workflow *operatorapi.SonataFlow)
(*operatorapi.SonataFlowBuild, error)
// MarkToRestart tell the controller to restart this build in the next
iteration
MarkToRestart(build *operatorapi.SonataFlowBuild) error
diff --git a/controllers/platform/defaults.go b/controllers/platform/defaults.go
index ee2015f5..828775d8 100644
--- a/controllers/platform/defaults.go
+++ b/controllers/platform/defaults.go
@@ -17,6 +17,7 @@ package platform
import (
"context"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime/pkg/client"
@@ -27,6 +28,8 @@ import (
operatorapi
"github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08"
)
+const defaultSonataFlowPlatformName = "sonataflow-platform"
+
func ConfigureDefaults(ctx context.Context, c client.Client, p
*operatorapi.SonataFlowPlatform, verbose bool) error {
// update missing fields in the resource
if p.Status.Cluster == "" || utils.IsOpenShift() {
@@ -38,12 +41,12 @@ func ConfigureDefaults(ctx context.Context, c
client.Client, p *operatorapi.Sona
p.Spec.Build.Config.BuildStrategy =
operatorapi.OperatorBuildStrategy
}
- err := SetPlatformDefaults(p, verbose)
+ err := setPlatformDefaults(p, verbose)
if err != nil {
return err
}
- err = ConfigureRegistry(ctx, c, p, verbose)
+ err = configureRegistry(ctx, c, p, verbose)
if err != nil {
return err
}
@@ -71,3 +74,31 @@ func updatePlatform(ctx context.Context, c client.Client, p
*operatorapi.SonataF
klog.V(log.E).ErrorS(updateErr, "Error updating the
BuildPlatform")
}
}
+
+func newDefaultSonataFlowPlatform(namespace string)
*operatorapi.SonataFlowPlatform {
+ if utils.IsOpenShift() {
+ return &operatorapi.SonataFlowPlatform{
+ ObjectMeta: metav1.ObjectMeta{Name:
defaultSonataFlowPlatformName, Namespace: namespace},
+ Spec: operatorapi.SonataFlowPlatformSpec{
+ Build: operatorapi.BuildPlatformSpec{
+ Config: operatorapi.BuildPlatformConfig{
+ BuildStrategy:
operatorapi.PlatformBuildStrategy,
+ },
+ },
+ },
+ }
+ }
+
+ return &operatorapi.SonataFlowPlatform{
+ ObjectMeta: metav1.ObjectMeta{Name:
defaultSonataFlowPlatformName, Namespace: namespace},
+ Spec: operatorapi.SonataFlowPlatformSpec{
+ Build: operatorapi.BuildPlatformSpec{
+ Config: operatorapi.BuildPlatformConfig{
+ BuildStrategyOptions: map[string]string{
+ kanikoBuildCacheEnabled: "true",
+ },
+ },
+ },
+ },
+ }
+}
diff --git a/controllers/platform/initialize.go
b/controllers/platform/initialize.go
index 6d79d122..44207349 100644
--- a/controllers/platform/initialize.go
+++ b/controllers/platform/initialize.go
@@ -156,7 +156,7 @@ func (action *initializeAction) isPrimaryDuplicate(ctx
context.Context, thisPlat
// Always reconcile secondary platforms
return false, nil
}
- platforms, err := ListPrimaryPlatforms(ctx, action.client,
thisPlatform.Namespace)
+ platforms, err := listPrimaryPlatforms(ctx, action.client,
thisPlatform.Namespace)
if err != nil {
return false, err
}
diff --git a/controllers/platform/platform.go b/controllers/platform/platform.go
index 87fb0040..db646f45 100644
--- a/controllers/platform/platform.go
+++ b/controllers/platform/platform.go
@@ -114,21 +114,21 @@ func GetOperatorLockName(operatorID string) string {
}
// GetActivePlatform returns the currently installed active platform in the
local namespace.
-func GetActivePlatform(ctx context.Context, c ctrl.Reader, namespace string)
(*operatorapi.SonataFlowPlatform, error) {
- return GetLocalPlatform(ctx, c, namespace, true)
+func GetActivePlatform(ctx context.Context, c ctrl.Client, namespace string)
(*operatorapi.SonataFlowPlatform, error) {
+ return getLocalPlatform(ctx, c, namespace, true)
}
-// GetLocalPlatform returns the currently installed platform or any platform
existing in local namespace.
-func GetLocalPlatform(ctx context.Context, c ctrl.Reader, namespace string,
active bool) (*operatorapi.SonataFlowPlatform, error) {
+// getLocalPlatform returns the currently installed platform or any platform
existing in local namespace.
+func getLocalPlatform(ctx context.Context, c ctrl.Client, namespace string,
active bool) (*operatorapi.SonataFlowPlatform, error) {
klog.V(log.D).InfoS("Finding available platforms")
- lst, err := ListPrimaryPlatforms(ctx, c, namespace)
+ lst, err := listPrimaryPlatforms(ctx, c, namespace)
if err != nil {
return nil, err
}
- for _, platform := range lst.Items {
- platform := platform // pin
+ for _, p := range lst.Items {
+ platform := p // pin
if IsActive(&platform) {
klog.V(log.D).InfoS("Found active local build
platform", "platform", platform.Name)
return &platform, nil
@@ -141,14 +141,18 @@ func GetLocalPlatform(ctx context.Context, c ctrl.Reader,
namespace string, acti
klog.V(log.D).InfoS("Found local build platform", "platform",
res.Name)
return &res, nil
}
-
- klog.V(log.D).InfoS("Not found a local build platform")
- return nil,
k8serrors.NewNotFound(operatorapi.Resource("SonataFlowPlatform"),
DefaultPlatformName)
+ klog.V(log.I).InfoS("Not found a local build platform", "Namespace",
namespace)
+ klog.V(log.I).InfoS("Creating a default SonataFlowPlatform",
"Namespace", namespace)
+ sfp := newDefaultSonataFlowPlatform(namespace)
+ if err = c.Create(ctx, sfp); err != nil {
+ return nil, err
+ }
+ return sfp, nil
}
-// ListPrimaryPlatforms returns all non-secondary platforms installed in a
given namespace (only one will be active).
-func ListPrimaryPlatforms(ctx context.Context, c ctrl.Reader, namespace
string) (*operatorapi.SonataFlowPlatformList, error) {
- lst, err := ListAllPlatforms(ctx, c, namespace)
+// listPrimaryPlatforms returns all non-secondary platforms installed in a
given namespace (only one will be active).
+func listPrimaryPlatforms(ctx context.Context, c ctrl.Reader, namespace
string) (*operatorapi.SonataFlowPlatformList, error) {
+ lst, err := listAllPlatforms(ctx, c, namespace)
if err != nil {
return nil, err
}
@@ -163,8 +167,8 @@ func ListPrimaryPlatforms(ctx context.Context, c
ctrl.Reader, namespace string)
return filtered, nil
}
-// ListAllPlatforms returns all platforms installed in a given namespace.
-func ListAllPlatforms(ctx context.Context, c ctrl.Reader, namespace string)
(*operatorapi.SonataFlowPlatformList, error) {
+// listAllPlatforms returns all platforms installed in a given namespace.
+func listAllPlatforms(ctx context.Context, c ctrl.Reader, namespace string)
(*operatorapi.SonataFlowPlatformList, error) {
lst := operatorapi.NewSonataFlowPlatformList()
if err := c.List(ctx, &lst, ctrl.InNamespace(namespace)); err != nil {
return nil, err
@@ -191,7 +195,7 @@ func IsNamespaceLocked(ctx context.Context, c ctrl.Reader,
namespace string) (bo
return false, nil
}
- platforms, err := ListPrimaryPlatforms(ctx, c, namespace)
+ platforms, err := listPrimaryPlatforms(ctx, c, namespace)
if err != nil {
return true, err
}
diff --git a/controllers/platform/platformutils.go
b/controllers/platform/platformutils.go
index 020f8b9b..a5851a92 100644
--- a/controllers/platform/platformutils.go
+++ b/controllers/platform/platformutils.go
@@ -42,7 +42,7 @@ var builderDockerfileFromRE = regexp.MustCompile(`FROM (.*)
AS builder`)
// ResourceCustomizer can be used to inject code that changes the objects
before they are created.
type ResourceCustomizer func(object ctrl.Object) ctrl.Object
-func ConfigureRegistry(ctx context.Context, c client.Client, p
*operatorapi.SonataFlowPlatform, verbose bool) error {
+func configureRegistry(ctx context.Context, c client.Client, p
*operatorapi.SonataFlowPlatform, verbose bool) error {
if p.Spec.Build.Config.BuildStrategy ==
operatorapi.PlatformBuildStrategy && p.Status.Cluster ==
operatorapi.PlatformClusterOpenShift {
p.Spec.Build.Config.Registry = operatorapi.RegistrySpec{}
klog.V(log.D).InfoS("Platform registry not set and ignored on
openshift cluster")
@@ -63,7 +63,7 @@ func ConfigureRegistry(ctx context.Context, c client.Client,
p *operatorapi.Sona
return nil
}
-func SetPlatformDefaults(p *operatorapi.SonataFlowPlatform, verbose bool)
error {
+func setPlatformDefaults(p *operatorapi.SonataFlowPlatform, verbose bool)
error {
if p.Spec.Build.Config.BuildStrategyOptions == nil {
klog.V(log.D).InfoS("SonataFlow Platform: setting publish
strategy options", "namespace", p.Namespace)
p.Spec.Build.Config.BuildStrategyOptions = map[string]string{}
diff --git a/controllers/profiles/prod/states_prod.go
b/controllers/profiles/prod/states_prod.go
index ee5f3747..142f3cf8 100644
--- a/controllers/profiles/prod/states_prod.go
+++ b/controllers/profiles/prod/states_prod.go
@@ -91,7 +91,7 @@ func (h *followBuildStatusState) Do(ctx context.Context,
workflow *operatorapi.S
build, err := builder.NewSonataFlowBuildManager(ctx,
h.C).GetOrCreateBuild(workflow)
if err != nil {
klog.V(log.E).ErrorS(err, "Failed to get or create the build
for the workflow.")
- workflow.Status.Manager().MarkFalse(api.BuiltConditionType,
api.BuildFailedReason, build.Status.Error)
+ workflow.Status.Manager().MarkFalse(api.BuiltConditionType,
api.BuildFailedReason, err.Error())
if _, err = h.PerformStatusUpdate(ctx, workflow); err != nil {
return ctrl.Result{}, nil, err
}
@@ -110,10 +110,15 @@ func (h *followBuildStatusState) Do(ctx context.Context,
workflow *operatorapi.S
workflow.Status.Manager().MarkFalse(api.BuiltConditionType,
api.BuildFailedReason,
"Workflow %s build failed. Error: %s", workflow.Name,
build.Status.Error)
_, err = h.PerformStatusUpdate(ctx, workflow)
+ } else if build.Status.BuildPhase == operatorapi.BuildPhaseRunning &&
!workflow.Status.IsBuildRunning() {
+ workflow.Status.Manager().MarkFalse(api.BuiltConditionType,
api.BuildIsRunningReason, "")
+ _, err = h.PerformStatusUpdate(ctx, workflow)
}
+
if err != nil {
return ctrl.Result{}, nil, err
}
+
return ctrl.Result{RequeueAfter: requeueWhileWaitForBuild}, nil, nil
}
diff --git a/test/e2e/workflow_test.go b/test/e2e/workflow_test.go
index 0d02ec50..bba7e475 100644
--- a/test/e2e/workflow_test.go
+++ b/test/e2e/workflow_test.go
@@ -171,16 +171,6 @@ var _ = Describe("SonataFlow Operator", Ordered, func() {
Describe("ensure that Operator and Operand(s) can run in restricted
namespaces", func() {
projectDir, _ := utils.GetProjectDir()
- It("should create a basic platform for Minikube", func() {
- By("creating an instance of the SonataFlowPlatform")
- EventuallyWithOffset(1, func() error {
- cmd := exec.Command("kubectl", "apply", "-f",
filepath.Join(projectDir,
- getSonataFlowPlatformFilename()), "-n",
namespace)
- _, err := utils.Run(cmd)
- return err
- }, time.Minute, time.Second).Should(Succeed())
- })
-
It("should successfully deploy the Simple Workflow in prod ops
mode and verify if it's running", func() {
By("creating an instance of the SonataFlow Operand(CR)")
EventuallyWithOffset(1, func() error {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]