Skip to content
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

feat: add hpa capabilites to helm-chart #151

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions deploy/charts/secrets-webhook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ The following table lists the configurable parameters of the Helm chart.
| `readinessProbe.periodSeconds` | int | `10` | |
| `readinessProbe.successThreshold` | int | `1` | |
| `readinessProbe.timeoutSeconds` | int | `1` | |
| `autoscaling.hpa.enabled` | bool | `true` | Enable autoscaling for the webhook deployment |
| `autoscaling.hpa.minReplicas` | int | `1` | |
| `autoscaling.hpa.maxReplicas` | int | `5` | |
| `autoscaling.hpa.targetCPU` | int | `80` | Target CPU utilization percentage |
| `autoscaling.hpa.targetMemory` | int | `80` | Target memory utilization percentage |
| `rbac.psp.enabled` | bool | `false` | Use pod security policy |
| `rbac.authDelegatorRole.enabled` | bool | `false` | Bind `system:auth-delegator` ClusterRoleBinding to given `serviceAccount` |
| `serviceAccount.create` | bool | `true` | Specifies whether a service account should be created |
Expand Down
47 changes: 47 additions & 0 deletions deploy/charts/secrets-webhook/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
{{/*
Return the target Kubernetes version
*/}}
{{- define "common.capabilities.kubeVersion" -}}
{{- default (default .Capabilities.KubeVersion.Version .Values.kubeVersion) ((.Values.global).kubeVersion) -}}
{{- end -}}

{{/*
Return the appropriate apiVersion for poddisruptionbudget.
*/}}
{{- define "common.capabilities.policy.apiVersion" -}}
{{- $kubeVersion := include "common.capabilities.kubeVersion" . -}}
{{- if and (not (empty $kubeVersion)) (semverCompare "<1.21-0" $kubeVersion) -}}
{{- print "policy/v1beta1" -}}
{{- else -}}
{{- print "policy/v1" -}}
{{- end -}}
{{- end -}}

{{/*
Return the appropriate apiVersion for deployment.
*/}}
{{- define "common.capabilities.deployment.apiVersion" -}}
{{- $kubeVersion := include "common.capabilities.kubeVersion" . -}}
{{- if and (not (empty $kubeVersion)) (semverCompare "<1.14-0" $kubeVersion) -}}
{{- print "extensions/v1beta1" -}}
{{- else -}}
{{- print "apps/v1" -}}
{{- end -}}
{{- end -}}

{{/*
Return the appropriate apiVersion for Horizontal Pod Autoscaler.
*/}}
{{- define "common.capabilities.hpa.apiVersion" -}}
{{- $kubeVersion := include "common.capabilities.kubeVersion" .context -}}
{{- if and (not (empty $kubeVersion)) (semverCompare "<1.23-0" $kubeVersion) -}}
{{- if .beta2 -}}
{{- print "autoscaling/v2beta2" -}}
{{- else -}}
{{- print "autoscaling/v2beta1" -}}
{{- end -}}
{{- else -}}
{{- print "autoscaling/v2" -}}
{{- end -}}
{{- end -}}

{{/*
Expand the name of the chart.
*/}}
Expand Down
36 changes: 36 additions & 0 deletions deploy/charts/secrets-webhook/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{{- if .Values.autoscaling.hpa.enabled }}
apiVersion: {{ include "common.capabilities.hpa.apiVersion" ( dict "context" $ ) }}
kind: HorizontalPodAutoscaler
metadata:
name: {{ template "secrets-webhook.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
chart: {{ include "secrets-webhook.chart" . }}
spec:
scaleTargetRef:
apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }}
kind: Deployment
name: {{ template "secrets-webhook.fullname" . }}
minReplicas: {{ .Values.autoscaling.hpa.minReplicas }}
maxReplicas: {{ .Values.autoscaling.hpa.maxReplicas }}
metrics:
{{- if .Values.autoscaling.hpa.targetCPU }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.hpa.targetCPU }}
{{- end }}
{{- if .Values.autoscaling.hpa.targetMemory }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.hpa.targetMemory }}
{{- end }}
{{- if .Values.autoscaling.hpa.customRules -}}
{{- toYaml .Values.autoscaling.hpa.customRules | nindent 4 }}
{{- end }}
{{- end }}
11 changes: 11 additions & 0 deletions deploy/charts/secrets-webhook/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,17 @@ readinessProbe:
successThreshold: 1
timeoutSeconds: 1

autoscaling:
hpa:
# -- Enable autoscaling for the webhook deployment
enabled: true
minReplicas: 1
maxReplicas: 5
# -- Target CPU utilization percentage
targetCPU: 80
# -- Target memory utilization percentage
targetMemory: 80

rbac:
psp:
# -- Use pod security policy
Expand Down
Loading