-
Notifications
You must be signed in to change notification settings - Fork 782
feat(deployment): Allow omitting replicas via null and support zero replicas #1452
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
base: master
Are you sure you want to change the base?
feat(deployment): Allow omitting replicas via null and support zero replicas #1452
Conversation
d2c2f42
to
78c0678
Compare
This comment was marked as outdated.
This comment was marked as outdated.
Thanks. It's missing a test when replicas is nullified. Instead of hiding it in this PR, wdyt about adding an EXAMPLE on this use case ? |
Thanks to comments!
Thanks for pointing that out! I've added the test case.
Good point. Unless I'm mistaken, my understanding is that the traefik-helm-chart/traefik/templates/hpa.yaml Lines 20 to 21 in 8873fd6
Additionally, this Helm chart is designed for the proxy workload to run as either a Deployment or a DaemonSet, so I believe there's little need to modify them.
That's a great suggestion, thank you! I'll work on adding an I'll start on the modifications now, so please give me a little time. |
When using [ArgoCD Rollouts](https://argoproj.github.io/rollouts/), one can delegate replica management to a `Rollout` resource, enabling progressive delivery strategies like canary and blue-green deployments. | ||
To do so, `replicas` should be set to `0` and the `Rollout` resource defined in `extraObjects`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a native English speaker, so I would appreciate it if you could point out any errors.
(Translate assisted with Gemini😇)
\o that's right. I opened #1453 in order to add this feature. |
I'm planning to add conditional logic based on scaleTargetRef.apiVersion and scaleTargetRef.kind, so I think it would be best for me to rebase after #1453 is merged first. It worked successfully after I applied this fix based on your code. apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: traefik-testing-with-rollouts
namespace: argocd
spec:
destination:
namespace: traefik-testing-with-rollouts
server: https://kubernetes.default.svc
source:
repoURL: https://github.com/na2na-p/traefik-helm-chart.git
targetRevision: feat/deployment-allow-zero-replicas-with-configuable-hpa
path: traefik
helm:
values: |-
deployment:
replicas: 0
autoscaling:
enabled: true
minReplicas: 5
maxReplicas: 50
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80
scaleTargetRef:
apiVersion: argoproj.io/v1alpha1
kind: Rollout
extraObjects:
- |
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: {{ template "traefik.fullname" . }}
spec:
workloadRef:
apiVersion: apps/v1
kind: Deployment
name: {{ template "traefik.fullname" . }}
strategy:
canary:
steps:
- setWeight: 10
- pause:
duration: 5m
project: default
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
- ServerSideApply=true
|
e363c82
to
ad742a7
Compare
deployment: | ||
replicas: 0 | ||
autoscaling: | ||
enabled: true | ||
minReplicas: 5 | ||
maxReplicas: 50 | ||
metrics: | ||
- type: Resource | ||
resource: | ||
name: cpu | ||
target: | ||
type: Utilization | ||
averageUtilization: 80 | ||
scaleTargetRef: | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Rollout | ||
extraObjects: | ||
- apiVersion: argoproj.io/v1alpha1 | ||
kind: Rollout | ||
metadata: | ||
name: "{{ template \"traefik.fullname\" . }}" | ||
spec: | ||
workloadRef: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
name: "{{ template \"traefik.fullname\" . }}" | ||
strategy: | ||
canary: | ||
steps: | ||
- setWeight: 10 | ||
- pause: | ||
duration: 5m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ad742a7
to
eabc5f8
Compare
This PR resolves #1451.
What does this PR do?
This pull request updates the logic for the
deployment.replicas
field to support two distinct, important use cases:replicas: null
to completely omit thereplicas
field from the renderedDeployment
manifest.replicas: 0
correctly rendersreplicas: 0
in the manifest.This is achieved by changing the rendering condition in
deployment.yaml
fromreplicas: {{ default 1 .Values.deployment.replicas }}
to use an explicit non-nil check:{{- if and (not .Values.autoscaling.enabled) (not (eq .Values.deployment.replicas nil)) }}
.Motivation
The primary motivation is to solve the problem described in #1451, where users need to delegate replica management to external controllers like Argo Rollouts. This requires omitting the
replicas
field from the chart's output.Following a discussion in the issue, we opted for a simpler approach of allowing
replicas: null
instead of introducing a newmanageReplicas
parameter. This PR implements that idea while also fixing a side effect wherereplicas: 0
would have been incorrectly ignored (as0
is falsy in Go templates).This solution provides the needed flexibility for modern GitOps patterns without adding new parameters and while maintaining backward compatibility.
More
make test
and all the tests passed