{{ if .Values.rocketchat.enabled }}
apiVersion: v1
kind: ServiceAccount
metadata:
  name: rocketchat
  namespace: {{ .Release.Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: {{ .Release.Namespace }}
  name: rocketchat
rules:
- apiGroups: [""]
  resources: ["configmaps", "secrets"]
  verbs: ["get", "list", "create", "update", "patch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: rocketchat
  namespace: {{ .Release.Namespace }}
subjects:
- kind: ServiceAccount
  name: rocketchat
  namespace: {{ .Release.Namespace }}
roleRef:
  kind: Role
  name: rocketchat
  apiGroup: rbac.authorization.k8s.io
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: rocketchat
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: "128m"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "300"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "300"
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "300"
spec:
  ingressClassName: nginx
  rules:
    - host: {{ .Values.rocketchat_prefix }}{{ .Values.domain }}
      http:
        paths:
          - pathType: Prefix
            backend:
              service:
                name: rocketchat
                port:
                  number: 3000
            path: /
{{ end }} 