This is an automated email from the ASF dual-hosted git repository.

wmedvedeo 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 ae7dde39 kie-kogito-serverless-operator-559: Add the ability to scale 
the Jobs Service to 0 (#563)
ae7dde39 is described below

commit ae7dde3987cd16f0540c7e2e92d2b4c7ca1ef4a0
Author: Walter Medvedeo <[email protected]>
AuthorDate: Thu Oct 31 18:54:39 2024 +0100

    kie-kogito-serverless-operator-559: Add the ability to scale the Jobs 
Service to 0 (#563)
---
 internal/controller/platform/k8s.go               |  4 ++++
 internal/controller/platform/services/services.go | 18 ++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/internal/controller/platform/k8s.go 
b/internal/controller/platform/k8s.go
index b5c0bde1..5725c746 100644
--- a/internal/controller/platform/k8s.go
+++ b/internal/controller/platform/k8s.go
@@ -159,6 +159,7 @@ func createOrUpdateDeployment(ctx context.Context, client 
client.Client, platfor
                        MatchLabels: selectorLbl,
                },
                Replicas: &replicas,
+               Strategy: psh.GetDeploymentStrategy(),
                Template: corev1.PodTemplateSpec{
                        ObjectMeta: metav1.ObjectMeta{
                                Labels: lbl,
@@ -200,6 +201,9 @@ func createOrUpdateDeployment(ctx context.Context, client 
client.Client, platfor
        if op, err := controllerutil.CreateOrUpdate(ctx, client, 
serviceDeployment, func() error {
                knative.SaveKnativeData(&serviceDeploymentSpec.Template.Spec, 
&serviceDeployment.Spec.Template.Spec)
                err := mergo.Merge(&(serviceDeployment.Spec), 
serviceDeploymentSpec, mergo.WithOverride)
+               // mergo.Merge algorithm is not setting the 
serviceDeployment.Spec.Replicas when the
+               // *serviceDeploymentSpec.Replicas is 0. Making impossible to 
scale to zero. Ensure the value.
+               serviceDeployment.Spec.Replicas = serviceDeploymentSpec.Replicas
                if err != nil {
                        return err
                }
diff --git a/internal/controller/platform/services/services.go 
b/internal/controller/platform/services/services.go
index bf448728..6c9644ad 100644
--- a/internal/controller/platform/services/services.go
+++ b/internal/controller/platform/services/services.go
@@ -22,6 +22,8 @@ package services
 import (
        "fmt"
 
+       appsv1 "k8s.io/api/apps/v1"
+
        
"github.com/apache/incubator-kie-kogito-serverless-operator/internal/controller/cfg"
        
"github.com/apache/incubator-kie-kogito-serverless-operator/internal/controller/knative"
        
"github.com/apache/incubator-kie-kogito-serverless-operator/internal/controller/profiles"
@@ -70,6 +72,8 @@ type PlatformServiceHandler interface {
        GetPodResourceRequirements() corev1.ResourceRequirements
        // GetReplicaCount Returns the default pod replica count for the given 
service
        GetReplicaCount() int32
+       // GetDeploymentStrategy Returns the deployment strategy for the service
+       GetDeploymentStrategy() appsv1.DeploymentStrategy
 
        // MergeContainerSpec performs a merge with override using the 
containerSpec argument and the expected values based on the service's pod 
template specifications. The returning
        // object is the merged result
@@ -255,6 +259,10 @@ func (d *DataIndexHandler) GetReplicaCount() int32 {
        return 1
 }
 
+func (d *DataIndexHandler) GetDeploymentStrategy() appsv1.DeploymentStrategy {
+       return appsv1.DeploymentStrategy{}
+}
+
 func (d *DataIndexHandler) GetServiceCmName() string {
        return fmt.Sprintf("%s-props", d.GetServiceName())
 }
@@ -383,9 +391,19 @@ func (j *JobServiceHandler) GetPodResourceRequirements() 
corev1.ResourceRequirem
 }
 
 func (j *JobServiceHandler) GetReplicaCount() int32 {
+       if j.platform.Spec.Services.JobService.PodTemplate.Replicas != nil && 
*j.platform.Spec.Services.JobService.PodTemplate.Replicas == 0 {
+               return 0
+       }
        return 1
 }
 
+func (j *JobServiceHandler) GetDeploymentStrategy() appsv1.DeploymentStrategy {
+       return appsv1.DeploymentStrategy{
+               Type:          appsv1.RecreateDeploymentStrategyType,
+               RollingUpdate: nil,
+       }
+}
+
 func (j JobServiceHandler) MergeContainerSpec(containerSpec *corev1.Container) 
(*corev1.Container, error) {
        return mergeContainerSpec(containerSpec, 
&j.platform.Spec.Services.JobService.PodTemplate.Container)
 }


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

Reply via email to