{{ if .Values.orm_restarter.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: orm-restarter
spec:
  type: ClusterIP
  selector:
    app: orm-restarter
  ports:
    - name: http
      protocol: TCP
      port: 8000
      targetPort: 8000
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: orm-restarter
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: orm-restarter
rules:
  - apiGroups: ["apps"]
    resources: ["deployments"]
    verbs: ["get", "list", "patch"]
  - apiGroups: ["apps"]
    resources: ["pods"]
    verbs: ["get", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: orm-restarter-binding
subjects:
  - kind: ServiceAccount
    name: orm-restarter
roleRef:
  kind: Role
  name: orm-restarter
  apiGroup: rbac.authorization.k8s.io
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: orm-restarter
spec:
  replicas: 1
  selector:
    matchLabels:
      app: orm-restarter
  template:
    metadata:
      name: orm-restarter
      labels:
        app: orm-restarter
    spec:
      containers:
        - name: orm-restarter
          image: goalprofit/orm-restarter:{{.Values.orm_restarter.version}}
          imagePullPolicy: Always
          ports:
            - containerPort: 8000
          env:
            - name: TARGET_DEPLOYMENT
              value: {{.Values.orm_restarter.deployment}}
            - name: MIN_ALIVE_PODS
              value: "{{.Values.orm_restarter.min_alive_pods}}"
      serviceAccountName: orm-restarter
      imagePullSecrets:
        - name: regcred
{{ end }}