{{- if (.Values.lighthouse) and (eq .Values.lighthouse true) -}}
apiVersion: v1
kind: ServiceAccount
metadata:
  name: px-lh-account
  namespace: kube-system
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
   name: px-lh-role
   namespace: kube-system
rules:
  - apiGroups: [""]
    resources: ["secrets"]
    verbs: ["get", "create", "update"]
  - apiGroups: [""]
    resources: ["configmaps"]
    verbs: ["get", "create", "update"]
  - apiGroups: [""]
    resources: ["nodes", "services"]
    verbs: ["get", "list", "watch"]
  - apiGroups: ["stork.libopenstorage.org"]
    resources: ["clusterpairs", "migrations", "groupvolumesnapshots"]
    verbs: ["get", "list", "create", "update", "delete"]  
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: px-lh-role-binding
  namespace: kube-system
subjects:
- kind: ServiceAccount
  name: px-lh-account
  namespace: kube-system
roleRef:
  kind: ClusterRole
  name: px-lh-role
  apiGroup: rbac.authorization.k8s.io
---
apiVersion: v1
kind: Service
metadata:
  name: px-lighthouse
  namespace: kube-system
  labels:
    tier: px-web-console
spec:
  type: NodePort
  ports:
    - name: http
      port: 80
    - name: https
      port: 443
  selector:
    tier: px-web-console
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: px-lighthouse
  namespace: kube-system
  labels:
    tier: px-web-console
spec:
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  selector:
    matchLabels:
      tier: px-web-console
  replicas: 1
  template:
    metadata:
      labels:
        tier: px-web-console
    spec:
      initContainers:
      - name: config-init
        image: "{{ template "px.getLighthouseImages" . }}/lh-config-sync:{{.Values.lighthouseSyncVersion}}"
        imagePullPolicy: Always
        args:
        - "init"
        volumeMounts:
        - name: config
          mountPath: /config/lh
      containers:
      - name: px-lighthouse
        image: "{{ template "px.getLighthouseImages" . }}/px-lighthouse:{{ required "A valid lighthouse image version is required" .Values.lighthouseVersion}}"
        imagePullPolicy: Always
        args: [ "-kubernetes", "true" ]
        ports:
        - containerPort: 80
        - containerPort: 443
        volumeMounts:
        - name: config
          mountPath: /config/lh
      - name: config-sync
        image: "{{ template "px.getLighthouseImages" . }}/lh-config-sync:{{.Values.lighthouseSyncVersion}}"
        imagePullPolicy: Always
        args:
        - "sync"
        volumeMounts:
        - name: config
          mountPath: /config/lh
      - name: stork-connector
        image: "{{ template "px.getLighthouseImages" . }}/lh-stork-connector:{{.Values.lighthouseStorkConnectorVersion}}"
        imagePullPolicy: Always
      serviceAccountName: px-lh-account
      volumes:
      - name: config
        emptyDir: {}
{{- end -}}
