# helm_charts_pushgateway.yaml
{{- if and .Values.pushgateway.enabled .Values.pushgateway.ingress.enabled -}}
{{- $releaseName := .Release.Name -}}
{{- $serviceName := include "prometheus.pushgateway.fullname" . }}
{{- $servicePort := .Values.pushgateway.service.servicePort -}}
{{- $extraPaths := .Values.pushgateway.ingress.extraPaths -}}
{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" }}
apiVersion: networking.k8s.io/v1beta1
{{ else }}
apiVersion: extensions/v1beta1
{{ end -}}
kind: Ingress
metadata:
{{- if .Values.pushgateway.ingress.annotations }}
  annotations:
{{ toYaml .Values.pushgateway.ingress.annotations | indent 4}}
{{- end }}
  labels:
    {{- include "prometheus.pushgateway.labels" . | nindent 4 }}
  name: {{ template "prometheus.pushgateway.fullname" . }}
{{ include "prometheus.namespace" . | indent 2 }}
spec:
  rules:
  {{- range .Values.pushgateway.ingress.hosts }}
    {{- $url := splitList "/" . }}
    - host: {{ first $url }}
      http:
        paths:
{{ if $extraPaths }}
{{ toYaml $extraPaths | indent 10 }}
{{- end }}
          - path: /{{ rest $url | join "/" }}
            backend:
              serviceName: {{ $serviceName }}
              servicePort: {{ $servicePort }}
  {{- end -}}
{{- if .Values.pushgateway.ingress.tls }}
  tls:
{{ toYaml .Values.pushgateway.ingress.tls | indent 4 }}
  {{- end -}}
{{- end -}}