apiVersion: apps/v1
kind: Deployment
metadata:
  name: gitreleases
  namespace: gitreleases
  labels:
    app: gitreleases
spec:
  replicas: 2
  # rolling updates ensures that during a deployment the minmum number of pods is allways in ready state.
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 30%
      maxUnavailable: 25%
  selector:
    matchLabels:
      app: gitreleases
  template:
    metadata:
      labels:
        app: gitreleases
        version: "{{TAG}}"
      annotations:
        ad.datadoghq.com/gitreleases.check_names: '["prometheus"]'
        ad.datadoghq.com/gitreleases.init_configs: "[{}]"
        ad.datadoghq.com/gitreleases.instances: '[{"prometheus_url": "http://%%env_METRICS_USERNAME%%:%%env_METRICS_PASSWORD%%@%%host%%:%%port%%/metrics","namespace": "gitreleases","metrics": ["api_requests_*","go_*","in_flight_requests","process_*","promhttp_*","request_duration_*","response_size_*"]}]'
    spec:
      imagePullSecrets:
        - name: gitlab-auth
      # If possible, don't schedule 2 pods of the same app on the same node.
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 100
              podAffinityTerm:
                topologyKey: kubernetes.io/hostname
                labelSelector:
                  matchExpressions:
                    - key: app
                      operator: In
                      values:
                        - gitreleases
      containers:
        - name: gitreleases
          image: "registry.gitlab.com/mweibel/gitreleases:{{TAG}}"
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080
          livenessProbe:
            httpGet:
              path: /status
              port: 8080
            initialDelaySeconds: 30
            timeoutSeconds: 30
          env:
            - name: LISTEN_ADDR
              value: ":8080"
            - name: GITHUB_TOKEN
              valueFrom:
                secretKeyRef:
                  name: gitreleases-secret
                  key: githubToken
            - name: METRICS_USERNAME
              valueFrom:
                secretKeyRef:
                  name: gitreleases-secret
                  key: metricsUsername
            - name: METRICS_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: gitreleases-secret
                  key: metricsPassword
