apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ template "selenium.hub.fullname" . }}
  labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: {{ template "selenium.hub.fullname" . }}
        chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
        release: "{{ .Release.Name }}"
        heritage: "{{ .Release.Service }}"
      {{- if .Values.hub.podAnnotations }}
      annotations:
{{ toYaml .Values.hub.podAnnotations | indent 8 }}
      {{- end}}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.hub.image }}:{{ .Values.hub.tag }}"
          imagePullPolicy: {{ .Values.hub.pullPolicy }}
          ports:
            {{- if .Values.hub.jmxPort }}
            - containerPort: {{ .Values.hub.jmxPort }}
              name: jmx
              protocol: TCP
            {{- end }}
            - containerPort: {{ .Values.hub.port }}
              name: http
          livenessProbe:
            httpGet:
              path: {{ .Values.hub.probePath }}
              port: {{ .Values.hub.port }}
            initialDelaySeconds: 30
            periodSeconds: 5
            timeoutSeconds: {{ .Values.hub.livenessTimeout }}
          readinessProbe:
            httpGet:
              path: {{ .Values.hub.probePath }}
              port: {{ .Values.hub.port }}
            initialDelaySeconds: {{ .Values.hub.readinessDelay }}
            timeoutSeconds: {{ .Values.hub.readinessTimeout }}
          env:
            - name: JAVA_TOOL_OPTIONS
              value: {{ default "" .Values.hub.javaOpts | quote }}
            - name: SE_OPTS
              value: {{ default "" .Values.hub.seOpts | quote }}
            {{- if .Values.hub.gridNewSessionWaitTimeout }}
            - name: GRID_NEW_SESSION_WAIT_TIMEOUT
              value: {{ .Values.hub.gridNewSessionWaitTimeout | quote }}
            {{- end }}
            {{- if .Values.hub.gridJettyMaxThreads }}
            - name: GRID_JETTY_MAX_THREADS
              value: {{ .Values.hub.gridJettyMaxThreads | quote }}
            {{- end }}
            {{- if .Values.hub.gridNodePolling }}
            - name: GRID_NODE_POLLING
              value: {{ .Values.hub.gridNodePolling | quote }}
            {{- end }}
            {{- if .Values.hub.gridCleanUpCycle }}
            - name: GRID_CLEANUP_CYCLE
              value: {{ .Values.hub.gridCleanUpCycle | quote }}
            {{- end }}
            {{- if .Values.hub.gridTimeout }}
            - name: GRID_TIMEOUT
              value: {{ .Values.hub.gridTimeout | quote }}
            {{- end }}
            {{- if .Values.hub.gridBrowserTimeout }}
            - name: GRID_BROWSER_TIMEOUT
              value: {{ .Values.hub.gridBrowserTimeout | quote }}
            {{- end }}
            {{- if .Values.hub.gridMaxSession }}
            - name: GRID_MAX_SESSION
              value: {{ .Values.hub.gridMaxSession | quote }}
            {{- end }}
            {{- if .Values.hub.gridUnregisterIfStillDownAfter }}
            - name: GRID_UNREGISTER_IF_STILL_DOWN_AFTER
              value: {{ .Values.hub.gridUnregisterIfStillDownAfter | quote }}
            {{- end }}
            {{- if .Values.hub.timeZone }}
            - name: TZ
              value: {{ .Values.hub.timeZone | quote }}
            {{- end }}
            {{- if .Values.hub.port }}
            - name: GRID_HUB_PORT
              value: {{ .Values.hub.port | quote }}
            {{- end }}
          resources:
{{ toYaml .Values.hub.resources | indent 12 }}
      nodeSelector:
{{- if .Values.hub.nodeSelector }}
{{ toYaml .Values.hub.nodeSelector | indent 8  }}
{{- else if .Values.global.nodeSelector }}
{{ toYaml .Values.global.nodeSelector | indent 8  }}
{{- end }}
      affinity:
{{- if .Values.hub.affinity }}
{{ toYaml .Values.hub.affinity | indent 8  }}
{{- else if .Values.global.affinity }}
{{ toYaml .Values.global.affinity | indent 8  }}
{{- end }}
      tolerations:
{{- if .Values.hub.tolerations }}
{{ toYaml .Values.hub.tolerations | indent 8  }}
{{- else if .Values.global.tolerations }}
{{ toYaml .Values.global.tolerations | indent 8  }}
{{- end }}
