{{- include "nplus.init" $ -}}
{{- if eq ((semver .component.version) | (semver "9.1.1200").Compare) 1 -}}
{{- if (.Values.kubePing).name -}}
{{- if (.Values.kubePing).create -}}
# {{ .component.version }} is less than 9.1.1200 ({{ semver .component.version | (semver "9.1.1200").Compare }})
# so we add the old kubePing mechanics.
apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{ tpl .Values.kubePing.name . }}
  {{- if .this.utils.includeNamespace }}
  namespace: {{ .Release.Namespace }}
  {{- end }}
  labels:
    {{- include "nplus.instanceLabels" . | nindent 4 }}
  annotations:
    {{- include "nplus.argoSharedResource" . | nindent 4 }}
    {{- include "nplus.annotations" . | nindent 4 }}
---
{{- end }}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: {{ tpl .Values.kubePing.name . }}
  {{- if .this.utils.includeNamespace }}
  namespace: {{ .Release.Namespace }}
  {{- end }}
  labels:
    {{- include "nplus.instanceLabels" . | nindent 4 }}
  annotations:
    {{- include "nplus.argoSharedResource" . | nindent 4 }}
    {{- include "nplus.annotations" . | nindent 4 }}

rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: {{ tpl .Values.kubePing.name . }}
  {{- if .this.utils.includeNamespace }}
  namespace: {{ .Release.Namespace }}
  {{- end }}
  labels:
    {{- include "nplus.instanceLabels" . | nindent 4 }}
  annotations:
    {{- include "nplus.argoSharedResource" . | nindent 4 }}
    {{- include "nplus.annotations" . | nindent 4 }}

roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: {{ tpl .Values.kubePing.name . }}
subjects:
- kind: ServiceAccount
  name: {{ tpl .Values.kubePing.name . }}
{{- end }}
{{- end }}