#Copyright 2019 Google LLC

#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at

#https://www.apache.org/licenses/LICENSE-2.0

#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: prometheus-deployment
  namespace: prometheus
  labels:
    app: prometheus-server
spec:
  replicas: 1
  selector:
    matchLabels:
      app: prometheus-server
  template:
    metadata:
      labels:
        app: prometheus-server
    spec:
      containers:
        - name: prometheus
          image: prom/prometheus:${PROMETHEUS_VER_TAG}
          args:
            - "--config.file=/etc/prometheus/prometheus.yml"
            - "--storage.tsdb.path=/prometheus/"
          ports:
            - containerPort: 9090
          volumeMounts:
            - name: prometheus-config-volume
              mountPath: /etc/prometheus/
            - name: prometheus-storage-volume
              mountPath: /prometheus/
        - name: sidecar
          image: gcr.io/stackdriver-prometheus/stackdriver-prometheus-sidecar:${SIDECAR_IMAGE_TAG}
          imagePullPolicy: Always
          args:
            - --stackdriver.project-id=${GCP_PROJECT}
            - --prometheus.wal-directory=${DATA_DIR}/wal
            - --stackdriver.kubernetes.location=${GCP_LOCATION}
            - --stackdriver.kubernetes.cluster-name=${KUBE_CLUSTER}
            #- --stackdriver.generic.location=${GCP_LOCATION}
            #- --stackdriver.generic.namespace=${KUBE_CLUSTER}
          ports:
            - name: sidecar
              containerPort: 9091
          volumeMounts:
            - name: ${DATA_VOLUME}
              mountPath: ${DATA_DIR}
            - name: prometheus-key
              mountPath: /var/secrets/google 
          env:
          - name: GOOGLE_APPLICATION_CREDENTIALS
            value: /var/secrets/google/prometheus-service-account.json
      volumes:
        - name: prometheus-config-volume
          configMap:
            defaultMode: 420
            name: prometheus-server-conf

        - name: prometheus-storage-volume
          emptyDir: {}

        - name: prometheus-key
          secret:
            secretName: prometheus-key
