airflow icon indicating copy to clipboard operation
airflow copied to clipboard

Helm: Enabling Celery worker HPA renders an invalid minimum replica count

Open AdeshDeshmukh opened this issue 1 week ago • 4 comments

Under which category would you file this issue?

Helm chart

Apache Airflow version

3.2.2 (default image for Helm chart 1.22.0)

What happened and how to reproduce it?

Enabling the Celery worker HPA with the chart defaults renders minReplicas: 0 with a single CPU resource metric. Kubernetes requires at least one Object or External metric when the minimum is zero, so this HPA fails API validation.

helm template probe airflow \
  --repo https://airflow.apache.org \
  --version 1.22.0 \
  --set executor=CeleryExecutor \
  --set workers.celery.hpa.enabled=true \
  --show-only templates/workers/worker-hpa.yaml

The rendered HPA contains:

minReplicas: 0
maxReplicas: 5
metrics:
  - resource:
      name: cpu
      target:
        averageUtilization: 80
        type: Utilization
    type: Resource

I verified the rendered manifest locally. Kubernetes HPA API reference

What you think should happen instead?

Enabling the worker HPA with the default CPU metric should render a valid HPA. The default minimum should be one replica. An explicit minimum of zero should still be available for eligible Object or External metric configurations.

Operating System

macOS (Apple Silicon)

Deployment

Official Apache Airflow Helm Chart

Apache Airflow Provider(s)

No response

Versions of Apache Airflow Providers

No response

Official Helm Chart version

1.22.0 (latest released)

Kubernetes Version

Reproduced with Helm 3.19.0 using helm template. No Kubernetes cluster was used.

Helm Chart configuration

executor: CeleryExecutor

workers:
  celery:
    hpa:
      enabled: true

Docker Image customizations

None.

Anything else?

As a workaround, set workers.celery.hpa.minReplicaCount: 1. I verified that this renders minReplicas: 1 with the same CPU metric.

Are you willing to submit PR?

  • [x] Yes I am willing to submit a PR!

Code of Conduct

AdeshDeshmukh avatar Nov 27 '26 08:11 AdeshDeshmukh

Proposed solution after reviewing the reproducer:

  1. Change the chart’s default Celery worker HPA minimum from 0 to 1, so the default CPU-only metric configuration always renders a valid autoscaling/v2 HPA.
  2. Preserve an explicit minReplicas: 0 for advanced configurations, but validate/document that it is only valid when the HPA includes at least one Object or External metric, as required by Kubernetes.
  3. Add Helm rendering coverage for:
    • default HPA values -> minReplicas: 1 with the CPU metric;
    • explicit minReplicas: 0 plus an eligible Object/External metric;
    • explicit minReplicas: 0 with CPU-only metrics -> a clear chart validation error.

This keeps the common configuration valid while retaining scale-to-zero for configurations that satisfy the Kubernetes API constraint.

senapati484 avatar Nov 29 '26 13:11 senapati484

I implemented the proposed fix in PR #77744. It changes the default Celery worker HPA minimum to 1, documents the scale-to-zero constraint, and adds regression coverage for both the safe default and explicit zero replicas with an Object metric.

senapati484 avatar Nov 29 '26 14:11 senapati484

@senapati484 Thanks for looking into this. I was surprised to see #77744 because #77664 was already open for the same fix and waiting for review. Was there a gap in my PR that you wanted the separate patch to address..?

I would have appreciated a quick comment on #77664 before opening a second PR so we could compare approaches and avoid duplicating the work. Your note about when scale-to-zero is valid is helpful, and I’d be happy to incorporate it there so maintainers have one patch to review.

AdeshDeshmukh avatar Nov 29 '26 14:11 AdeshDeshmukh

You’re right—sorry, I missed #77664 when checking the issue. I opened #77744 based on the issue’s earlier state, but there’s no intentional difference between the two PRs.

I’ll close #77744 to avoid duplicate work. If useful, I can contribute the additional scale-to-zero documentation or test coverage directly to #77664 instead. Thanks for pointing this out.

senapati484 avatar Nov 29 '26 14:11 senapati484