{{- $domains := .Values.domains -}}
{{- if .Values.global }}
    {{- if .Values.global.domains }}
        {{- $domains = .Values.global.domains -}}
    {{- end -}}
{{- end -}}

{{- if not $domains -}}
{{- $name := (dict "name" (.Values.environment.ADDRESS | replace "https://" "" | replace "http://" "")) -}}
{{- $domains = (list (merge .Values.environment $name)) -}}
{{- end -}}

{{- range $domains }}
---
apiVersion: v1
kind: Service
metadata:
  {{- with $.Values.service.annotations }}
  annotations:
  {{ toYaml . | indent 4 }}
  {{- end }}
  name: {{ include "layer1_port_owncloud.fullname" (mergeOverwrite $ .) }}
  namespace: {{ $.Values.global.namespace.name | default $.Release.Namespace  }}
  labels:
{{ include "layer1_port_owncloud.labels" (mergeOverwrite $ .) | indent 4 }}
spec:
  type: {{ $.Values.service.type }}
  ports:
    - port: {{ $.Values.service.port }}
      targetPort: http
      protocol: TCP
      name: http
  selector:
    app.kubernetes.io/name: {{ include "layer1_port_owncloud.name" (mergeOverwrite $ .) }}
    app.kubernetes.io/instance: {{ $.Release.Name }}
{{- end }}
