# helm_charts_hub-deployment.yaml
apiVersion: {{ template "deployment.apiVersion" . }}
kind: Deployment
metadata:
  name: {{ template "selenium.hub.fullname" . }}
  labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: {{ template "selenium.hub.fullname" . }}
      release: "{{ .Release.Name }}"
  template:
    metadata:
      labels:
        app: {{ template "selenium.hub.fullname" . }}
        chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
        release: "{{ .Release.Name }}"
        heritage: "{{ .Release.Service }}"
      {{- with .Values.hub.podLabels }}
      {{ toYaml .| indent 2 }}
      {{- end }}  
      {{- if .Values.hub.podAnnotations }}
      annotations:
{{ toYaml .Values.hub.podAnnotations | indent 8 }}
      {{- end}}
    spec:
      {{- if .Values.hub.securityContext }}
      securityContext:
{{ toYaml .Values.hub.securityContext | indent 8 }}
      {{- end }}
      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_CLEAN_UP_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 }}
            {{- if .Values.hub.extraEnvs }}
{{ toYaml .Values.hub.extraEnvs | indent 12 }}
            {{- end }}
          resources:
{{ toYaml .Values.hub.resources | trim | indent 12 -}}
{{- if or .Values.global.imagePullSecrets .Values.hub.imagePullSecrets }}
      imagePullSecrets:
      - name: {{ .Values.hub.imagePullSecrets | default .Values.global.imagePullSecrets | quote }}
{{- end }}
      nodeSelector:
{{- if .Values.hub.nodeSelector }}
{{ toYaml .Values.hub.nodeSelector | trim | indent 8  }}
{{- else if .Values.global.nodeSelector }}
{{ toYaml .Values.global.nodeSelector | trim | 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 }}