Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kie-kogito-serverless-operator-559: Add the ability to scale the Jobs Service to 0 #563

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/controller/platform/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down
18 changes: 18 additions & 0 deletions internal/controller/platform/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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)
}
Expand Down
Loading