From e4acc53fa5174fe401eafe830b1a137035348778 Mon Sep 17 00:00:00 2001 From: Joan Miquel Luque Oliver Date: Fri, 31 May 2024 10:05:02 +0200 Subject: [PATCH 1/8] Add support for Horizontal Pod Autoscaler Signed-off-by: Joan Miquel Luque Oliver --- templates/_helpers.tpl | 11 +- templates/core/core-dpl.yaml | 2 + templates/core/core-hpa.yaml | 43 ++++ templates/database/database-ss.yaml | 2 +- templates/exporter/exporter-dpl.yaml | 2 + templates/exporter/exporter-hpa.yaml | 43 ++++ templates/jobservice/jobservice-dpl.yaml | 2 + templates/jobservice/jobservice-hpa.yaml | 43 ++++ templates/portal/deployment.yaml | 2 + templates/portal/portal-hpa.yaml | 43 ++++ templates/redis/statefulset.yaml | 2 +- templates/registry/registry-dpl.yaml | 2 + templates/registry/registry-hpa.yaml | 43 ++++ templates/trivy/trivy-hpa.yaml | 43 ++++ templates/trivy/trivy-sts.yaml | 4 +- values.yaml | 254 +++++++++++++++++++++-- 16 files changed, 521 insertions(+), 20 deletions(-) create mode 100644 templates/core/core-hpa.yaml create mode 100644 templates/exporter/exporter-hpa.yaml create mode 100644 templates/jobservice/jobservice-hpa.yaml create mode 100644 templates/portal/portal-hpa.yaml create mode 100644 templates/registry/registry-hpa.yaml create mode 100644 templates/trivy/trivy-hpa.yaml diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 0914d5684..f6249b399 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -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 }} @@ -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 -}} \ No newline at end of file +{{- end -}} diff --git a/templates/core/core-dpl.yaml b/templates/core/core-dpl.yaml index e52e5f775..c01f51d4c 100644 --- a/templates/core/core-dpl.yaml +++ b/templates/core/core-dpl.yaml @@ -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: diff --git a/templates/core/core-hpa.yaml b/templates/core/core-hpa.yaml new file mode 100644 index 000000000..af9c9b3f9 --- /dev/null +++ b/templates/core/core-hpa.yaml @@ -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 }} \ No newline at end of file diff --git a/templates/database/database-ss.yaml b/templates/database/database-ss.yaml index dc6f962e1..8cf9cd928 100644 --- a/templates/database/database-ss.yaml +++ b/templates/database/database-ss.yaml @@ -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 }} diff --git a/templates/exporter/exporter-dpl.yaml b/templates/exporter/exporter-dpl.yaml index 01e9258ea..bfb0cab34 100644 --- a/templates/exporter/exporter-dpl.yaml +++ b/templates/exporter/exporter-dpl.yaml @@ -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: diff --git a/templates/exporter/exporter-hpa.yaml b/templates/exporter/exporter-hpa.yaml new file mode 100644 index 000000000..b999eaf80 --- /dev/null +++ b/templates/exporter/exporter-hpa.yaml @@ -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 }} \ No newline at end of file diff --git a/templates/jobservice/jobservice-dpl.yaml b/templates/jobservice/jobservice-dpl.yaml index 780d5e4ae..32929ca80 100644 --- a/templates/jobservice/jobservice-dpl.yaml +++ b/templates/jobservice/jobservice-dpl.yaml @@ -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 }} diff --git a/templates/jobservice/jobservice-hpa.yaml b/templates/jobservice/jobservice-hpa.yaml new file mode 100644 index 000000000..de0567589 --- /dev/null +++ b/templates/jobservice/jobservice-hpa.yaml @@ -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 }} \ No newline at end of file diff --git a/templates/portal/deployment.yaml b/templates/portal/deployment.yaml index 01d1e8575..ae1251360 100644 --- a/templates/portal/deployment.yaml +++ b/templates/portal/deployment.yaml @@ -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: diff --git a/templates/portal/portal-hpa.yaml b/templates/portal/portal-hpa.yaml new file mode 100644 index 000000000..7c320be80 --- /dev/null +++ b/templates/portal/portal-hpa.yaml @@ -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 }} \ No newline at end of file diff --git a/templates/redis/statefulset.yaml b/templates/redis/statefulset.yaml index 9573f9ad6..ed8f705a7 100644 --- a/templates/redis/statefulset.yaml +++ b/templates/redis/statefulset.yaml @@ -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 }} diff --git a/templates/registry/registry-dpl.yaml b/templates/registry/registry-dpl.yaml index bb9cb1dba..ee11abf5d 100644 --- a/templates/registry/registry-dpl.yaml +++ b/templates/registry/registry-dpl.yaml @@ -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 }} diff --git a/templates/registry/registry-hpa.yaml b/templates/registry/registry-hpa.yaml new file mode 100644 index 000000000..c803c08e1 --- /dev/null +++ b/templates/registry/registry-hpa.yaml @@ -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 }} \ No newline at end of file diff --git a/templates/trivy/trivy-hpa.yaml b/templates/trivy/trivy-hpa.yaml new file mode 100644 index 000000000..d773cbaf0 --- /dev/null +++ b/templates/trivy/trivy-hpa.yaml @@ -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 }} \ No newline at end of file diff --git a/templates/trivy/trivy-sts.yaml b/templates/trivy/trivy-sts.yaml index ddaa4c908..ae53e50fc 100644 --- a/templates/trivy/trivy-sts.yaml +++ b/templates/trivy/trivy-sts.yaml @@ -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: @@ -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 }} diff --git a/values.yaml b/values.yaml index 505d755aa..2b6715089 100644 --- a/values.yaml +++ b/values.yaml @@ -511,6 +511,38 @@ nginx: ## The priority class to run the pod as priorityClassName: + # Horizontal Pod Autoscaler + autoscaling: + enabled: false + annotations: {} + minReplicas: 1 + maxReplicas: 11 + targetCPUUtilizationPercentage: 50 + targetMemoryUtilizationPercentage: 50 + behavior: {} + # scaleDown: + # stabilizationWindowSeconds: 300 + # policies: + # - type: Pods + # value: 1 + # periodSeconds: 180 + # scaleUp: + # stabilizationWindowSeconds: 300 + # policies: + # - type: Pods + # value: 2 + # periodSeconds: 60 + autoscalingTemplate: [] + # Custom or additional autoscaling metrics + # ref: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-custom-metrics + # - type: Pods + # pods: + # metric: + # name: nginx_ingress_controller_nginx_process_requests_total + # target: + # type: AverageValue + # averageValue: 10000m + portal: image: repository: goharbor/harbor-portal @@ -544,6 +576,38 @@ portal: ## The priority class to run the pod as priorityClassName: + # Horizontal Pod Autoscaler + autoscaling: + enabled: false + annotations: {} + minReplicas: 1 + maxReplicas: 11 + targetCPUUtilizationPercentage: 50 + targetMemoryUtilizationPercentage: 50 + behavior: {} + # scaleDown: + # stabilizationWindowSeconds: 300 + # policies: + # - type: Pods + # value: 1 + # periodSeconds: 180 + # scaleUp: + # stabilizationWindowSeconds: 300 + # policies: + # - type: Pods + # value: 2 + # periodSeconds: 60 + autoscalingTemplate: [] + # Custom or additional autoscaling metrics + # ref: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-custom-metrics + # - type: Pods + # pods: + # metric: + # name: nginx_ingress_controller_nginx_process_requests_total + # target: + # type: AverageValue + # averageValue: 10000m + core: image: repository: goharbor/harbor-core @@ -608,21 +672,53 @@ core: # tokenKey and tokenCert must BOTH be set or BOTH unset. # The tokenKey value is formatted as a multiline string containing a PEM-encoded RSA key, indented one more than tokenKey on the following line. tokenKey: | - # If tokenKey is set, the value of tokenCert must be set as a PEM-encoded certificate signed by tokenKey, and supplied as a multiline string, indented one more than tokenCert on the following line. - tokenCert: | - # The XSRF key. Will be generated automatically if it isn't specified - xsrfKey: "" - # If using existingSecret, the key is defined by core.existingXsrfSecretKey - existingXsrfSecret: "" - # If using existingSecret, the key - existingXsrfSecretKey: CSRF_KEY - # The time duration for async update artifact pull_time and repository - # pull_count, the unit is second. Will be 10 seconds if it isn't set. - # eg. artifactPullAsyncFlushDuration: 10 - artifactPullAsyncFlushDuration: - gdpr: - deleteUser: false - auditLogsCompliant: false + # If tokenKey is set, the value of tokenCert must be set as a PEM-encoded certificate signed by tokenKey, and supplied as a multiline string, indented one more than tokenCert on the following line. + tokenCert: | + # The XSRF key. Will be generated automatically if it isn't specified + xsrfKey: "" + # If using existingSecret, the key is defined by core.existingXsrfSecretKey + existingXsrfSecret: "" + # If using existingSecret, the key + existingXsrfSecretKey: CSRF_KEY + # The time duration for async update artifact pull_time and repository + # pull_count, the unit is second. Will be 10 seconds if it isn't set. + # eg. artifactPullAsyncFlushDuration: 10 + artifactPullAsyncFlushDuration: + gdpr: + deleteUser: false + auditLogsCompliant: false + + # Horizontal Pod Autoscaler + autoscaling: + enabled: false + annotations: {} + minReplicas: 1 + maxReplicas: 11 + targetCPUUtilizationPercentage: 50 + targetMemoryUtilizationPercentage: 50 + behavior: {} + # scaleDown: + # stabilizationWindowSeconds: 300 + # policies: + # - type: Pods + # value: 1 + # periodSeconds: 180 + # scaleUp: + # stabilizationWindowSeconds: 300 + # policies: + # - type: Pods + # value: 2 + # periodSeconds: 60 + autoscalingTemplate: [] + # Custom or additional autoscaling metrics + # ref: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-custom-metrics + # - type: Pods + # pods: + # metric: + # name: nginx_ingress_controller_nginx_process_requests_total + # target: + # type: AverageValue + # averageValue: 10000m jobservice: image: @@ -679,6 +775,38 @@ jobservice: # Key within the existing secret for the job service secret existingSecretKey: JOBSERVICE_SECRET + # Horizontal Pod Autoscaler + autoscaling: + enabled: false + annotations: {} + minReplicas: 1 + maxReplicas: 11 + targetCPUUtilizationPercentage: 50 + targetMemoryUtilizationPercentage: 50 + behavior: {} + # scaleDown: + # stabilizationWindowSeconds: 300 + # policies: + # - type: Pods + # value: 1 + # periodSeconds: 180 + # scaleUp: + # stabilizationWindowSeconds: 300 + # policies: + # - type: Pods + # value: 2 + # periodSeconds: 60 + autoscalingTemplate: [] + # Custom or additional autoscaling metrics + # ref: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-custom-metrics + # - type: Pods + # pods: + # metric: + # name: nginx_ingress_controller_nginx_process_requests_total + # target: + # type: AverageValue + # averageValue: 10000m + registry: registry: image: @@ -759,6 +887,38 @@ registry: interval: 24h dryrun: false + # Horizontal Pod Autoscaler + autoscaling: + enabled: false + annotations: {} + minReplicas: 1 + maxReplicas: 11 + targetCPUUtilizationPercentage: 50 + targetMemoryUtilizationPercentage: 50 + behavior: {} + # scaleDown: + # stabilizationWindowSeconds: 300 + # policies: + # - type: Pods + # value: 1 + # periodSeconds: 180 + # scaleUp: + # stabilizationWindowSeconds: 300 + # policies: + # - type: Pods + # value: 2 + # periodSeconds: 60 + autoscalingTemplate: [] + # Custom or additional autoscaling metrics + # ref: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-custom-metrics + # - type: Pods + # pods: + # metric: + # name: nginx_ingress_controller_nginx_process_requests_total + # target: + # type: AverageValue + # averageValue: 10000m + trivy: # enabled the flag to enable Trivy scanner enabled: true @@ -845,6 +1005,38 @@ trivy: # The duration to wait for scan completion timeout: 5m0s + # Horizontal Pod Autoscaler + autoscaling: + enabled: false + annotations: {} + minReplicas: 1 + maxReplicas: 11 + targetCPUUtilizationPercentage: 50 + targetMemoryUtilizationPercentage: 50 + behavior: {} + # scaleDown: + # stabilizationWindowSeconds: 300 + # policies: + # - type: Pods + # value: 1 + # periodSeconds: 180 + # scaleUp: + # stabilizationWindowSeconds: 300 + # policies: + # - type: Pods + # value: 2 + # periodSeconds: 60 + autoscalingTemplate: [] + # Custom or additional autoscaling metrics + # ref: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-custom-metrics + # - type: Pods + # pods: + # metric: + # name: nginx_ingress_controller_nginx_process_requests_total + # target: + # type: AverageValue + # averageValue: 10000m + database: # if external database is used, set "type" to "external" # and fill the connection information in "external" section @@ -1007,3 +1199,35 @@ exporter: # whenUnsatisfiable: DoNotSchedule cacheDuration: 23 cacheCleanInterval: 14400 + + # Horizxonal Pod Autoscaler + autoscaling: + enabled: false + annotations: {} + minReplicas: 1 + maxReplicas: 11 + targetCPUUtilizationPercentage: 50 + targetMemoryUtilizationPercentage: 50 + behavior: {} + # scaleDown: + # stabilizationWindowSeconds: 300 + # policies: + # - type: Pods + # value: 1 + # periodSeconds: 180 + # scaleUp: + # stabilizationWindowSeconds: 300 + # policies: + # - type: Pods + # value: 2 + # periodSeconds: 60 + autoscalingTemplate: [] + # Custom or additional autoscaling metrics + # ref: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-custom-metrics + # - type: Pods + # pods: + # metric: + # name: nginx_ingress_controller_nginx_process_requests_total + # target: + # type: AverageValue + # averageValue: 10000m From ceece9601f2af1a5385687188c2520b2b5438c4c Mon Sep 17 00:00:00 2001 From: Shengwen Yu Date: Mon, 22 Apr 2024 18:46:23 +0800 Subject: [PATCH 2/8] feat: update images and tags for FC testing Signed-off-by: Shengwen Yu Signed-off-by: Joan Miquel Luque Oliver --- Chart.yaml | 4 ++-- values.yaml | 40 ++++++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Chart.yaml b/Chart.yaml index 59edf1fcd..3daffb820 100644 --- a/Chart.yaml +++ b/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v1 name: harbor -version: 1.4.0-dev -appVersion: dev +version: 1.15.0 +appVersion: 2.11.0-fc description: An open source trusted cloud native registry that stores, signs, and scans content keywords: - docker diff --git a/values.yaml b/values.yaml index 2b6715089..4488248d5 100644 --- a/values.yaml +++ b/values.yaml @@ -482,8 +482,8 @@ containerSecurityContext: # If service exposed via "ingress", the Nginx will not be used nginx: image: - repository: goharbor/nginx-photon - tag: dev + repository: zigzag18/nginx-photon + tag: v2.11.0-build.2621 # set the service account to be used, default if left empty serviceAccountName: "" # mount the service account token @@ -545,8 +545,8 @@ nginx: portal: image: - repository: goharbor/harbor-portal - tag: dev + repository: zigzag18/harbor-portal + tag: v2.11.0-build.2621 # set the service account to be used, default if left empty serviceAccountName: "" # mount the service account token @@ -610,8 +610,8 @@ portal: core: image: - repository: goharbor/harbor-core - tag: dev + repository: zigzag18/harbor-core + tag: v2.11.0-build.2621 # set the service account to be used, default if left empty serviceAccountName: "" # mount the service account token @@ -722,8 +722,8 @@ core: jobservice: image: - repository: goharbor/harbor-jobservice - tag: dev + repository: zigzag18/harbor-jobservice + tag: v2.11.0-build.2621 # set the service account to be used, default if left empty serviceAccountName: "" # mount the service account token @@ -810,8 +810,8 @@ jobservice: registry: registry: image: - repository: goharbor/registry-photon - tag: dev + repository: zigzag18/registry-photon + tag: v2.11.0-build.2621 # resources: # requests: # memory: 256Mi @@ -819,8 +819,8 @@ registry: extraEnvVars: [] controller: image: - repository: goharbor/harbor-registryctl - tag: dev + repository: zigzag18/harbor-registryctl + tag: v2.11.0-build.2621 # resources: # requests: # memory: 256Mi @@ -924,9 +924,9 @@ trivy: enabled: true image: # repository the repository for Trivy adapter image - repository: goharbor/trivy-adapter-photon + repository: zigzag18/trivy-adapter-photon # tag the tag for Trivy adapter image - tag: dev + tag: v2.11.0-build.2621 # set the service account to be used, default if left empty serviceAccountName: "" # mount the service account token @@ -1043,8 +1043,8 @@ database: type: internal internal: image: - repository: goharbor/harbor-db - tag: dev + repository: zigzag18/harbor-db + tag: v2.11.0-build.2621 # set the service account to be used, default if left empty serviceAccountName: "" # mount the service account token @@ -1116,8 +1116,8 @@ redis: type: internal internal: image: - repository: goharbor/redis-photon - tag: dev + repository: zigzag18/redis-photon + tag: v2.11.0-build.2621 # set the service account to be used, default if left empty serviceAccountName: "" # mount the service account token @@ -1171,8 +1171,8 @@ redis: exporter: image: - repository: goharbor/harbor-exporter - tag: dev + repository: zigzag18/harbor-exporter + tag: v2.11.0-build.2621 serviceAccountName: "" # mount the service account token automountServiceAccountToken: false From eb69aaae966a217ee40949f68a5cbe30150b26ab Mon Sep 17 00:00:00 2001 From: Shengwen Yu Date: Wed, 24 Apr 2024 08:51:14 +0000 Subject: [PATCH 3/8] fix: add "harbor.legacy.labels" to resolve the upgrade issue 1747 Signed-off-by: Shengwen Yu Signed-off-by: Joan Miquel Luque Oliver --- Chart.yaml | 4 ++-- values.yaml | 40 ++++++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Chart.yaml b/Chart.yaml index 3daffb820..59edf1fcd 100644 --- a/Chart.yaml +++ b/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v1 name: harbor -version: 1.15.0 -appVersion: 2.11.0-fc +version: 1.4.0-dev +appVersion: dev description: An open source trusted cloud native registry that stores, signs, and scans content keywords: - docker diff --git a/values.yaml b/values.yaml index 4488248d5..2b6715089 100644 --- a/values.yaml +++ b/values.yaml @@ -482,8 +482,8 @@ containerSecurityContext: # If service exposed via "ingress", the Nginx will not be used nginx: image: - repository: zigzag18/nginx-photon - tag: v2.11.0-build.2621 + repository: goharbor/nginx-photon + tag: dev # set the service account to be used, default if left empty serviceAccountName: "" # mount the service account token @@ -545,8 +545,8 @@ nginx: portal: image: - repository: zigzag18/harbor-portal - tag: v2.11.0-build.2621 + repository: goharbor/harbor-portal + tag: dev # set the service account to be used, default if left empty serviceAccountName: "" # mount the service account token @@ -610,8 +610,8 @@ portal: core: image: - repository: zigzag18/harbor-core - tag: v2.11.0-build.2621 + repository: goharbor/harbor-core + tag: dev # set the service account to be used, default if left empty serviceAccountName: "" # mount the service account token @@ -722,8 +722,8 @@ core: jobservice: image: - repository: zigzag18/harbor-jobservice - tag: v2.11.0-build.2621 + repository: goharbor/harbor-jobservice + tag: dev # set the service account to be used, default if left empty serviceAccountName: "" # mount the service account token @@ -810,8 +810,8 @@ jobservice: registry: registry: image: - repository: zigzag18/registry-photon - tag: v2.11.0-build.2621 + repository: goharbor/registry-photon + tag: dev # resources: # requests: # memory: 256Mi @@ -819,8 +819,8 @@ registry: extraEnvVars: [] controller: image: - repository: zigzag18/harbor-registryctl - tag: v2.11.0-build.2621 + repository: goharbor/harbor-registryctl + tag: dev # resources: # requests: # memory: 256Mi @@ -924,9 +924,9 @@ trivy: enabled: true image: # repository the repository for Trivy adapter image - repository: zigzag18/trivy-adapter-photon + repository: goharbor/trivy-adapter-photon # tag the tag for Trivy adapter image - tag: v2.11.0-build.2621 + tag: dev # set the service account to be used, default if left empty serviceAccountName: "" # mount the service account token @@ -1043,8 +1043,8 @@ database: type: internal internal: image: - repository: zigzag18/harbor-db - tag: v2.11.0-build.2621 + repository: goharbor/harbor-db + tag: dev # set the service account to be used, default if left empty serviceAccountName: "" # mount the service account token @@ -1116,8 +1116,8 @@ redis: type: internal internal: image: - repository: zigzag18/redis-photon - tag: v2.11.0-build.2621 + repository: goharbor/redis-photon + tag: dev # set the service account to be used, default if left empty serviceAccountName: "" # mount the service account token @@ -1171,8 +1171,8 @@ redis: exporter: image: - repository: zigzag18/harbor-exporter - tag: v2.11.0-build.2621 + repository: goharbor/harbor-exporter + tag: dev serviceAccountName: "" # mount the service account token automountServiceAccountToken: false From 1952cc0cdcd38cb8fb87db5aa81ce7b59c9e5496 Mon Sep 17 00:00:00 2001 From: Joan Miquel Luque Oliver Date: Fri, 31 May 2024 10:07:43 +0200 Subject: [PATCH 4/8] Fix indentation in if sentence Signed-off-by: Joan Miquel Luque Oliver --- templates/exporter/exporter-dpl.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/exporter/exporter-dpl.yaml b/templates/exporter/exporter-dpl.yaml index bfb0cab34..a4e5fa21f 100644 --- a/templates/exporter/exporter-dpl.yaml +++ b/templates/exporter/exporter-dpl.yaml @@ -8,7 +8,7 @@ metadata: component: exporter app.kubernetes.io/component: exporter spec: - {{- if .Values.exporter.autoscaling.enabled }} + {{- if .Values.exporter.autoscaling.enabled }} replicas: {{ .Values.exporter.replicas }} {{- end }} revisionHistoryLimit: {{ .Values.exporter.revisionHistoryLimit }} From a7810aabaca8a0d1400acc3e5408e0473351e4ec Mon Sep 17 00:00:00 2001 From: Joan Miquel Luque Oliver Date: Fri, 31 May 2024 10:33:09 +0200 Subject: [PATCH 5/8] Move Autoscaling section on core values Signed-off-by: Joan Miquel Luque Oliver --- values.yaml | 67 ++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/values.yaml b/values.yaml index 2b6715089..1bf1437b4 100644 --- a/values.yaml +++ b/values.yaml @@ -654,40 +654,6 @@ core: # suggest switch provider to redis if you were ran into the db connections spike around # the scenario of high concurrent pushing to same project, no improvment for other scenes. quotaUpdateProvider: db # Or redis - # Secret is used when core server communicates with other components. - # If a secret key is not specified, Helm will generate one. Alternatively set existingSecret to use an existing secret - # Must be a string of 16 chars. - secret: "" - # Fill in the name of a kubernetes secret if you want to use your own - # If using existingSecret, the key must be secret - existingSecret: "" - # Fill the name of a kubernetes secret if you want to use your own - # TLS certificate and private key for token encryption/decryption. - # The secret must contain keys named: - # "tls.key" - the private key - # "tls.crt" - the certificate - secretName: "" - # If not specifying a preexisting secret, a secret can be created from tokenKey and tokenCert and used instead. - # If none of secretName, tokenKey, and tokenCert are specified, an ephemeral key and certificate will be autogenerated. - # tokenKey and tokenCert must BOTH be set or BOTH unset. - # The tokenKey value is formatted as a multiline string containing a PEM-encoded RSA key, indented one more than tokenKey on the following line. - tokenKey: | - # If tokenKey is set, the value of tokenCert must be set as a PEM-encoded certificate signed by tokenKey, and supplied as a multiline string, indented one more than tokenCert on the following line. - tokenCert: | - # The XSRF key. Will be generated automatically if it isn't specified - xsrfKey: "" - # If using existingSecret, the key is defined by core.existingXsrfSecretKey - existingXsrfSecret: "" - # If using existingSecret, the key - existingXsrfSecretKey: CSRF_KEY - # The time duration for async update artifact pull_time and repository - # pull_count, the unit is second. Will be 10 seconds if it isn't set. - # eg. artifactPullAsyncFlushDuration: 10 - artifactPullAsyncFlushDuration: - gdpr: - deleteUser: false - auditLogsCompliant: false - # Horizontal Pod Autoscaler autoscaling: enabled: false @@ -719,6 +685,39 @@ core: # target: # type: AverageValue # averageValue: 10000m + # Secret is used when core server communicates with other components. + # If a secret key is not specified, Helm will generate one. Alternatively set existingSecret to use an existing secret + # Must be a string of 16 chars. + secret: "" + # Fill in the name of a kubernetes secret if you want to use your own + # If using existingSecret, the key must be secret + existingSecret: "" + # Fill the name of a kubernetes secret if you want to use your own + # TLS certificate and private key for token encryption/decryption. + # The secret must contain keys named: + # "tls.key" - the private key + # "tls.crt" - the certificate + secretName: "" + # If not specifying a preexisting secret, a secret can be created from tokenKey and tokenCert and used instead. + # If none of secretName, tokenKey, and tokenCert are specified, an ephemeral key and certificate will be autogenerated. + # tokenKey and tokenCert must BOTH be set or BOTH unset. + # The tokenKey value is formatted as a multiline string containing a PEM-encoded RSA key, indented one more than tokenKey on the following line. + tokenKey: | + # If tokenKey is set, the value of tokenCert must be set as a PEM-encoded certificate signed by tokenKey, and supplied as a multiline string, indented one more than tokenCert on the following line. + tokenCert: | + # The XSRF key. Will be generated automatically if it isn't specified + xsrfKey: "" + # If using existingSecret, the key is defined by core.existingXsrfSecretKey + existingXsrfSecret: "" + # If using existingSecret, the key + existingXsrfSecretKey: CSRF_KEY + # The time duration for async update artifact pull_time and repository + # pull_count, the unit is second. Will be 10 seconds if it isn't set. + # eg. artifactPullAsyncFlushDuration: 10 + artifactPullAsyncFlushDuration: + gdpr: + deleteUser: false + auditLogsCompliant: false jobservice: image: From 7c3afc520b839382c2848af52dc147106dc28584 Mon Sep 17 00:00:00 2001 From: Carlos Vega Date: Tue, 17 Dec 2024 10:28:32 +0100 Subject: [PATCH 6/8] Fixed tests for HPA Signed-off-by: Carlos Vega --- templates/core/core-dpl.yaml | 2 +- templates/exporter/exporter-dpl.yaml | 2 +- templates/jobservice/jobservice-dpl.yaml | 2 +- templates/portal/deployment.yaml | 2 +- templates/registry/registry-dpl.yaml | 2 +- templates/trivy/trivy-sts.yaml | 2 +- test/unittest/core_deployment_test.yaml | 22 +++ test/unittest/core_hpa_test.yaml | 178 +++++++++++++++++++++++ 8 files changed, 206 insertions(+), 6 deletions(-) create mode 100644 test/unittest/core_hpa_test.yaml diff --git a/templates/core/core-dpl.yaml b/templates/core/core-dpl.yaml index 42f444029..9b04b42b2 100644 --- a/templates/core/core-dpl.yaml +++ b/templates/core/core-dpl.yaml @@ -8,7 +8,7 @@ metadata: component: core app.kubernetes.io/component: core spec: - {{- if .Values.core.autoscaling.enabled }} + {{- if not .Values.core.autoscaling.enabled }} replicas: {{ .Values.core.replicas }} {{- end }} revisionHistoryLimit: {{ .Values.core.revisionHistoryLimit }} diff --git a/templates/exporter/exporter-dpl.yaml b/templates/exporter/exporter-dpl.yaml index 8a8237b3e..790514fb2 100644 --- a/templates/exporter/exporter-dpl.yaml +++ b/templates/exporter/exporter-dpl.yaml @@ -9,7 +9,7 @@ metadata: component: exporter app.kubernetes.io/component: exporter spec: - {{- if .Values.exporter.autoscaling.enabled }} + {{- if not .Values.exporter.autoscaling.enabled }} replicas: {{ .Values.exporter.replicas }} {{- end }} revisionHistoryLimit: {{ .Values.exporter.revisionHistoryLimit }} diff --git a/templates/jobservice/jobservice-dpl.yaml b/templates/jobservice/jobservice-dpl.yaml index aa6a8c990..d4eca8aa9 100644 --- a/templates/jobservice/jobservice-dpl.yaml +++ b/templates/jobservice/jobservice-dpl.yaml @@ -8,7 +8,7 @@ metadata: component: jobservice app.kubernetes.io/component: jobservice spec: - {{- if .Values.jobservice.autoscaling.enabled }} + {{- if not .Values.jobservice.autoscaling.enabled }} replicas: {{ .Values.jobservice.replicas }} {{- end }} revisionHistoryLimit: {{ .Values.jobservice.revisionHistoryLimit }} diff --git a/templates/portal/deployment.yaml b/templates/portal/deployment.yaml index f8a6dc6e9..5c9ae1463 100644 --- a/templates/portal/deployment.yaml +++ b/templates/portal/deployment.yaml @@ -8,7 +8,7 @@ metadata: component: portal app.kubernetes.io/component: portal spec: - {{- if .Values.portal.autoscaling.enabled }} + {{- if not .Values.portal.autoscaling.enabled }} replicas: {{ .Values.portal.replicas }} {{- end }} revisionHistoryLimit: {{ .Values.portal.revisionHistoryLimit }} diff --git a/templates/registry/registry-dpl.yaml b/templates/registry/registry-dpl.yaml index 9005925dd..c65d088d2 100644 --- a/templates/registry/registry-dpl.yaml +++ b/templates/registry/registry-dpl.yaml @@ -10,7 +10,7 @@ metadata: component: registry app.kubernetes.io/component: registry spec: - {{- if .Values.registry.autoscaling.enabled }} + {{- if not .Values.registry.autoscaling.enabled }} replicas: {{ .Values.registry.replicas }} {{- end }} revisionHistoryLimit: {{ .Values.registry.revisionHistoryLimit }} diff --git a/templates/trivy/trivy-sts.yaml b/templates/trivy/trivy-sts.yaml index 8c3c4d7ce..cdacf1215 100644 --- a/templates/trivy/trivy-sts.yaml +++ b/templates/trivy/trivy-sts.yaml @@ -10,7 +10,7 @@ metadata: component: trivy app.kubernetes.io/component: trivy spec: - {{- if .Values.trivy.autoscaling.enabled }} + {{- if not .Values.trivy.autoscaling.enabled }} replicas: {{ .Values.trivy.replicas }} {{- end }} serviceName: {{ template "harbor.trivy" . }} diff --git a/test/unittest/core_deployment_test.yaml b/test/unittest/core_deployment_test.yaml index da67d3cbf..d766b2aca 100644 --- a/test/unittest/core_deployment_test.yaml +++ b/test/unittest/core_deployment_test.yaml @@ -43,6 +43,28 @@ tests: path: spec.replicas value: 2 + - it: HPADisabledReplicas + set: + core: + replicas: 2 + autoscaling: + enabled: false + template: templates/core/core-dpl.yaml + asserts: + - equal: + path: spec.replicas + value: 2 + + - it: HPAEnabledReplicas + set: + core: + autoscaling: + enabled: true + template: templates/core/core-dpl.yaml + asserts: + - notExists: + path: spec.replicas + - it: ServiceAccounts set: core: diff --git a/test/unittest/core_hpa_test.yaml b/test/unittest/core_hpa_test.yaml new file mode 100644 index 000000000..0bc91d56e --- /dev/null +++ b/test/unittest/core_hpa_test.yaml @@ -0,0 +1,178 @@ +suite: CoreHPA + +tests: + - it: Default + set: + core: + autoscaling: + enabled: true + template: templates/core/core-hpa.yaml + asserts: + - equal: + path: spec.minReplicas + value: 1 + - equal: + path: spec.maxReplicas + value: 11 + - equal: + path: spec.metrics[0].resource.target.averageUtilization + value: 50 + - equal: + path: spec.metrics[1].resource.target.averageUtilization + value: 50 + + - it: HpaAnnotations + set: + core: + autoscaling: + enabled: true + annotations: + test.annotation: test + template: templates/core/core-hpa.yaml + asserts: + - equal: + path: metadata.annotations["test.annotation"] + value: test + + - it: SpecifyReplicas + set: + core: + autoscaling: + enabled: true + minReplicas: 2 + maxReplicas: 10 + template: templates/core/core-hpa.yaml + asserts: + - equal: + path: spec.minReplicas + value: 2 + - equal: + path: spec.maxReplicas + value: 10 + + - it: SpecifyUtilization + set: + core: + autoscaling: + enabled: true + targetMemoryUtilizationPercentage: 70 + targetCPUUtilizationPercentage: 80 + template: templates/core/core-hpa.yaml + asserts: + - equal: + path: spec.metrics[0].resource.target.averageUtilization + value: 70 + - equal: + path: spec.metrics[1].resource.target.averageUtilization + value: 80 + + - it: AutoscalingTemplateSingle + set: + core: + autoscaling: + enabled: true + autoscalingTemplate: + - type: Pods + pods: + metric: + name: test-metric + target: + type: AverageValue + averageValue: 10000m + template: templates/core/core-hpa.yaml + asserts: + - lengthEqual: + path: spec.metrics + count: 3 + - equal: + path: spec.metrics[2].pods.metric.name + value: test-metric + - equal: + path: spec.metrics[2].pods.target.type + value: AverageValue + - equal: + path: spec.metrics[2].pods.target.averageValue + value: 10000m + + - it: AutoscalingTemplateMultiple + set: + core: + autoscaling: + enabled: true + autoscalingTemplate: + - type: Pods + pods: + metric: + name: test-metric + target: + type: AverageValue + averageValue: 10000m + - type: Pods + pods: + metric: + name: test-metric-multiple + target: + type: AverageValue + averageValue: 500m + template: templates/core/core-hpa.yaml + asserts: + - lengthEqual: + path: spec.metrics + count: 4 + - equal: + path: spec.metrics[2].pods.metric.name + value: test-metric + - equal: + path: spec.metrics[2].pods.target.type + value: AverageValue + - equal: + path: spec.metrics[2].pods.target.averageValue + value: 10000m + - equal: + path: spec.metrics[3].pods.metric.name + value: test-metric-multiple + - equal: + path: spec.metrics[3].pods.target.type + value: AverageValue + - equal: + path: spec.metrics[3].pods.target.averageValue + value: 500m + + - it: Behavior + set: + core: + autoscaling: + enabled: true + behavior: + scaleDown: + stabilizationWindowSeconds: 300 + policies: + - type: Pods + value: 1 + periodSeconds: 180 + scaleUp: + stabilizationWindowSeconds: 600 + policies: + - type: Pods + value: 2 + periodSeconds: 60 + template: templates/core/core-hpa.yaml + asserts: + - equal: + path: spec.behavior.scaleDown.stabilizationWindowSeconds + value: 300 + - equal: + path: spec.behavior.scaleDown.policies[0].value + value: 1 + - equal: + path: spec.behavior.scaleDown.policies[0].periodSeconds + value: 180 + - equal: + path: spec.behavior.scaleUp.stabilizationWindowSeconds + value: 600 + - equal: + path: spec.behavior.scaleUp.policies[0].value + value: 2 + - equal: + path: spec.behavior.scaleUp.policies[0].periodSeconds + value: 60 \ No newline at end of file From befd6d1af4520ce71fdd109e66ce83c54f39c458 Mon Sep 17 00:00:00 2001 From: Carlos Vega Date: Wed, 8 Jan 2025 09:44:20 +0100 Subject: [PATCH 7/8] Moved core HPA tests and created exporter HPA tests Signed-off-by: Carlos Vega --- test/unittest/{ => core}/core_hpa_test.yaml | 0 test/unittest/exporter/exporter_hpa_test.yaml | 178 ++++++++++++++++++ 2 files changed, 178 insertions(+) rename test/unittest/{ => core}/core_hpa_test.yaml (100%) create mode 100644 test/unittest/exporter/exporter_hpa_test.yaml diff --git a/test/unittest/core_hpa_test.yaml b/test/unittest/core/core_hpa_test.yaml similarity index 100% rename from test/unittest/core_hpa_test.yaml rename to test/unittest/core/core_hpa_test.yaml diff --git a/test/unittest/exporter/exporter_hpa_test.yaml b/test/unittest/exporter/exporter_hpa_test.yaml new file mode 100644 index 000000000..385bfbf82 --- /dev/null +++ b/test/unittest/exporter/exporter_hpa_test.yaml @@ -0,0 +1,178 @@ +suite: ExporterHPA + +tests: + - it: Default + set: + exporter: + autoscaling: + enabled: true + template: templates/exporter/exporter-hpa.yaml + asserts: + - equal: + path: spec.minReplicas + value: 1 + - equal: + path: spec.maxReplicas + value: 11 + - equal: + path: spec.metrics[0].resource.target.averageUtilization + value: 50 + - equal: + path: spec.metrics[1].resource.target.averageUtilization + value: 50 + + - it: HpaAnnotations + set: + exporter: + autoscaling: + enabled: true + annotations: + test.annotation: test + template: templates/exporter/exporter-hpa.yaml + asserts: + - equal: + path: metadata.annotations["test.annotation"] + value: test + + - it: SpecifyReplicas + set: + exporter: + autoscaling: + enabled: true + minReplicas: 2 + maxReplicas: 10 + template: templates/exporter/exporter-hpa.yaml + asserts: + - equal: + path: spec.minReplicas + value: 2 + - equal: + path: spec.maxReplicas + value: 10 + + - it: SpecifyUtilization + set: + exporter: + autoscaling: + enabled: true + targetMemoryUtilizationPercentage: 70 + targetCPUUtilizationPercentage: 80 + template: templates/exporter/exporter-hpa.yaml + asserts: + - equal: + path: spec.metrics[0].resource.target.averageUtilization + value: 70 + - equal: + path: spec.metrics[1].resource.target.averageUtilization + value: 80 + + - it: AutoscalingTemplateSingle + set: + exporter: + autoscaling: + enabled: true + autoscalingTemplate: + - type: Pods + pods: + metric: + name: test-metric + target: + type: AverageValue + averageValue: 10000m + template: templates/exporter/exporter-hpa.yaml + asserts: + - lengthEqual: + path: spec.metrics + count: 3 + - equal: + path: spec.metrics[2].pods.metric.name + value: test-metric + - equal: + path: spec.metrics[2].pods.target.type + value: AverageValue + - equal: + path: spec.metrics[2].pods.target.averageValue + value: 10000m + + - it: AutoscalingTemplateMultiple + set: + exporter: + autoscaling: + enabled: true + autoscalingTemplate: + - type: Pods + pods: + metric: + name: test-metric + target: + type: AverageValue + averageValue: 10000m + - type: Pods + pods: + metric: + name: test-metric-multiple + target: + type: AverageValue + averageValue: 500m + template: templates/exporter/exporter-hpa.yaml + asserts: + - lengthEqual: + path: spec.metrics + count: 4 + - equal: + path: spec.metrics[2].pods.metric.name + value: test-metric + - equal: + path: spec.metrics[2].pods.target.type + value: AverageValue + - equal: + path: spec.metrics[2].pods.target.averageValue + value: 10000m + - equal: + path: spec.metrics[3].pods.metric.name + value: test-metric-multiple + - equal: + path: spec.metrics[3].pods.target.type + value: AverageValue + - equal: + path: spec.metrics[3].pods.target.averageValue + value: 500m + + - it: Behavior + set: + exporter: + autoscaling: + enabled: true + behavior: + scaleDown: + stabilizationWindowSeconds: 300 + policies: + - type: Pods + value: 1 + periodSeconds: 180 + scaleUp: + stabilizationWindowSeconds: 600 + policies: + - type: Pods + value: 2 + periodSeconds: 60 + template: templates/exporter/exporter-hpa.yaml + asserts: + - equal: + path: spec.behavior.scaleDown.stabilizationWindowSeconds + value: 300 + - equal: + path: spec.behavior.scaleDown.policies[0].value + value: 1 + - equal: + path: spec.behavior.scaleDown.policies[0].periodSeconds + value: 180 + - equal: + path: spec.behavior.scaleUp.stabilizationWindowSeconds + value: 600 + - equal: + path: spec.behavior.scaleUp.policies[0].value + value: 2 + - equal: + path: spec.behavior.scaleUp.policies[0].periodSeconds + value: 60 \ No newline at end of file From 94c3e56edf98629405a05f21e532bbffb0c0d7fe Mon Sep 17 00:00:00 2001 From: Carlos Vega Date: Wed, 8 Jan 2025 09:47:51 +0100 Subject: [PATCH 8/8] Trivy HPA tests Signed-off-by: Carlos Vega --- test/unittest/trivy/trivy_hpa_test.yaml | 178 ++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 test/unittest/trivy/trivy_hpa_test.yaml diff --git a/test/unittest/trivy/trivy_hpa_test.yaml b/test/unittest/trivy/trivy_hpa_test.yaml new file mode 100644 index 000000000..3b65f84f7 --- /dev/null +++ b/test/unittest/trivy/trivy_hpa_test.yaml @@ -0,0 +1,178 @@ +suite: TrivyHPA + +tests: + - it: Default + set: + trivy: + autoscaling: + enabled: true + template: templates/trivy/trivy-hpa.yaml + asserts: + - equal: + path: spec.minReplicas + value: 1 + - equal: + path: spec.maxReplicas + value: 11 + - equal: + path: spec.metrics[0].resource.target.averageUtilization + value: 50 + - equal: + path: spec.metrics[1].resource.target.averageUtilization + value: 50 + + - it: HpaAnnotations + set: + trivy: + autoscaling: + enabled: true + annotations: + test.annotation: test + template: templates/trivy/trivy-hpa.yaml + asserts: + - equal: + path: metadata.annotations["test.annotation"] + value: test + + - it: SpecifyReplicas + set: + trivy: + autoscaling: + enabled: true + minReplicas: 2 + maxReplicas: 10 + template: templates/trivy/trivy-hpa.yaml + asserts: + - equal: + path: spec.minReplicas + value: 2 + - equal: + path: spec.maxReplicas + value: 10 + + - it: SpecifyUtilization + set: + trivy: + autoscaling: + enabled: true + targetMemoryUtilizationPercentage: 70 + targetCPUUtilizationPercentage: 80 + template: templates/trivy/trivy-hpa.yaml + asserts: + - equal: + path: spec.metrics[0].resource.target.averageUtilization + value: 70 + - equal: + path: spec.metrics[1].resource.target.averageUtilization + value: 80 + + - it: AutoscalingTemplateSingle + set: + trivy: + autoscaling: + enabled: true + autoscalingTemplate: + - type: Pods + pods: + metric: + name: test-metric + target: + type: AverageValue + averageValue: 10000m + template: templates/trivy/trivy-hpa.yaml + asserts: + - lengthEqual: + path: spec.metrics + count: 3 + - equal: + path: spec.metrics[2].pods.metric.name + value: test-metric + - equal: + path: spec.metrics[2].pods.target.type + value: AverageValue + - equal: + path: spec.metrics[2].pods.target.averageValue + value: 10000m + + - it: AutoscalingTemplateMultiple + set: + trivy: + autoscaling: + enabled: true + autoscalingTemplate: + - type: Pods + pods: + metric: + name: test-metric + target: + type: AverageValue + averageValue: 10000m + - type: Pods + pods: + metric: + name: test-metric-multiple + target: + type: AverageValue + averageValue: 500m + template: templates/trivy/trivy-hpa.yaml + asserts: + - lengthEqual: + path: spec.metrics + count: 4 + - equal: + path: spec.metrics[2].pods.metric.name + value: test-metric + - equal: + path: spec.metrics[2].pods.target.type + value: AverageValue + - equal: + path: spec.metrics[2].pods.target.averageValue + value: 10000m + - equal: + path: spec.metrics[3].pods.metric.name + value: test-metric-multiple + - equal: + path: spec.metrics[3].pods.target.type + value: AverageValue + - equal: + path: spec.metrics[3].pods.target.averageValue + value: 500m + + - it: Behavior + set: + trivy: + autoscaling: + enabled: true + behavior: + scaleDown: + stabilizationWindowSeconds: 300 + policies: + - type: Pods + value: 1 + periodSeconds: 180 + scaleUp: + stabilizationWindowSeconds: 600 + policies: + - type: Pods + value: 2 + periodSeconds: 60 + template: templates/trivy/trivy-hpa.yaml + asserts: + - equal: + path: spec.behavior.scaleDown.stabilizationWindowSeconds + value: 300 + - equal: + path: spec.behavior.scaleDown.policies[0].value + value: 1 + - equal: + path: spec.behavior.scaleDown.policies[0].periodSeconds + value: 180 + - equal: + path: spec.behavior.scaleUp.stabilizationWindowSeconds + value: 600 + - equal: + path: spec.behavior.scaleUp.policies[0].value + value: 2 + - equal: + path: spec.behavior.scaleUp.policies[0].periodSeconds + value: 60 \ No newline at end of file