diff --git a/internal/controller/install/executor_controller.go b/internal/controller/install/executor_controller.go index 3e79c0e..890c1d2 100644 --- a/internal/controller/install/executor_controller.go +++ b/internal/controller/install/executor_controller.go @@ -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) diff --git a/internal/controller/install/executor_controller_test.go b/internal/controller/install/executor_controller_test.go index 830d4ca..bcfcd82 100644 --- a/internal/controller/install/executor_controller_test.go +++ b/internal/controller/install/executor_controller_test.go @@ -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{ @@ -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) +} diff --git a/internal/controller/install/lookoutingester_controller.go b/internal/controller/install/lookoutingester_controller.go index b7973ed..8c6e394 100644 --- a/internal/controller/install/lookoutingester_controller.go +++ b/internal/controller/install/lookoutingester_controller.go @@ -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 { @@ -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), },