{{- if .Values.createController -}}
apiVersion: v1
kind: Service
metadata:
  name: {{ include "sealed-secrets.fullname" . }}
  namespace: {{ include "sealed-secrets.namespace" . }}
  {{- if or .Values.service.annotations .Values.commonAnnotations }}
  annotations:
    {{- if .Values.service.annotations }}
    {{- include "sealed-secrets.render" (dict "value" .Values.service.annotations "context" $) | nindent 4 }}
    {{- end }}
    {{- if .Values.commonAnnotations }}
    {{- include "sealed-secrets.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
    {{- end }}
  {{- end }}
  labels: {{- include "sealed-secrets.labels" . | nindent 4 }}
    {{- if .Values.service.labels }}
    {{- include "sealed-secrets.render" ( dict "value" .Values.service.labels "context" $) | nindent 4 }}
    {{- end }}
    {{- if .Values.commonLabels }}
    {{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
    {{- end }}
spec:
  type: {{ .Values.service.type }}
  {{- with .Values.service.loadBalancerClass }}
  loadBalancerClass: {{ . }}
  {{- end }}
  ports:
    - name: http
      port: {{ .Values.service.port }}
      targetPort: http
      {{- if and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePort)) }}
      nodePort: {{ .Values.service.nodePort }}
      {{- else if eq .Values.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
  selector: {{- include "sealed-secrets.matchLabels" . | nindent 4 }}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "sealed-secrets.fullname" . }}-metrics
  namespace: {{ include "sealed-secrets.namespace" . }}
  {{- if or .Values.metrics.service.annotations .Values.commonAnnotations }}
  annotations:
    {{- if .Values.metrics.service.annotations }}
    {{- include "sealed-secrets.render" (dict "value" .Values.metrics.service.annotations "context" $) | nindent 4 }}
    {{- end }}
    {{- if .Values.commonAnnotations }}
    {{- include "sealed-secrets.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
    {{- end }}
  {{- end }}
  labels: {{- include "sealed-secrets.labels" . | nindent 4 }}
    {{- if .Values.metrics.service.labels }}
    {{- include "sealed-secrets.render" ( dict "value" .Values.metrics.service.labels "context" $) | nindent 4 }}
    {{- end }}
    {{- if .Values.commonLabels }}
    {{- include "sealed-secrets.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
    {{- end }}
    app.kubernetes.io/component: metrics
spec:
  type: {{ .Values.metrics.service.type }}
  {{- with .Values.metrics.service.loadBalancerClass }}
  loadBalancerClass: {{ . }}
  {{- end }}
  ports:
    - name: metrics
      port: {{ .Values.metrics.service.port }}
      targetPort: metrics
      {{- if and (or (eq .Values.metrics.service.type "NodePort") (eq .Values.metrics.service.type "LoadBalancer")) (not (empty .Values.metrics.service.nodePort)) }}
      nodePort: {{ .Values.metrics.service.nodePort }}
      {{- else if eq .Values.metrics.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
  selector: {{- include "sealed-secrets.matchLabels" . | nindent 4 }}
{{- end }}
