{{- if or .Values.rules.default .Values.rules.custom }}
{{- if .Capabilities.APIVersions.Has "apiregistration.k8s.io/v1" }}
apiVersion: apiregistration.k8s.io/v1
{{- else }}
apiVersion: apiregistration.k8s.io/v1beta1
{{- end }}
kind: APIService
metadata:
{{- if .Values.certManager.enabled }}
  annotations:
    certmanager.k8s.io/inject-ca-from: {{ printf "%s/%s-root-cert" .Release.Namespace (include "k8s-prometheus-adapter.fullname" .) | quote }}
    cert-manager.io/inject-ca-from: {{ printf "%s/%s-root-cert" .Release.Namespace (include "k8s-prometheus-adapter.fullname" .) | quote }}
{{- end }}
  labels:
    app: {{ template "k8s-prometheus-adapter.name" . }}
    chart: {{ template "k8s-prometheus-adapter.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
  name: v1beta1.custom.metrics.k8s.io
spec:
  service:
    name: {{ template "k8s-prometheus-adapter.fullname" . }}
    namespace: {{ .Release.Namespace | quote }}
  {{- if .Values.tls.enable }}
  caBundle: {{ b64enc .Values.tls.ca }}
  {{- end }}
  group: custom.metrics.k8s.io
  version: v1beta1
  insecureSkipTLSVerify: {{ if or .Values.tls.enable .Values.certManager.enabled }}false{{ else }}true{{ end }}
  groupPriorityMinimum: 100
  versionPriority: 100
{{- end }}
