{{- if .Values.deploymentProfiles | has "altair-license" }}
{{ if eq .Values.license.type "altair_unit" }}
kind: Service
apiVersion: v1
metadata:
  name: {{ .Values.licenseProxy.serviceName }}
  namespace: {{ .Values.common.productNS }}
  labels:
    app: license-proxy-svc
spec:
  selector:
    app: license-proxy-app
    tier: backends
  ports:
  - port: 9898
    targetPort: lic-proxy-port

---

kind: Deployment
apiVersion: apps/v1
metadata:
  name: license-proxy-dep
  namespace: {{ .Values.common.productNS }}
  labels:
    app: license-proxy-deployment
spec:
  selector:
    matchLabels:
      app: license-proxy-app
      tier: backends
  replicas: 1
  template:
    metadata:
      {{- with .Values.licenseProxy.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        app: license-proxy-app
        tier: backends
    spec:
      {{- if ne .Values.common.platform "OpenShift" }}
      {{- with .Values.licenseProxy.securityContext }}
      securityContext:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- end }}
      hostname: {{ .Values.licenseProxy.hostname | default "license-proxy" | quote}}
      containers:
      - name: license-proxy
        image: "{{ .Values.licenseProxy.repoName | default .Values.common.dockerURL }}{{ .Values.licenseProxy.imageName }}:{{ .Values.licenseProxy.version | default .Values.common.mainVersion }}"
        imagePullPolicy: "Always"
        envFrom:
          - configMapRef:
              name: {{ .Values.licenseProxy.configName }}
          - secretRef:
              name: {{ .Values.licenseProxy.envSecretName }}
        {{- if .Values.common.externalLicenseSecret }}
          - prefix: ALM_HHWU_
            secretRef:
              name: {{ .Values.common.externalLicenseSecret }}
        {{ end }}
        {{- if eq .Values.license.altair.mode "altair_one" }}
        env:
        {{- if eq .Values.license.altair.altairOne.authType "credentials" }}
          - name: LICENSE_UNIT_MANAGER_USER_NAME
            valueFrom:
              secretKeyRef:
                name: {{ .Values.licenseProxy.secretName }}
                key: username
          - name: LICENSE_UNIT_MANAGER_PASSWORD
            valueFrom:
              secretKeyRef:
                name: {{ .Values.licenseProxy.secretName }}
                key: password
        {{- else if eq .Values.license.altair.altairOne.authType "static_token" }}
          - name: LICENSE_UNIT_MANAGER_TOKEN
            valueFrom:
              secretKeyRef:
              {{- if .Values.common.externalLicenseSecret }}
                name: {{ .Values.common.externalLicenseSecret }}
                key: {{ .Values.licenseProxy.secretKeyName }}
              {{- else }}
                name: {{ .Values.licenseProxy.secretName }}
                key: {{ .Values.licenseProxy.secretKeyName }}
              {{- end }}
        {{- end }}
        {{- end }}
        ports:
        - name: lic-proxy-port
          containerPort: 9898
        readinessProbe:
          tcpSocket:
            port: 9191
          initialDelaySeconds: {{ .Values.licenseProxy.readinessprobe.initialdelayseconds }}
          periodSeconds: {{ .Values.licenseProxy.readinessprobe.periodseconds }}
          failureThreshold: {{ .Values.licenseProxy.readinessprobe.failurethreshold }}
          timeoutSeconds: {{ .Values.licenseProxy.readinessprobe.timeoutseconds }}
        volumeMounts:
        - name: license-proxy-home-pv
          mountPath: /license-proxy/home
          subPath: "license-proxy-home"
        {{- if .Values.common.customCA.enabled }}
        - name: proxy-ssl-vol
          mountPath: {{ .Values.common.jdkCACertPath | quote }}
          subPath: "ssl/java_cacerts"
          readOnly: True
        {{- end }}
        {{- with .Values.licenseProxy.resources }}
        resources:
          {{- toYaml . | nindent 10 }}
        {{- end }}
      volumes:
      - name: license-proxy-home-pv
        persistentVolumeClaim:
          claimName: {{ .Values.licenseProxy.pvcName }}
      {{- if .Values.common.customCA.enabled }}
      - name: proxy-ssl-vol
        persistentVolumeClaim:
          claimName: {{ .Values.proxy.pvcName }}
      {{- end }}
      {{- with .Values.common.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{ if .Values.common.imagePullSecret }}
      imagePullSecrets:
        - name: {{ .Values.common.imagePullSecret }}
      {{ end }}
{{ end }}
{{- end }}
