apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    io.kompose.service: trillian-map
  name: trillian-mapserver-deployment
spec:
  replicas: 4
  selector:
    matchLabels:
      io.kompose.service: trillian-map
  strategy: {}
  template:
    metadata:
      labels:
        io.kompose.service: trillian-map
    spec:
      volumes:
      - name: google-cloud-key
        secret:
          secretName: trillian-key
      restartPolicy: Always
      containers:
      - name: trillian-mapserver
        # TODO(RJPercival): Pass STORAGE_FLAG via --config to protect any
        # sensitive contents (e.g. passwords) from being seen in process list.
        args: [
        "$(STORAGE_FLAG)",
        "--storage_system=$(STORAGE_SYSTEM)",
        "--etcd_servers=trillian-etcd-cluster-client:2379",
        "--quota_system=etcd",
        "--rpc_endpoint=0.0.0.0:8090",
        "--http_endpoint=0.0.0.0:8091",
        "--tracing",
        "--alsologtostderr"
        ]
        envFrom:
        - configMapRef:
            name: deploy-config
        - secretRef:
            name: trillian-secrets
        image: gcr.io/${PROJECT_ID}/map_server:${IMAGE_TAG}
        imagePullPolicy: Always
        resources:
          limits:
            cpu: "1.0"
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8091
          failureThreshold: 3
          periodSeconds: 30
          timeoutSeconds: 5
        ports:
        - containerPort: 8090
          name: grpc
        - containerPort: 8091
          name: http-metrics
        volumeMounts:
        - name: google-cloud-key
          mountPath: /var/secrets/google
      - name: prometheus-to-sd
        image: gcr.io/google-containers/prometheus-to-sd:v0.5.2
        ports:
          - name: profiler
            containerPort: 6060
        command:
          - /monitor
          - --stackdriver-prefix=custom.googleapis.com
          - --source=mapserver:http://localhost:8091/metrics
          - --pod-id=$(POD_NAME)
          - --namespace-id=$(POD_NAMESPACE)
          - --scrape-interval=5s
          - --export-interval=60s
        resources:
          limits:
            cpu: 20m
          requests:
            cpu: 20m
        env:
          - name: POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
