commit a98d58a367985e4ae9cf0d0a08d47f534edd334b
Author: Stefan Nica <snica@suse.com>
Date:   Tue Oct 6 23:45:30 2020 +0200

    Add integration tests to the helm chart
    
    Adds the ability to run helm integration tests using `helm test`.

diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl
index 3a49107..0d49fc8 100644
--- a/templates/_helpers.tpl
+++ b/templates/_helpers.tpl
@@ -581,3 +581,42 @@ postgres://{{ template "harbor.database.username" . }}:{{ template "harbor.datab
     {{- include "harbor.nginx" . -}}
   {{- end -}}
 {{- end -}}
+
+{{- define "harbor.test" -}}
+  {{- printf "%s-test" (include "harbor.fullname" .) -}}
+{{- end -}}
+
+{{- define "harbor.tests.api.abortOnFailure" -}}
+  {{- if .Values.tests.api.abortOnFailure -}}
+    {{- printf "-X" }}
+  {{- end -}}
+{{- end -}}
+
+{{- define "harbor.tests.api.include" -}}
+  {{- if .Values.tests.api.include -}}
+    {{- printf "-i %s" (.Values.tests.api.include | join " -i ") }}
+  {{- end -}}
+{{- end -}}
+
+# Build exclude list accordingly to enabled services
+{{- define "harbor.tests.api.exclude" -}}
+  {{- $el := .Values.tests.api.exclude -}}
+  {{- if not .Values.chartmuseum.enabled -}}
+    {{- $el = append $el "list_helm_charts" -}}
+  {{- end -}}
+  {{- if not .Values.notary.enabled -}}
+    {{- $el = append $el "sign_image" -}}
+  {{- end -}}
+  {{- if not .Values.trivy.enabled -}}
+    {{- $el = append $el "push_index" -}}
+    {{- $el = append $el "scan" -}}
+    {{- $el = append $el "scan_all" -}}
+  {{- end -}}
+  {{- if $el -}}
+    {{- printf "-e %s" ($el | join " -e ") }}
+  {{- end -}}
+{{- end -}}
+
+{{- define "harbor.tests.api.options" -}}
+  {{- printf "%s %s %s" (include "harbor.tests.api.include" .) (include "harbor.tests.api.exclude" .) (include "harbor.tests.api.abortOnFailure" .) }}
+{{- end -}}
diff --git a/templates/tests/api.yaml b/templates/tests/api.yaml
new file mode 100644
index 0000000..24fa64b
--- /dev/null
+++ b/templates/tests/api.yaml
@@ -0,0 +1,61 @@
+{{- if .Values.tests.api.enabled }}
+apiVersion: v1
+kind: Pod
+metadata:
+  name: "{{ template "harbor.test" . }}-api"
+  labels:
+{{ include "harbor.labels" . | indent 4 }}
+    component: tests-api
+  annotations:
+    {{- if .Values.tests.api.podAnnotations }}
+      {{ toYaml .Values.tests.api.podAnnotations | indent 4 }}
+    {{- end }}
+    helm.sh/hook: test-success
+spec:
+  {{- with .Values.imagePullSecrets }}
+  imagePullSecrets:
+    {{- toYaml . | nindent 4 }}
+  {{- end }}
+  containers:
+    - name: api-tests
+      image: {{ .Values.tests.api.image.repository }}:{{ .Values.tests.api.image.tag }}
+      imagePullPolicy: {{ .Values.imagePullPolicy }}
+      env:
+        - name: HARBOR_IP
+          value: {{ .Values.externalURL | replace "https://" "" }}
+        {{- if and .Values.notary.enabled (eq .Values.expose.type "ingress") }}
+        - name: NOTARY_URL
+          value: https://{{ .Values.expose.ingress.hosts.notary }}
+        {{- end }}
+        - name: ROBOT_OPTIONS
+          value: "{{ template "harbor.tests.api.options" . }}"
+      volumeMounts:
+        {{- if .Values.expose.tls.enabled }}
+        - name: ca-download
+          mountPath: /usr/share/pki/trust/anchors
+          readOnly: true
+        {{- end }}
+      securityContext:
+        privileged: true
+        allowPrivilegeEscalation: true
+{{- if .Values.tests.api.resources }}
+      resources:
+{{ toYaml .Values.tests.api.resources | indent 8 }}
+{{- end }}
+  volumes:
+    {{- if .Values.expose.tls.enabled }}
+    - name: ca-download
+      secret:
+      {{- if eq (include "harbor.autoGenCertForIngress" .) "true" }}
+        secretName: "{{ template "harbor.ingress" . }}"
+      {{- else if eq (include "harbor.autoGenCertForNginx" .) "true" }}
+        secretName: {{ template "harbor.nginx" . }}
+      {{- else }}
+        secretName: {{ .Values.expose.tls.secretName }}
+      {{- end }}
+        items:
+          - key: ca.crt
+            path: ca.crt
+    {{- end }}
+  restartPolicy: Never
+{{- end }}
diff --git a/values.yaml b/values.yaml
index 369e067..a1698e1 100644
--- a/values.yaml
+++ b/values.yaml
@@ -741,3 +741,29 @@ redis:
     password: ""
   ## Additional deployment annotations
   podAnnotations: {}
+
+
+# Tests that can be executed by using helm test
+tests:
+  api:
+    # Enable/disable API tests
+    enabled: true
+    # Stops test execution if any test fails
+    abortOnFailure: false
+    # Select test cases to run by tag
+    include: []
+    # Select test cases not to run by tag. These tests are not run
+    # even if included on the include list.
+    # Note: Some tests are automatically skipped according to the
+    # harbor enabled services/features.
+    exclude:
+      - singularity # CLI not yet included in the harbor-test-image
+    image:
+      repository: registry.suse.com/harbor/harbor-test
+      tag: 2.1.0
+    # resources:
+    #  requests:
+    #    memory: 128Mi
+    #    cpu: 100m
+    podAnnotations: {}
+
