{{- if .Values.rules.resource}}
{{- if .Capabilities.APIVersions.Has "apiregistration.k8s.io/v1" }}
apiVersion: apiregistration.k8s.io/v1
{{- else }}
apiVersion: apiregistration.k8s.io/v1beta1
{{- end }}
kind: APIService
metadata:
{{- if or .Values.certManager.enabled .Values.customAnnotations }}
  annotations:
    certmanager.k8s.io/inject-ca-from: {{ printf "%s/%s-root-cert" (include "k8s-prometheus-adapter.namespace" .) (include "k8s-prometheus-adapter.fullname" .) | quote }}
    cert-manager.io/inject-ca-from: {{ printf "%s/%s-root-cert" (include "k8s-prometheus-adapter.namespace" .) (include "k8s-prometheus-adapter.fullname" .) | quote }}
    {{- if .Values.customAnnotations }}
    {{- toYaml .Values.customAnnotations | nindent 4 }}
    {{- end }}
{{- end }}
  labels:
    {{- include "k8s-prometheus-adapter.labels" . | indent 4 }}
  name: v1beta1.metrics.k8s.io
spec:
  service:
    name: {{ template "k8s-prometheus-adapter.fullname" . }}
    namespace: {{ include "k8s-prometheus-adapter.namespace" . | quote }}
  {{- if .Values.tls.enable }}
  caBundle: {{ b64enc .Values.tls.ca }}
  {{- end }}
  group: metrics.k8s.io
  version: v1beta1
  {{- if not (or .Values.tls.enable .Values.certManager.enabled) }}
  insecureSkipTLSVerify: true
  {{- end }}
  groupPriorityMinimum: 100
  versionPriority: 100
{{- end -}}
