diff --git a/internal/controller/platform/k8s.go b/internal/controller/platform/k8s.go index b5c0bde18..5725c7463 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 bf448728e..6c9644add 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) }