# helm_charts_driver-statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: {{ template "cosbench.driver.fullname" . }}
  labels:
    app: {{ template "cosbench.name" . }}
    chart: {{ template "cosbench.chart" . }}
    component: driver
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
spec:
  serviceName: {{ template "cosbench.driver.fullname" . }}
  replicas: {{ .Values.driver.replicaCount }}
  selector:
    matchLabels:
        app: {{ template "cosbench.name" . }}
        component: driver
        release: "{{ .Release.Name }}"
  template:
    metadata:
      labels:
        app: {{ template "cosbench.name" . }}
        component: driver
        release: "{{ .Release.Name }}"
    spec:
      serviceAccountName: {{ template "cosbench.serviceAccountName.driver" . }}
      containers:
        - name: {{ template "cosbench.driver.fullname" . }}
          image: "{{ .Values.driver.image.repository }}:{{ .Values.driver.image.tag }}"
          imagePullPolicy: {{ .Values.driver.image.pullPolicy }}
          ports:
            - name: driver
              containerPort: 18088
              protocol: TCP
          env:
            - name: LOG_LEVEL
              value: "{{ .Values.driver.logLevel }}"
          args: ['java','-Dcosbench.tomcat.config=conf/driver-tomcat-server.xml','-server','-cp','main/*','org.eclipse.equinox.launcher.Main','-configuration','conf/.driver','-console','18089']
          resources:
{{ toYaml .Values.driver.resources | indent 12 }}
      affinity:
        podAntiAffinity:
        {{- if eq .Values.driver.antiAffinity "hard" }}
          requiredDuringSchedulingIgnoredDuringExecution:
          - topologyKey: "kubernetes.io/hostname"
            labelSelector:
              matchLabels:
                app:  {{ template "cosbench.name" . }}
                component: driver
                release: {{ .Release.Name | quote }}
        {{- else if eq .Values.driver.antiAffinity "soft" }}
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: {{ .Values.driver.antiAffinityWeight }}
            podAffinityTerm:
              topologyKey: "kubernetes.io/hostname"
              labelSelector:
                matchLabels:
                  app:  {{ template "cosbench.name" . }}
                  component: driver
                  release: {{ .Release.Name | quote }}
        {{- end }}
      {{- if .Values.driver.hostAliases }}
      hostAliases:
{{ toYaml .Values.driver.hostAliases | indent 8 }}
      {{- end }}