# Kube information about the deployment # For documentation on these properties, see: # kubernetes.io/docs/concepts/workloads/controllers/deployment/#creating-a-deployment

apiVersion: apps/v1 kind: Deployment metadata:

name: {{ template "<%= Tpt::Rails.app_name %>.fullname" . }}
labels:
  app: {{ template "<%= Tpt::Rails.app_name %>.name" . }}
  chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
  release: "{{ .Release.Name }}"
  heritage: "{{ .Release.Service }}"
  tpt/project: "{{ .Chart.Name }}"
  tpt/owner: {{ .Values.annotations.owner }}
  tpt/creator: {{ .Values.annotations.creator | default "UNKNOWN" | quote }}
  tpt/release: "{{ .Release.Name }}"
  tpt/costEnv: {{ .Values.annotations.costEnv | quote }}
  tpt/costCategory: {{ .Values.annotations.costCategory | quote }}

spec:

strategy:
  type: RollingUpdate
  rollingUpdate:
    {{ toYaml .Values.rollingUpdate | indent 6 | trim }}
selector:
  matchLabels:
    app: {{ template "<%= Tpt::Rails.app_name %>.fullname" . }}
# Max number of replicat sets to retain.
# Sets exceeding this limit will get deleted
revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
template:
  metadata:
    labels:
      app: {{ template "<%= Tpt::Rails.app_name %>.fullname" . }}
      release: "{{ .Release.Name }}"
      track: stable
      language: ruby
      tpt/project: "{{ .Chart.Name }}"
      tpt/creator: {{ .Values.annotations.creator | default "UNKNOWN" | quote }}
    annotations:
      buildID: "{{ .Values.buildID }}"
      sidecar.istio.io/inject: "false"
  spec:
    # Specifies where our Kube secrets are coming from
    imagePullSecrets:
    - name: {{ .Values.imagePullSecrets.name }}
    containers:
    - name: {{ template "<%= Tpt::Rails.app_name %>.fullname" . }}
      # This references our images on Docker hub
      {{- if .Values.revision }}
      # If a different container version has been specified, use it
      image: "teacherspayteachers/{{ .Values.image.name }}:{{ .Values.revision }}"
      {{- else }}
      image: "teacherspayteachers/{{ .Values.image.name }}:{{ .Values.image.tag }}"
      {{- end }}
      imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
      # Specifies provisioning requests & limits (memory and CPU)
      resources:
        limits:
          memory: {{ .Values.resources.limits.memory }}
          cpu: {{ .Values.resources.limits.cpu }}
        requests:
          memory: {{ .Values.resources.requests.memory }}
          cpu: {{ .Values.resources.requests.cpu }}
      env:
        {{- include "env" . | indent 10 }}
        {{- include "<%= Tpt::Rails.app_name %>.services" . | nindent 10 }}
        {{- if .Values.secrets }}
        {{ toYaml .Values.secrets | trim | nindent 10 }}
        {{- end }}
      ports:
        # Where our application is listening
        - containerPort: {{ .Values.environment.APP_PORT }}
      # Specifies an endpoint. Kube won't mark the container as ready until
      # this endpoint returns a success code
      readinessProbe:
        httpGet:
          path: /internal/health-check
          port: {{ .Values.environment.APP_PORT }}
          scheme: HTTP
        initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
        timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
        periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
        failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
        successThreshold: {{ .Values.readinessProbe.successThreshold }}
      # Specifies an endpoint. Kube will take the container out of circulation
      # if it fails the health check for too long
      livenessProbe:
        httpGet:
          path: /internal/health-check
          port: {{ .Values.environment.APP_PORT }}
          scheme: HTTP
        initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
        timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
        periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
        failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
        successThreshold: {{ .Values.livenessProbe.successThreshold }}