# Copyright 2022 Tigris Data, Inc.
#
# 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
#
#      http://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:
  labels:
    app.kubernetes.io/name: tigris-server
    app.kubernetes.io/part-of: tigris
    app.kubernetes.io/component: server
  name: tigris-server
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: tigris-server
  template:
    metadata:
      labels:
        app.kubernetes.io/name: tigris-server
    spec:
      containers:
        - name: tigris-server
          image: tigrisdata/tigris:latest # Replace this with the version you want to run through kustomization
          imagePullPolicy: Always
          command: ["/server/service"]
          volumeMounts:
            - mountPath: /tmp
              name: tmp
            - mountPath: /mnt/fdb-config-volume
              name: fdb-cluster-config-volume
            - mountPath: /etc/tigrisdata/tigris
              name: server-config-volume
          ports:
            - containerPort: 8080
          startupProbe:
            httpGet:
              port: 8080
              path: /api/v1/health
            failureThreshold: 6
            periodSeconds: 10
          livenessProbe:
            httpGet:
              port: 8080
              path: /api/v1/health
            initialDelaySeconds: 10
            periodSeconds: 5
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            capabilities:
              drop:
                - all
      volumes:
        - name: tmp
          emptyDir: {}
        # This configmap is created by the fdb-kubernetes-operator when the cluster is created
        # The cluster-name below has to be replaced with the actual cluster name during kustomization phase
        - name: fdb-cluster-config-volume
          configMap:
            name: cluster-name-config
        # This configmap is created during the kustomization phase
        - name: server-config-volume
          configMap:
            name: tigris-server-config
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - podAffinityTerm:
                topologyKey: kubernetes.io/hostname
                labelSelector:
                  matchLabels:
                    app.kubernetes.io/name: tigris-server
              weight: 100
            - podAffinityTerm:
                topologyKey: kubernetes.io/hostname
                labelSelector:
                  matchLabels:
                    app.kubernetes.io/part-of: tigris
              weight: 5
