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 f59867c0 [KOGITO-9908] Fix reconciliation to always ensure prod 
objects (#284)
f59867c0 is described below

commit f59867c0da1a106a2c37de06943eb76ac96a2720
Author: Ricardo Zanini <[email protected]>
AuthorDate: Fri Oct 27 12:03:03 2023 -0300

    [KOGITO-9908] Fix reconciliation to always ensure prod objects (#284)
    
    * [KOGITO-9908] Fix reconciliation to always ensure prod objects
    
    Signed-off-by: Ricardo Zanini <[email protected]>
    
    * Merging podSpec from cluster, fix deployment checks
    
    Signed-off-by: Ricardo Zanini <[email protected]>
    
    ---------
    
    Signed-off-by: Ricardo Zanini <[email protected]>
---
 controllers/profiles/common/deployment.go          |  2 +-
 controllers/profiles/common/ensurer.go             |  4 +-
 controllers/profiles/common/mutate_visitors.go     | 15 ++--
 controllers/profiles/common/object_creators.go     | 10 ++-
 controllers/profiles/dev/profile_dev_test.go       | 18 ++---
 .../profiles/dev/status_enricher_dev_test.go       |  4 +-
 controllers/profiles/prod/deployment_handler.go    | 81 ++++++++--------------
 .../profiles/prod/deployment_handler_test.go       | 59 ++++++++++++++++
 controllers/profiles/prod/profile_prod_test.go     | 10 +--
 controllers/sonataflow_controller_test.go          |  2 +-
 controllers/sonataflowbuild_controller_test.go     |  4 +-
 controllers/sonataflowplatform_controller_test.go  |  2 +-
 test/kubernetes_cli.go                             |  4 +-
 test/yaml.go                                       |  1 +
 utils/kubernetes/naming_test.go                    | 27 ++++++++
 15 files changed, 158 insertions(+), 85 deletions(-)

diff --git a/controllers/profiles/common/deployment.go 
b/controllers/profiles/common/deployment.go
index 38b1c570..6563bd93 100644
--- a/controllers/profiles/common/deployment.go
+++ b/controllers/profiles/common/deployment.go
@@ -88,7 +88,7 @@ func (d deploymentHandler) SyncDeploymentStatus(ctx 
context.Context, workflow *o
 
        workflow.Status.Manager().MarkFalse(api.RunningConditionType, 
api.WaitingForDeploymentReason, "")
        klog.V(log.I).InfoS("Workflow is in WaitingForDeployment Condition")
-       return ctrl.Result{RequeueAfter: RequeueAfterFollowDeployment}, nil
+       return ctrl.Result{RequeueAfter: RequeueAfterFollowDeployment, Requeue: 
true}, nil
 }
 
 // GetDeploymentUnavailabilityMessage gets the replica failure reason.
diff --git a/controllers/profiles/common/ensurer.go 
b/controllers/profiles/common/ensurer.go
index fa5e74b5..4316e35c 100644
--- a/controllers/profiles/common/ensurer.go
+++ b/controllers/profiles/common/ensurer.go
@@ -17,10 +17,8 @@ package common
 import (
        "context"
 
-       "k8s.io/klog/v2"
-
        "github.com/apache/incubator-kie-kogito-serverless-operator/log"
-
+       "k8s.io/klog/v2"
        "sigs.k8s.io/controller-runtime/pkg/client"
        "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
 
diff --git a/controllers/profiles/common/mutate_visitors.go 
b/controllers/profiles/common/mutate_visitors.go
index 8f4df507..a07f6cb4 100644
--- a/controllers/profiles/common/mutate_visitors.go
+++ b/controllers/profiles/common/mutate_visitors.go
@@ -15,6 +15,7 @@
 package common
 
 import (
+       "github.com/imdario/mergo"
        appsv1 "k8s.io/api/apps/v1"
        corev1 "k8s.io/api/core/v1"
        "sigs.k8s.io/controller-runtime/pkg/client"
@@ -55,19 +56,25 @@ func DeploymentMutateVisitor(workflow 
*operatorapi.SonataFlow) MutateVisitor {
                        if err != nil {
                                return err
                        }
-                       EnsureDeployment(original.(*appsv1.Deployment), 
object.(*appsv1.Deployment))
-                       return nil
+                       return EnsureDeployment(original.(*appsv1.Deployment), 
object.(*appsv1.Deployment))
                }
        }
 }
 
 // EnsureDeployment Ensure that the original Deployment fields are immutable.
-func EnsureDeployment(original *appsv1.Deployment, object *appsv1.Deployment) {
+func EnsureDeployment(original *appsv1.Deployment, object *appsv1.Deployment) 
error {
        object.Spec.Replicas = original.Spec.Replicas
        object.Spec.Selector = original.Spec.Selector
        object.Labels = original.GetLabels()
 
-       object.Spec.Template.Spec = original.Spec.Template.Spec
+       // Clean up the volumes, they are inherited from original, additional 
are added by other visitors
+       object.Spec.Template.Spec.Volumes = nil
+       for i := range object.Spec.Template.Spec.Containers {
+               object.Spec.Template.Spec.Containers[i].VolumeMounts = nil
+       }
+
+       // we do a merge to not keep changing the spec since k8s will set 
default values to the podSpec
+       return mergo.Merge(&object.Spec.Template.Spec, 
original.Spec.Template.Spec, mergo.WithOverride)
 }
 
 func ServiceMutateVisitor(workflow *operatorapi.SonataFlow) MutateVisitor {
diff --git a/controllers/profiles/common/object_creators.go 
b/controllers/profiles/common/object_creators.go
index 1f22676b..7c95cebb 100644
--- a/controllers/profiles/common/object_creators.go
+++ b/controllers/profiles/common/object_creators.go
@@ -67,7 +67,7 @@ func DeploymentCreator(workflow *operatorapi.SonataFlow) 
(client.Object, error)
                        Labels:    lbl,
                },
                Spec: appsv1.DeploymentSpec{
-                       Replicas: workflow.Spec.PodTemplate.Replicas,
+                       Replicas: getReplicasOrDefault(workflow),
                        Selector: &metav1.LabelSelector{
                                MatchLabels: lbl,
                        },
@@ -93,6 +93,14 @@ func DeploymentCreator(workflow *operatorapi.SonataFlow) 
(client.Object, error)
        return deployment, nil
 }
 
+func getReplicasOrDefault(workflow *operatorapi.SonataFlow) *int32 {
+       var dReplicas int32 = 1
+       if workflow.Spec.PodTemplate.Replicas == nil {
+               return &dReplicas
+       }
+       return workflow.Spec.PodTemplate.Replicas
+}
+
 func defaultContainer(workflow *operatorapi.SonataFlow) (*corev1.Container, 
error) {
        defaultContainerPort := corev1.ContainerPort{
                ContainerPort: DefaultHTTPWorkflowPortInt,
diff --git a/controllers/profiles/dev/profile_dev_test.go 
b/controllers/profiles/dev/profile_dev_test.go
index d85453c3..97b2ea11 100644
--- a/controllers/profiles/dev/profile_dev_test.go
+++ b/controllers/profiles/dev/profile_dev_test.go
@@ -47,7 +47,7 @@ import (
 func Test_OverrideStartupProbe(t *testing.T) {
        workflow := test.GetBaseSonataFlow(t.Name())
 
-       client := 
test.NewKogitoClientBuilder().WithRuntimeObjects(workflow).WithStatusSubresource(workflow).Build()
+       client := 
test.NewSonataFlowClientBuilder().WithRuntimeObjects(workflow).WithStatusSubresource(workflow).Build()
 
        devReconciler := NewProfileReconciler(client)
 
@@ -74,7 +74,7 @@ func Test_recoverFromFailureNoDeployment(t *testing.T) {
        workflowID := clientruntime.ObjectKeyFromObject(workflow)
 
        workflow.Status.Manager().MarkFalse(api.RunningConditionType, 
api.DeploymentFailureReason, "")
-       client := 
test.NewKogitoClientBuilder().WithRuntimeObjects(workflow).WithStatusSubresource(workflow).Build()
+       client := 
test.NewSonataFlowClientBuilder().WithRuntimeObjects(workflow).WithStatusSubresource(workflow).Build()
 
        reconciler := NewProfileReconciler(client)
 
@@ -115,7 +115,7 @@ func Test_recoverFromFailureNoDeployment(t *testing.T) {
 func Test_newDevProfile(t *testing.T) {
        workflow := test.GetBaseSonataFlow(t.Name())
 
-       client := 
test.NewKogitoClientBuilder().WithRuntimeObjects(workflow).WithStatusSubresource(workflow).Build()
+       client := 
test.NewSonataFlowClientBuilder().WithRuntimeObjects(workflow).WithStatusSubresource(workflow).Build()
 
        devReconciler := NewProfileReconciler(client)
 
@@ -189,7 +189,7 @@ func Test_newDevProfile(t *testing.T) {
 
 func Test_devProfileImageDefaultsNoPlatform(t *testing.T) {
        workflow := test.GetBaseSonataFlowWithDevProfile(t.Name())
-       client := 
test.NewKogitoClientBuilder().WithRuntimeObjects(workflow).WithStatusSubresource(workflow).Build()
+       client := 
test.NewSonataFlowClientBuilder().WithRuntimeObjects(workflow).WithStatusSubresource(workflow).Build()
        devReconciler := NewProfileReconciler(client)
 
        result, err := devReconciler.Reconcile(context.TODO(), workflow)
@@ -206,7 +206,7 @@ func Test_devProfileWithImageSnapshotOverrideWithPlatform(t 
*testing.T) {
 
        platform := 
test.GetBasePlatformWithDevBaseImageInReadyPhase(workflow.Namespace)
 
-       client := test.NewKogitoClientBuilder().WithRuntimeObjects(workflow, 
platform).WithStatusSubresource(workflow, platform).Build()
+       client := 
test.NewSonataFlowClientBuilder().WithRuntimeObjects(workflow, 
platform).WithStatusSubresource(workflow, platform).Build()
        devReconciler := NewProfileReconciler(client)
 
        result, err := devReconciler.Reconcile(context.TODO(), workflow)
@@ -223,7 +223,7 @@ func 
Test_devProfileWithWPlatformWithoutDevBaseImageAndWithBaseImage(t *testing.
 
        platform := 
test.GetBasePlatformWithBaseImageInReadyPhase(workflow.Namespace)
 
-       client := test.NewKogitoClientBuilder().WithRuntimeObjects(workflow, 
platform).WithStatusSubresource(workflow, platform).Build()
+       client := 
test.NewSonataFlowClientBuilder().WithRuntimeObjects(workflow, 
platform).WithStatusSubresource(workflow, platform).Build()
        devReconciler := NewProfileReconciler(client)
 
        result, err := devReconciler.Reconcile(context.TODO(), workflow)
@@ -240,7 +240,7 @@ func 
Test_devProfileWithPlatformWithoutDevBaseImageAndWithoutBaseImage(t *testin
 
        platform := test.GetBasePlatformInReadyPhase(workflow.Namespace)
 
-       client := test.NewKogitoClientBuilder().WithRuntimeObjects(workflow, 
platform).WithStatusSubresource(workflow, platform).Build()
+       client := 
test.NewSonataFlowClientBuilder().WithRuntimeObjects(workflow, 
platform).WithStatusSubresource(workflow, platform).Build()
        devReconciler := NewProfileReconciler(client)
 
        result, err := devReconciler.Reconcile(context.TODO(), workflow)
@@ -258,7 +258,7 @@ func Test_newDevProfileWithExternalConfigMaps(t *testing.T) 
{
        workflow.Spec.Resources.ConfigMaps = 
append(workflow.Spec.Resources.ConfigMaps,
                operatorapi.ConfigMapWorkflowResource{ConfigMap: 
v1.LocalObjectReference{Name: configmapName}, WorkflowPath: "routes"})
 
-       client := 
test.NewKogitoClientBuilder().WithRuntimeObjects(workflow).WithStatusSubresource(workflow).Build()
+       client := 
test.NewSonataFlowClientBuilder().WithRuntimeObjects(workflow).WithStatusSubresource(workflow).Build()
 
        devReconciler := NewProfileReconciler(client)
 
@@ -374,7 +374,7 @@ func Test_VolumeWithCapitalizedPaths(t *testing.T) {
        configMap.Namespace = t.Name()
        workflow := 
test.GetSonataFlow(test.SonataFlowGreetingsWithStaticResourcesCR, t.Name())
 
-       client := test.NewKogitoClientBuilder().WithRuntimeObjects(workflow, 
configMap).WithStatusSubresource(workflow, configMap).Build()
+       client := 
test.NewSonataFlowClientBuilder().WithRuntimeObjects(workflow, 
configMap).WithStatusSubresource(workflow, configMap).Build()
 
        devReconciler := NewProfileReconciler(client)
 
diff --git a/controllers/profiles/dev/status_enricher_dev_test.go 
b/controllers/profiles/dev/status_enricher_dev_test.go
index a00ad09a..71406404 100644
--- a/controllers/profiles/dev/status_enricher_dev_test.go
+++ b/controllers/profiles/dev/status_enricher_dev_test.go
@@ -35,7 +35,7 @@ func Test_enrichmentStatusOnK8s(t *testing.T) {
                workflow := test.GetBaseSonataFlowWithDevProfile(t.Name())
                workflow.Namespace = toK8SNamespace(t.Name())
                service, err := common.ServiceCreator(workflow)
-               client := 
test.NewKogitoClientBuilder().WithRuntimeObjects(workflow, service).Build()
+               client := 
test.NewSonataFlowClientBuilder().WithRuntimeObjects(workflow, service).Build()
                obj, err := statusEnricher(context.TODO(), client, workflow)
 
                reflectWorkflow := obj.(*apiv08.SonataFlow)
@@ -51,7 +51,7 @@ func Test_enrichmentStatusOnK8s(t *testing.T) {
                workflow := test.GetBaseSonataFlowWithDevProfile(t.Name())
                workflow.Namespace = t.Name()
                service, err := serviceCreator(workflow)
-               client := 
test.NewKogitoClientBuilder().WithRuntimeObjects(workflow, service).Build()
+               client := 
test.NewSonataFlowClientBuilder().WithRuntimeObjects(workflow, service).Build()
                _, err = statusEnricher(context.TODO(), client, workflow)
                assert.Error(t, err)
 
diff --git a/controllers/profiles/prod/deployment_handler.go 
b/controllers/profiles/prod/deployment_handler.go
index 9ea412da..9a69334d 100644
--- a/controllers/profiles/prod/deployment_handler.go
+++ b/controllers/profiles/prod/deployment_handler.go
@@ -17,18 +17,15 @@ package prod
 import (
        "context"
 
-       appsv1 "k8s.io/api/apps/v1"
        v1 "k8s.io/api/core/v1"
-       "k8s.io/apimachinery/pkg/api/errors"
-       "k8s.io/klog/v2"
        ctrl "sigs.k8s.io/controller-runtime"
        "sigs.k8s.io/controller-runtime/pkg/client"
+       "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
        "sigs.k8s.io/controller-runtime/pkg/reconcile"
 
        "github.com/apache/incubator-kie-kogito-serverless-operator/api"
        operatorapi 
"github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08"
        
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles/common"
-       "github.com/apache/incubator-kie-kogito-serverless-operator/log"
        "github.com/apache/incubator-kie-kogito-serverless-operator/utils"
 )
 
@@ -56,69 +53,45 @@ func (d *deploymentHandler) handleWithImage(ctx 
context.Context, workflow *opera
                return ctrl.Result{}, nil, err
        }
 
-       // Check if this Deployment already exists
-       // TODO: we should NOT do this. The ensurers are there to do exactly 
this fetch. Review once we refactor this reconciliation algorithm. See 
https://issues.redhat.com/browse/KOGITO-8524
-       existingDeployment := &appsv1.Deployment{}
-       requeue := false
-       if err := d.C.Get(ctx, client.ObjectKeyFromObject(workflow), 
existingDeployment); err != nil {
-               if !errors.IsNotFound(err) {
-                       
workflow.Status.Manager().MarkFalse(api.RunningConditionType, 
api.DeploymentUnavailableReason, "Unable to verify if deployment is available 
due to ", err)
-                       _, err = d.PerformStatusUpdate(ctx, workflow)
-                       return reconcile.Result{Requeue: false}, nil, err
-               }
-               deployment, _, err :=
-                       d.ensurers.deployment.Ensure(
-                               ctx,
-                               workflow,
-                               d.getDeploymentMutateVisitors(workflow, image, 
propsCM.(*v1.ConfigMap))...,
-                       )
-               if err != nil {
-                       
workflow.Status.Manager().MarkFalse(api.RunningConditionType, 
api.DeploymentFailureReason, "Unable to perform the deploy due to ", err)
-                       _, err = d.PerformStatusUpdate(ctx, workflow)
-                       return reconcile.Result{}, nil, err
-               }
-               existingDeployment, _ = deployment.(*appsv1.Deployment)
-               requeue = true
+       deployment, deploymentOp, err :=
+               d.ensurers.deployment.Ensure(
+                       ctx,
+                       workflow,
+                       d.getDeploymentMutateVisitors(workflow, image, 
propsCM.(*v1.ConfigMap))...,
+               )
+       if err != nil {
+               workflow.Status.Manager().MarkFalse(api.RunningConditionType, 
api.DeploymentUnavailableReason, "Unable to perform the deploy due to ", err)
+               _, err = d.PerformStatusUpdate(ctx, workflow)
+               return reconcile.Result{}, nil, err
        }
-       // TODO: verify if deployment is ready. See 
https://issues.redhat.com/browse/KOGITO-8524
 
-       existingService := &v1.Service{}
-       if err := d.C.Get(ctx, client.ObjectKeyFromObject(workflow), 
existingService); err != nil {
-               if !errors.IsNotFound(err) {
-                       return reconcile.Result{Requeue: false}, nil, err
-               }
-               service, _, err := d.ensurers.service.Ensure(ctx, workflow, 
common.ServiceMutateVisitor(workflow))
-               if err != nil {
-                       
workflow.Status.Manager().MarkFalse(api.RunningConditionType, 
api.DeploymentUnavailableReason, "Unable to make the service available due to 
", err)
-                       _, err = d.PerformStatusUpdate(ctx, workflow)
-                       return reconcile.Result{}, nil, err
-               }
-               existingService, _ = service.(*v1.Service)
-               requeue = true
+       service, _, err := d.ensurers.service.Ensure(ctx, workflow, 
common.ServiceMutateVisitor(workflow))
+       if err != nil {
+               workflow.Status.Manager().MarkFalse(api.RunningConditionType, 
api.DeploymentUnavailableReason, "Unable to make the service available due to 
", err)
+               _, err = d.PerformStatusUpdate(ctx, workflow)
+               return reconcile.Result{}, nil, err
        }
-       // TODO: verify if service is ready. See 
https://issues.redhat.com/browse/KOGITO-8524
-
-       objs := []client.Object{existingDeployment, existingService, propsCM}
 
-       if !requeue {
-               klog.V(log.I).InfoS("Skip reconcile: Deployment and service 
already exists",
-                       "Deployment.Namespace", existingDeployment.Namespace, 
"Deployment.Name", existingDeployment.Name)
-               result, err := 
common.DeploymentHandler(d.C).SyncDeploymentStatus(ctx, workflow)
-               if err != nil {
-                       return reconcile.Result{Requeue: false}, nil, err
-               }
+       objs := []client.Object{deployment, service, propsCM}
 
+       if deploymentOp == controllerutil.OperationResultCreated {
+               workflow.Status.Manager().MarkFalse(api.RunningConditionType, 
api.WaitingForDeploymentReason, "")
                if _, err := d.PerformStatusUpdate(ctx, workflow); err != nil {
                        return reconcile.Result{Requeue: false}, nil, err
                }
-               return result, objs, nil
+               return reconcile.Result{RequeueAfter: 
common.RequeueAfterFollowDeployment, Requeue: true}, objs, nil
+       }
+
+       // Follow deployment status
+       result, err := common.DeploymentHandler(d.C).SyncDeploymentStatus(ctx, 
workflow)
+       if err != nil {
+               return reconcile.Result{Requeue: false}, nil, err
        }
 
-       workflow.Status.Manager().MarkFalse(api.RunningConditionType, 
api.WaitingForDeploymentReason, "")
        if _, err := d.PerformStatusUpdate(ctx, workflow); err != nil {
                return reconcile.Result{Requeue: false}, nil, err
        }
-       return reconcile.Result{RequeueAfter: 
common.RequeueAfterFollowDeployment}, objs, nil
+       return result, objs, nil
 }
 
 func (d *deploymentHandler) getDeploymentMutateVisitors(
diff --git a/controllers/profiles/prod/deployment_handler_test.go 
b/controllers/profiles/prod/deployment_handler_test.go
new file mode 100644
index 00000000..bde14159
--- /dev/null
+++ b/controllers/profiles/prod/deployment_handler_test.go
@@ -0,0 +1,59 @@
+// Copyright 2023 Red Hat, Inc. and/or its affiliates
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package prod
+
+import (
+       "context"
+       "testing"
+
+       
"github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08"
+       "github.com/apache/incubator-kie-kogito-serverless-operator/test"
+       "github.com/stretchr/testify/assert"
+       v1 "k8s.io/api/apps/v1"
+       utilruntime "k8s.io/apimachinery/pkg/util/runtime"
+)
+
+func Test_CheckPodTemplateChangesReflectDeployment(t *testing.T) {
+       workflow := test.GetBaseSonataFlowWithProdOpsProfile(t.Name())
+
+       client := test.NewSonataFlowClientBuilder().
+               WithRuntimeObjects(workflow).
+               WithStatusSubresource(workflow).
+               Build()
+       stateSupport := fakeReconcilerSupport(client)
+       handler := newDeploymentHandler(stateSupport, 
newObjectEnsurers(stateSupport))
+
+       result, objects, err := handler.handle(context.TODO(), workflow)
+       assert.NoError(t, err)
+       assert.NotEmpty(t, objects)
+       assert.True(t, result.Requeue)
+
+       // Second reconciliation, we do change the image and that must reflect 
the deployment
+       expectedImg := "quay.io/apache/my-new-workflow:1.0.0"
+       workflow.Spec.PodTemplate.Container.Image = expectedImg
+       utilruntime.Must(client.Update(context.TODO(), workflow))
+       result, objects, err = handler.handle(context.TODO(), workflow)
+       assert.NoError(t, err)
+       assert.NotEmpty(t, objects)
+       assert.True(t, result.Requeue)
+       for _, o := range objects {
+               if _, ok := o.(*v1.Deployment); ok {
+                       deployment := o.(*v1.Deployment)
+                       assert.Equal(t, expectedImg, 
deployment.Spec.Template.Spec.Containers[0].Image)
+                       assert.Equal(t, v1alpha08.DefaultContainerName, 
deployment.Spec.Template.Spec.Containers[0].Name)
+                       break
+               }
+       }
+}
diff --git a/controllers/profiles/prod/profile_prod_test.go 
b/controllers/profiles/prod/profile_prod_test.go
index 9b49c020..05cd5593 100644
--- a/controllers/profiles/prod/profile_prod_test.go
+++ b/controllers/profiles/prod/profile_prod_test.go
@@ -39,7 +39,7 @@ func Test_Reconciler_ProdOps(t *testing.T) {
                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().
+       client := test.NewSonataFlowClientBuilder().
                WithRuntimeObjects(workflow).
                WithStatusSubresource(workflow, 
&operatorapi.SonataFlowBuild{}).Build()
        result, err := 
NewProfileForOpsReconciler(client).Reconcile(context.TODO(), workflow)
@@ -78,7 +78,7 @@ func Test_Reconciler_ProdCustomPod(t *testing.T) {
        workflow.Status.Manager().MarkTrue(api.RunningConditionType)
        build := test.GetLocalSucceedSonataFlowBuild(workflow.Name, 
workflow.Namespace)
        platform := test.GetBasePlatformInReadyPhase(workflow.Namespace)
-       client := test.NewKogitoClientBuilder().
+       client := test.NewSonataFlowClientBuilder().
                WithRuntimeObjects(workflow, build, platform).
                WithStatusSubresource(workflow, build, platform).Build()
        _, err := NewProfileReconciler(client).Reconcile(context.TODO(), 
workflow)
@@ -98,7 +98,7 @@ func Test_Reconciler_ProdCustomPod(t *testing.T) {
 func Test_reconcilerProdBuildConditions(t *testing.T) {
        workflow := test.GetBaseSonataFlow(t.Name())
        platform := test.GetBasePlatformInReadyPhase(t.Name())
-       client := test.NewKogitoClientBuilder().
+       client := test.NewSonataFlowClientBuilder().
                WithRuntimeObjects(workflow, platform).
                WithStatusSubresource(workflow, platform, 
&operatorapi.SonataFlowBuild{}).Build()
 
@@ -159,7 +159,7 @@ func 
Test_deployWorkflowReconciliationHandler_handleObjects(t *testing.T) {
        workflow := test.GetBaseSonataFlow(t.Name())
        platform := test.GetBasePlatformInReadyPhase(t.Name())
        build := test.GetLocalSucceedSonataFlowBuild(workflow.Name, 
workflow.Namespace)
-       client := test.NewKogitoClientBuilder().
+       client := test.NewSonataFlowClientBuilder().
                WithRuntimeObjects(workflow, platform, build).
                WithStatusSubresource(workflow, platform, build).
                Build()
@@ -206,7 +206,7 @@ func Test_GenerationAnnotationCheck(t *testing.T) {
        // we load a workflow with metadata.generation to 0
        workflow := test.GetBaseSonataFlow(t.Name())
        platform := test.GetBasePlatformInReadyPhase(t.Name())
-       client := test.NewKogitoClientBuilder().
+       client := test.NewSonataFlowClientBuilder().
                WithRuntimeObjects(workflow, platform).
                WithStatusSubresource(workflow, platform, 
&operatorapi.SonataFlowBuild{}).Build()
 
diff --git a/controllers/sonataflow_controller_test.go 
b/controllers/sonataflow_controller_test.go
index 08b9fa4e..3907cfea 100644
--- a/controllers/sonataflow_controller_test.go
+++ b/controllers/sonataflow_controller_test.go
@@ -42,7 +42,7 @@ func TestSonataFlowController(t *testing.T) {
                objs := []runtime.Object{ksw, ksp}
 
                // Create a fake client to mock API calls.
-               cl := 
test.NewKogitoClientBuilder().WithRuntimeObjects(objs...).WithStatusSubresource(ksw,
 ksp).Build()
+               cl := 
test.NewSonataFlowClientBuilder().WithRuntimeObjects(objs...).WithStatusSubresource(ksw,
 ksp).Build()
                // Create a SonataFlowReconciler object with the scheme and 
fake client.
                r := &SonataFlowReconciler{Client: cl, Scheme: cl.Scheme()}
 
diff --git a/controllers/sonataflowbuild_controller_test.go 
b/controllers/sonataflowbuild_controller_test.go
index 6b2f3cf1..ccfab808 100644
--- a/controllers/sonataflowbuild_controller_test.go
+++ b/controllers/sonataflowbuild_controller_test.go
@@ -35,7 +35,7 @@ func TestSonataFlowBuildController(t *testing.T) {
        ksw := test.GetBaseSonataFlow(namespace)
        ksb := test.GetNewEmptySonataFlowBuild(ksw.Name, namespace)
 
-       cl := test.NewKogitoClientBuilder().
+       cl := test.NewSonataFlowClientBuilder().
                WithRuntimeObjects(ksb, ksw).
                WithRuntimeObjects(test.GetBasePlatformInReadyPhase(namespace)).
                WithRuntimeObjects(test.GetSonataFlowBuilderConfig(namespace)).
@@ -77,7 +77,7 @@ func TestSonataFlowBuildController_WithArgsAndEnv(t 
*testing.T) {
                Value: "extension1,extension2",
        }
 
-       cl := test.NewKogitoClientBuilder().
+       cl := test.NewSonataFlowClientBuilder().
                WithRuntimeObjects(ksb, ksw).
                WithRuntimeObjects(test.GetBasePlatformInReadyPhase(namespace)).
                WithRuntimeObjects(test.GetSonataFlowBuilderConfig(namespace)).
diff --git a/controllers/sonataflowplatform_controller_test.go 
b/controllers/sonataflowplatform_controller_test.go
index c6f48464..31741a4d 100644
--- a/controllers/sonataflowplatform_controller_test.go
+++ b/controllers/sonataflowplatform_controller_test.go
@@ -35,7 +35,7 @@ func TestSonataFlowPlatformController(t *testing.T) {
                ksp := test.GetBasePlatform()
 
                // Create a fake client to mock API calls.
-               cl := 
test.NewKogitoClientBuilder().WithRuntimeObjects(ksp).WithStatusSubresource(ksp).Build()
+               cl := 
test.NewSonataFlowClientBuilder().WithRuntimeObjects(ksp).WithStatusSubresource(ksp).Build()
                // Create a SonataFlowPlatformReconciler object with the scheme 
and fake client.
                r := &SonataFlowPlatformReconciler{cl, cl, cl.Scheme(), 
&rest.Config{}, &record.FakeRecorder{}}
 
diff --git a/test/kubernetes_cli.go b/test/kubernetes_cli.go
index 908ff5f5..c74ee6b8 100644
--- a/test/kubernetes_cli.go
+++ b/test/kubernetes_cli.go
@@ -33,8 +33,8 @@ import (
        operatorapi 
"github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08"
 )
 
-// NewKogitoClientBuilder creates a new fake.ClientBuilder with the right 
scheme references
-func NewKogitoClientBuilder() *fake.ClientBuilder {
+// NewSonataFlowClientBuilder creates a new fake.ClientBuilder with the right 
scheme references
+func NewSonataFlowClientBuilder() *fake.ClientBuilder {
        s := scheme.Scheme
        utilruntime.Must(operatorapi.AddToScheme(s))
        return fake.NewClientBuilder().WithScheme(s)
diff --git a/test/yaml.go b/test/yaml.go
index a1cbe11a..042d8400 100644
--- a/test/yaml.go
+++ b/test/yaml.go
@@ -171,6 +171,7 @@ func GetBaseSonataFlowWithProdProfile(namespace string) 
*operatorapi.SonataFlow
        return workflow
 }
 
+// GetBaseSonataFlowWithProdOpsProfile gets a base workflow that has a 
pre-built image set in podTemplate.
 func GetBaseSonataFlowWithProdOpsProfile(namespace string) 
*operatorapi.SonataFlow {
        workflow := GetSonataFlow(SonataFlowSimpleOpsYamlCR, namespace)
        return workflow
diff --git a/utils/kubernetes/naming_test.go b/utils/kubernetes/naming_test.go
new file mode 100644
index 00000000..4c2697f5
--- /dev/null
+++ b/utils/kubernetes/naming_test.go
@@ -0,0 +1,27 @@
+// Copyright 2023 Red Hat, Inc. and/or its affiliates
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package kubernetes
+
+import (
+       "testing"
+
+       "github.com/stretchr/testify/assert"
+)
+
+func TestMustSafeDNS1035_EnsureEquality(t *testing.T) {
+       s1 := MustSafeDNS1035("prefix-", "bananas")
+       s2 := MustSafeDNS1035("prefix-", "bananas")
+       assert.Equal(t, s1, s2)
+}


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

Reply via email to