apiVersion: v1
kind: Pod
metadata:
  name: "{{ .Release.Name }}-assetsvc-test"
  annotations:
    "helm.sh/hook": test-success
spec:
  containers:
    - name: {{ .Release.Name }}-assetsvc-test
      image: {{ template "kubeapps.image" (list .Values.testImage .Values.global) }}
      env:
        - name: ASSETSVC_HOST
          value: {{ template "kubeapps.assetsvc.fullname" . }}.{{ .Release.Namespace }}
        - name: ASSETSVC_PORT
          value: "{{ .Values.assetsvc.service.port }}"
      command:
        - bash
        - -c
        # We are requesting the "wordpress" chart to the chartsvc to check that everything works as expected
        # Also, we retry several times in case the repository is being populated at the time of executing this test
        - |
            n=0
            until [ "$n" -ge 5 ]; do
              if curl -o /tmp/output $ASSETSVC_HOST:$ASSETSVC_PORT/v1/clusters/default/namespaces/{{ .Release.Namespace }}/charts && cat /tmp/output && cat /tmp/output | grep wordpress; then
                break
              fi
              sleep 10
              ((n+=1))
            done
            if [ "$n" -eq 5 ]; then
              exit 1
            fi
  restartPolicy: Never
