Skip to content

Commit

Permalink
Allow replicas to be configurable for executor, lookout ingester
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Parraga <[email protected]>
  • Loading branch information
Sovietaced committed Dec 19, 2024
1 parent 5504878 commit a1bc4ad
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
5 changes: 5 additions & 0 deletions internal/controller/install/executor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ func createExecutorDeployment(
config *builders.CommonApplicationConfig,
) *appsv1.Deployment {
var replicas int32 = 1

if executor.Spec.Replicas != nil {
replicas = min(replicas, *executor.Spec.Replicas) // Allow executor replicas to scale down to 0
}

volumes := createVolumes(executor.Name, executor.Spec.AdditionalVolumes)
volumeMounts := createVolumeMounts(GetConfigFilename(executor.Name), executor.Spec.AdditionalVolumeMounts)
readinessProbe, livenessProbe := CreateProbesWithScheme(corev1.URISchemeHTTP)
Expand Down
39 changes: 39 additions & 0 deletions internal/controller/install/executor_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ func TestExecutorReconciler_CreateDeployment(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{Namespace: "default", Name: "executor"},
Spec: installv1alpha1.ExecutorSpec{
Replicas: ptr.To[int32](2), // Max of 1 even if configured higher
CommonSpecBase: installv1alpha1.CommonSpecBase{
Labels: nil,
Image: installv1alpha1.Image{
Expand Down Expand Up @@ -563,3 +564,41 @@ func TestExecutorReconciler_CreateDeployment(t *testing.T) {
t.Fatalf("deployment is not the same %s", cmp.Diff(expectedDeployment, deployment, protocmp.Transform()))
}
}

func TestExecutorReconciler_CreateDeploymentScaledDown(t *testing.T) {
t.Parallel()

commonConfig := &builders.CommonApplicationConfig{
HTTPPort: 8080,
GRPCPort: 5051,
MetricsPort: 9000,
Profiling: builders.ProfilingConfig{
Port: 1337,
},
}

executor := &installv1alpha1.Executor{
TypeMeta: metav1.TypeMeta{
Kind: "Executor",
APIVersion: "install.armadaproject.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{Namespace: "default", Name: "executor"},
Spec: installv1alpha1.ExecutorSpec{
Replicas: ptr.To[int32](0),
CommonSpecBase: installv1alpha1.CommonSpecBase{
Labels: nil,
Image: installv1alpha1.Image{
Repository: "testrepo",
Tag: "1.0.0",
},
ApplicationConfig: runtime.RawExtension{},
Resources: &corev1.ResourceRequirements{},
Prometheus: &installv1alpha1.PrometheusConfig{Enabled: true, ScrapeInterval: &metav1.Duration{Duration: 1 * time.Second}},
},
},
}

deployment := createExecutorDeployment(executor, "executor", commonConfig)

assert.Equal(t, int32(0), *deployment.Spec.Replicas)
}
4 changes: 1 addition & 3 deletions internal/controller/install/lookoutingester_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ func (r *LookoutIngesterReconciler) createDeployment(
serviceAccountName string,
config *builders.CommonApplicationConfig,
) (*appsv1.Deployment, error) {
var replicas int32 = 1

env := createEnv(lookoutIngester.Spec.Environment)
pulsarConfig, err := ExtractPulsarConfig(lookoutIngester.Spec.ApplicationConfig)
if err != nil {
Expand All @@ -177,7 +175,7 @@ func (r *LookoutIngesterReconciler) createDeployment(
deployment := appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{Name: lookoutIngester.Name, Namespace: lookoutIngester.Namespace, Labels: AllLabels(lookoutIngester.Name, lookoutIngester.Labels)},
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
Replicas: lookoutIngester.Spec.Replicas,
Selector: &metav1.LabelSelector{
MatchLabels: IdentityLabel(lookoutIngester.Name),
},
Expand Down

0 comments on commit a1bc4ad

Please sign in to comment.