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

Add support for HPA #1765

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
11 changes: 9 additions & 2 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@ If release name contains chart name it will be used as a full name.
{{- end }}
{{- end }}

{{/* Helm required labels: legacy */}}
{{- define "harbor.legacy.labels" -}}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
chart: {{ .Chart.Name }}
app: "{{ template "harbor.name" . }}"
{{- end -}}

{{/* Helm required labels */}}
{{- define "harbor.labels" -}}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
chart: {{ .Chart.Name }}
app: "{{ template "harbor.name" . }}"
{{ include "harbor.matchLabels" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/name: {{ include "harbor.name" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
Expand Down Expand Up @@ -571,4 +578,4 @@ app: "{{ template "harbor.name" . }}"
{{/* Allow KubeVersion to be overridden. */}}
{{- define "harbor.ingress.kubeVersion" -}}
{{- default .Capabilities.KubeVersion.Version .Values.expose.ingress.kubeVersionOverride -}}
{{- end -}}
{{- end -}}
2 changes: 2 additions & 0 deletions templates/core/core-dpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ metadata:
component: core
app.kubernetes.io/component: core
spec:
{{- if .Values.core.autoscaling.enabled }}
replicas: {{ .Values.core.replicas }}
{{- end }}
revisionHistoryLimit: {{ .Values.core.revisionHistoryLimit }}
selector:
matchLabels:
Expand Down
43 changes: 43 additions & 0 deletions templates/core/core-hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{- if .Values.core.autoscaling.enabled }}
apiVersion: {{ ternary "autoscaling/v2" "autoscaling/v2beta2" (.Capabilities.APIVersions.Has "autoscaling/v2") }}
kind: HorizontalPodAutoscaler
metadata:
{{- with .Values.core.autoscaling.annotations }}
annotations: {{ toYaml . | nindent 4 }}
{{- end }}
labels:
{{- include "harbor.labels" . | nindent 4 }}
app.kubernetes.io/component: core
name: {{ template "harbor.core" . }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ template "harbor.core" . }}
minReplicas: {{ .Values.core.autoscaling.minReplicas }}
maxReplicas: {{ .Values.core.autoscaling.maxReplicas }}
metrics:
{{- with .Values.core.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ . }}
{{- end }}
{{- with .Values.core.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ . }}
{{- end }}
{{- with .Values.core.autoscalingTemplate }}
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.core.autoscaling.behavior }}
behavior:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion templates/database/database-ss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ spec:
- metadata:
name: "database-data"
labels:
{{ include "harbor.labels" . | indent 8 }}
{{ include "harbor.legacy.labels" . | indent 8 }}
annotations:
{{- range $key, $value := $database.annotations }}
{{ $key }}: {{ $value | quote }}
Expand Down
2 changes: 2 additions & 0 deletions templates/exporter/exporter-dpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ metadata:
component: exporter
app.kubernetes.io/component: exporter
spec:
{{- if .Values.exporter.autoscaling.enabled }}
replicas: {{ .Values.exporter.replicas }}
{{- end }}
revisionHistoryLimit: {{ .Values.exporter.revisionHistoryLimit }}
selector:
matchLabels:
Expand Down
43 changes: 43 additions & 0 deletions templates/exporter/exporter-hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{- if .Values.exporter.autoscaling.enabled }}
apiVersion: {{ ternary "autoscaling/v2" "autoscaling/v2beta2" (.Capabilities.APIVersions.Has "autoscaling/v2") }}
kind: HorizontalPodAutoscaler
metadata:
{{- with .Values.exporter.autoscaling.annotations }}
annotations: {{ toYaml . | nindent 4 }}
{{- end }}
labels:
{{- include "harbor.labels" . | nindent 4 }}
app.kubernetes.io/component: exporter
name: {{ template "harbor.exporter" . }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ template "harbor.exporter" . }}
minReplicas: {{ .Values.exporter.autoscaling.minReplicas }}
maxReplicas: {{ .Values.exporter.autoscaling.maxReplicas }}
metrics:
{{- with .Values.exporter.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ . }}
{{- end }}
{{- with .Values.exporter.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ . }}
{{- end }}
{{- with .Values.exporter.autoscalingTemplate }}
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.exporter.autoscaling.behavior }}
behavior:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions templates/jobservice/jobservice-dpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ metadata:
component: jobservice
app.kubernetes.io/component: jobservice
spec:
{{- if .Values.jobservice.autoscaling.enabled }}
replicas: {{ .Values.jobservice.replicas }}
{{- end }}
revisionHistoryLimit: {{ .Values.jobservice.revisionHistoryLimit }}
strategy:
type: {{ .Values.updateStrategy.type }}
Expand Down
43 changes: 43 additions & 0 deletions templates/jobservice/jobservice-hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{- if .Values.jobservice.autoscaling.enabled }}
apiVersion: {{ ternary "autoscaling/v2" "autoscaling/v2beta2" (.Capabilities.APIVersions.Has "autoscaling/v2") }}
kind: HorizontalPodAutoscaler
metadata:
{{- with .Values.jobservice.autoscaling.annotations }}
annotations: {{ toYaml . | nindent 4 }}
{{- end }}
labels:
{{- include "harbor.labels" . | nindent 4 }}
app.kubernetes.io/component: jobservice
name: {{ template "harbor.jobservice" . }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ template "harbor.jobservice" . }}
minReplicas: {{ .Values.jobservice.autoscaling.minReplicas }}
maxReplicas: {{ .Values.jobservice.autoscaling.maxReplicas }}
metrics:
{{- with .Values.jobservice.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ . }}
{{- end }}
{{- with .Values.jobservice.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ . }}
{{- end }}
{{- with .Values.jobservice.autoscalingTemplate }}
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.jobservice.autoscaling.behavior }}
behavior:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions templates/portal/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ metadata:
component: portal
app.kubernetes.io/component: portal
spec:
{{- if .Values.portal.autoscaling.enabled }}
replicas: {{ .Values.portal.replicas }}
{{- end }}
revisionHistoryLimit: {{ .Values.portal.revisionHistoryLimit }}
selector:
matchLabels:
Expand Down
43 changes: 43 additions & 0 deletions templates/portal/portal-hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{- if .Values.portal.autoscaling.enabled }}
apiVersion: {{ ternary "autoscaling/v2" "autoscaling/v2beta2" (.Capabilities.APIVersions.Has "autoscaling/v2") }}
kind: HorizontalPodAutoscaler
metadata:
{{- with .Values.portal.autoscaling.annotations }}
annotations: {{ toYaml . | nindent 4 }}
{{- end }}
labels:
{{- include "harbor.labels" . | nindent 4 }}
app.kubernetes.io/component: portal
name: {{ template "harbor.portal" . }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ template "harbor.portal" . }}
minReplicas: {{ .Values.portal.autoscaling.minReplicas }}
maxReplicas: {{ .Values.portal.autoscaling.maxReplicas }}
metrics:
{{- with .Values.portal.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ . }}
{{- end }}
{{- with .Values.portal.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ . }}
{{- end }}
{{- with .Values.portal.autoscalingTemplate }}
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.portal.autoscaling.behavior }}
behavior:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion templates/redis/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ spec:
- metadata:
name: data
labels:
{{ include "harbor.labels" . | indent 8 }}
{{ include "harbor.legacy.labels" . | indent 8 }}
annotations:
{{- range $key, $value := $redis.annotations }}
{{ $key }}: {{ $value | quote }}
Expand Down
2 changes: 2 additions & 0 deletions templates/registry/registry-dpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ metadata:
component: registry
app.kubernetes.io/component: registry
spec:
{{- if .Values.registry.autoscaling.enabled }}
replicas: {{ .Values.registry.replicas }}
{{- end }}
revisionHistoryLimit: {{ .Values.registry.revisionHistoryLimit }}
strategy:
type: {{ .Values.updateStrategy.type }}
Expand Down
43 changes: 43 additions & 0 deletions templates/registry/registry-hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{- if .Values.registry.autoscaling.enabled }}
apiVersion: {{ ternary "autoscaling/v2" "autoscaling/v2beta2" (.Capabilities.APIVersions.Has "autoscaling/v2") }}
kind: HorizontalPodAutoscaler
metadata:
{{- with .Values.registry.autoscaling.annotations }}
annotations: {{ toYaml . | nindent 4 }}
{{- end }}
labels:
{{- include "harbor.labels" . | nindent 4 }}
app.kubernetes.io/component: registry
name: {{ template "harbor.registry" . }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ template "harbor.registry" . }}
minReplicas: {{ .Values.registry.autoscaling.minReplicas }}
maxReplicas: {{ .Values.registry.autoscaling.maxReplicas }}
metrics:
{{- with .Values.registry.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ . }}
{{- end }}
{{- with .Values.registry.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ . }}
{{- end }}
{{- with .Values.registry.autoscalingTemplate }}
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.registry.autoscaling.behavior }}
behavior:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
43 changes: 43 additions & 0 deletions templates/trivy/trivy-hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{- if .Values.trivy.autoscaling.enabled }}
apiVersion: {{ ternary "autoscaling/v2" "autoscaling/v2beta2" (.Capabilities.APIVersions.Has "autoscaling/v2") }}
kind: HorizontalPodAutoscaler
metadata:
{{- with .Values.trivy.autoscaling.annotations }}
annotations: {{ toYaml . | nindent 4 }}
{{- end }}
labels:
{{- include "harbor.labels" . | nindent 4 }}
app.kubernetes.io/component: trivy
name: {{ template "harbor.trivy" . }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: StatefulSet
name: {{ template "harbor.trivy" . }}
minReplicas: {{ .Values.trivy.autoscaling.minReplicas }}
maxReplicas: {{ .Values.trivy.autoscaling.maxReplicas }}
metrics:
{{- with .Values.trivy.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ . }}
{{- end }}
{{- with .Values.trivy.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ . }}
{{- end }}
{{- with .Values.trivy.autoscalingTemplate }}
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.trivy.autoscaling.behavior }}
behavior:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
4 changes: 3 additions & 1 deletion templates/trivy/trivy-sts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ metadata:
component: trivy
app.kubernetes.io/component: trivy
spec:
{{- if .Values.trivy.autoscaling.enabled }}
replicas: {{ .Values.trivy.replicas }}
{{- end }}
serviceName: {{ template "harbor.trivy" . }}
selector:
matchLabels:
Expand Down Expand Up @@ -205,7 +207,7 @@ spec:
- metadata:
name: data
labels:
{{ include "harbor.labels" . | indent 8 }}
{{ include "harbor.legacy.labels" . | indent 8 }}
annotations:
{{- range $key, $value := $trivy.annotations }}
{{ $key }}: {{ $value | quote }}
Expand Down
Loading
Loading