# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

{{- if .Values.rbac.create }}
{{- if .Values.rbac.namespaceRestricted }}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: {{ include "chrek.fullname" . }}-agent
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "chrek.labels" . | nindent 4 }}
    app.kubernetes.io/component: checkpoint-agent
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: {{ include "chrek.fullname" . }}-agent
subjects:
  - kind: ServiceAccount
    name: {{ include "chrek.serviceAccountName" . }}
    namespace: {{ .Release.Namespace }}
{{- else }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: {{ include "chrek.fullname" . }}-agent
  labels:
    {{- include "chrek.labels" . | nindent 4 }}
    app.kubernetes.io/component: checkpoint-agent
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ include "chrek.fullname" . }}-agent
subjects:
  - kind: ServiceAccount
    name: {{ include "chrek.serviceAccountName" . }}
    namespace: {{ .Release.Namespace }}
{{- end }}
{{- end }}

