Skip to content

Commit 161ba4e

Browse files
authored
Allow replicas to be configurable for executor, lookout ingester (#345)
Signed-off-by: Jason Parraga <sovietaced@gmail.com>
1 parent 928a87b commit 161ba4e

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

internal/controller/install/executor_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ func createExecutorDeployment(
247247
config *builders.CommonApplicationConfig,
248248
) *appsv1.Deployment {
249249
var replicas int32 = 1
250+
251+
if executor.Spec.Replicas != nil {
252+
replicas = min(replicas, *executor.Spec.Replicas) // Allow executor replicas to scale down to 0
253+
}
254+
250255
volumes := createVolumes(executor.Name, executor.Spec.AdditionalVolumes)
251256
volumeMounts := createVolumeMounts(GetConfigFilename(executor.Name), executor.Spec.AdditionalVolumeMounts)
252257
readinessProbe, livenessProbe := CreateProbesWithScheme(corev1.URISchemeHTTP)

internal/controller/install/executor_controller_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ func TestExecutorReconciler_CreateDeployment(t *testing.T) {
421421
},
422422
ObjectMeta: metav1.ObjectMeta{Namespace: "default", Name: "executor"},
423423
Spec: installv1alpha1.ExecutorSpec{
424+
Replicas: ptr.To[int32](2), // Max of 1 even if configured higher
424425
CommonSpecBase: installv1alpha1.CommonSpecBase{
425426
Labels: nil,
426427
Image: installv1alpha1.Image{
@@ -563,3 +564,41 @@ func TestExecutorReconciler_CreateDeployment(t *testing.T) {
563564
t.Fatalf("deployment is not the same %s", cmp.Diff(expectedDeployment, deployment, protocmp.Transform()))
564565
}
565566
}
567+
568+
func TestExecutorReconciler_CreateDeploymentScaledDown(t *testing.T) {
569+
t.Parallel()
570+
571+
commonConfig := &builders.CommonApplicationConfig{
572+
HTTPPort: 8080,
573+
GRPCPort: 5051,
574+
MetricsPort: 9000,
575+
Profiling: builders.ProfilingConfig{
576+
Port: 1337,
577+
},
578+
}
579+
580+
executor := &installv1alpha1.Executor{
581+
TypeMeta: metav1.TypeMeta{
582+
Kind: "Executor",
583+
APIVersion: "install.armadaproject.io/v1alpha1",
584+
},
585+
ObjectMeta: metav1.ObjectMeta{Namespace: "default", Name: "executor"},
586+
Spec: installv1alpha1.ExecutorSpec{
587+
Replicas: ptr.To[int32](0),
588+
CommonSpecBase: installv1alpha1.CommonSpecBase{
589+
Labels: nil,
590+
Image: installv1alpha1.Image{
591+
Repository: "testrepo",
592+
Tag: "1.0.0",
593+
},
594+
ApplicationConfig: runtime.RawExtension{},
595+
Resources: &corev1.ResourceRequirements{},
596+
Prometheus: &installv1alpha1.PrometheusConfig{Enabled: true, ScrapeInterval: &metav1.Duration{Duration: 1 * time.Second}},
597+
},
598+
},
599+
}
600+
601+
deployment := createExecutorDeployment(executor, "executor", commonConfig)
602+
603+
assert.Equal(t, int32(0), *deployment.Spec.Replicas)
604+
}

internal/controller/install/lookoutingester_controller.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,6 @@ func (r *LookoutIngesterReconciler) createDeployment(
162162
serviceAccountName string,
163163
config *builders.CommonApplicationConfig,
164164
) (*appsv1.Deployment, error) {
165-
var replicas int32 = 1
166-
167165
env := createEnv(lookoutIngester.Spec.Environment)
168166
pulsarConfig, err := ExtractPulsarConfig(lookoutIngester.Spec.ApplicationConfig)
169167
if err != nil {
@@ -177,7 +175,7 @@ func (r *LookoutIngesterReconciler) createDeployment(
177175
deployment := appsv1.Deployment{
178176
ObjectMeta: metav1.ObjectMeta{Name: lookoutIngester.Name, Namespace: lookoutIngester.Namespace, Labels: AllLabels(lookoutIngester.Name, lookoutIngester.Labels)},
179177
Spec: appsv1.DeploymentSpec{
180-
Replicas: &replicas,
178+
Replicas: lookoutIngester.Spec.Replicas,
181179
Selector: &metav1.LabelSelector{
182180
MatchLabels: IdentityLabel(lookoutIngester.Name),
183181
},

0 commit comments

Comments
 (0)