{{- if eq true .Values.chromeDebug.enabled -}}
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ template "selenium.chromeDebug.fullname" . }}
  labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
spec:
  replicas: {{ .Values.chromeDebug.replicas }}
  template:
    metadata:
      labels:
        app: {{ template "selenium.chromeDebug.fullname" . }}
        chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
        release: "{{ .Release.Name }}"
        heritage: "{{ .Release.Service }}"
      {{- if .Values.chromeDebug.podAnnotations }}
      annotations:
{{ toYaml .Values.chromeDebug.podAnnotations | indent 8 }}
      {{- end}}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.chromeDebug.image }}:{{ .Values.chromeDebug.tag }}"
          imagePullPolicy: {{ .Values.chromeDebug.pullPolicy }}
          ports:
            {{- if .Values.hub.jmxPort }}
            - containerPort: {{ .Values.hub.jmxPort }}
              name: jmx
              protocol: TCP
            {{- end }}
            - containerPort: 5900 
              name: vnc
          env:
            - name: HUB_PORT_4444_TCP_ADDR
              value: {{ template "selenium.hub.fullname" . }}
            - name: HUB_PORT_4444_TCP_PORT
              value: {{ .Values.hub.servicePort | quote }}
            - name: JAVA_TOOL_OPTIONS
              value: {{ default "" .Values.chromeDebug.javaOpts | quote }}
            - name: SE_OPTS
              value: {{ default "" .Values.chromeDebug.seOpts | quote }}
            {{- if .Values.chromeDebug.chromeVersion }}
            - name: CHROME_VERSION
              value: {{ .Values.chromeDebug.chromeVersion | quote }}
            {{- end }}
            {{- if .Values.chromeDebug.nodeMaxInstances }}
            - name: NODE_MAX_INSTANCES
              value: {{ .Values.chromeDebug.nodeMaxInstances | quote }}
            {{- end }}
            {{- if .Values.chromeDebug.nodeMaxSession }}
            - name: NODE_MAX_SESSION
              value: {{ .Values.chromeDebug.nodeMaxSession | quote }}
            {{- end }}
            {{- if .Values.chromeDebug.nodeRegisterCycle }}
            - name: NODE_REGISTER_CYCLE
              value: {{ .Values.chromeDebug.nodeRegisterCycle | quote }}
            {{- end }}
            {{- if .Values.chromeDebug.nodePort }}
            - name: NODE_PORT
              value: {{ .Values.chromeDebug.nodePort | quote }}
            {{- end }}
            {{- if .Values.chromeDebug.screenWidth }}
            - name: SCREEN_WIDTH
              value: {{ .Values.chromeDebug.screenWidth | quote }}
            {{- end }}
            {{- if .Values.chromeDebug.screenHeight }}
            - name: SCREEN_HEIGHT
              value: {{ .Values.chromeDebug.screenHeight | quote }}
            {{- end }}
            {{- if .Values.chromeDebug.screenDepth }}
            - name: SCREEN_DEPTH
              value: {{ .Values.chromeDebug.screenDepth | quote }}
            {{- end }}
            {{- if .Values.chromeDebug.display }}
            - name: DISPLAY
              value: {{ .Values.chromeDebug.display | quote }}
            {{- end }}
            {{- if .Values.chromeDebug.timeZone }}
            - name: TZ
              value: {{ .Values.chromeDebug.timeZone | quote }}
            {{- end }}
          volumeMounts:
{{ if .Values.chromeDebug.volumeMounts -}}
{{ toYaml .Values.chromeDebug.volumeMounts | indent 12 }}
{{- end }}
          resources:
{{ toYaml .Values.chromeDebug.resources | indent 12 }}
      volumes:
{{ if .Values.chromeDebug.volumes -}}
{{ toYaml .Values.chromeDebug.volumes | indent 8 }}
{{- end }}
      hostAliases:
{{ toYaml .Values.global.hostAliases | indent 8 }}
      nodeSelector:
{{- if .Values.chromeDebug.nodeSelector }}
{{ toYaml .Values.chromeDebug.nodeSelector | indent 8  }}
{{- else if .Values.global.nodeSelector }}
{{ toYaml .Values.global.nodeSelector | indent 8  }}
{{- end }}
      affinity:
{{- if .Values.chromeDebug.affinity }}
{{ toYaml .Values.chromeDebug.affinity | indent 8  }}
{{- else if .Values.global.affinity }}
{{ toYaml .Values.global.affinity | indent 8  }}
{{- end }}
      tolerations:
{{- if .Values.chromeDebug.tolerations }}
{{ toYaml .Values.chromeDebug.tolerations | indent 8  }}
{{- else if .Values.global.tolerations }}
{{ toYaml .Values.global.tolerations | indent 8  }}
{{- end }}
{{- end -}}
