# 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: Role
metadata:
  name: {{ include "chrek.fullname" . }}-agent
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "chrek.labels" . | nindent 4 }}
    app.kubernetes.io/component: checkpoint-agent
rules:
  # Watch pods in this namespace to detect checkpoint-source pods becoming ready
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get", "list", "watch"]
{{- else }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: {{ include "chrek.fullname" . }}-agent
  labels:
    {{- include "chrek.labels" . | nindent 4 }}
    app.kubernetes.io/component: checkpoint-agent
rules:
  # Watch pods cluster-wide to detect checkpoint-source pods on assigned nodes
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get", "list", "watch"]
{{- end }}
{{- end }}

