'Helm templating.. values match

Wondering whether it's possible to use a port if it exists in the values, else use http.. something like this;

svc:
  app:
    ports:
      - port: 8080
        name: http
      - port: 8090
        name: metrics
  app2:
    ports:
      - port: 8080
        name: http

Some service expose their metrics over http and some have metrics ports.. So I'd like to template it something like;

{{ define "app.service.ports" }}
{{ range (index .Values.svc (include "app.refName" .) "ports") }}
- name: {{ .name }}
{{ end }}
{{ end }}

This will pull each port name right, but I want to pull metrics if it exists, else pull http.. can someone point me in the right direction?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source