apiVersion: batch/v1
kind: Job
metadata:
  name: (join('-', [$namespace, 'job1']))
  labels:
    kind: no-metric
spec:
  backoffLimit: 0
  template:
    spec:
      containers:
        - name: test-prometheus
          image: curlimages/curl:8.11.0
          env:
            - name: NAME
              value: (replace_all($namespace, '-', ''))
            - name: SVCNAME
              value: ($service.metadata.name)
          args:
            - /bin/sh
            - -ec
            - |
              curl -s $SVCNAME.keptn-system.svc.cluster.local:9999/metrics > ~/out.txt
              if grep -Fxq "# HELP $NAME $NAME" ~/out.txt
              then
                exit 1
              fi
        - name: test-api-endpoint
          image: curlimages/curl:8.11.0
          env:
            - name: NAME
              value: (replace_all($namespace, '-', ''))
            - name: SVCNAME
              value: ($service.metadata.name)
            - name: NAMESPACE
              value: ($namespace)
          args:
            - /bin/sh
            - -ec
            - |
              curl -s $SVCNAME.keptn-system.svc.cluster.local:9999/api/v1/metrics/$NAMESPACE/$NAME > ~/out.txt
              if grep -F "$NAME" ~/out.txt
              then
                exit 1
              fi
      restartPolicy: Never
