# 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
#
#      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: StatefulSet
metadata:
  name: db2wh
spec:
  podManagementPolicy: Parallel
  selector:
    matchLabels:
      app: db2wh # has to match .spec.template.metadata.labels
  serviceName: "db2wh"
  replicas: 3
  template:
    metadata:
      labels:
        app: db2wh # has to match .spec.selector.matchLabels
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: "app"
                operator: In
                values:
                - db2wh
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: "app"
                operator: In
                values:
                - db2wh
            topologyKey: "kubernetes.io/hostname"
      terminationGracePeriodSeconds: 5
      containers:
      - name: db2wh
        image: store/ibmcorp/db2wh_ee:v2.12.0-db2wh-linux
        ports:
        - containerPort: 50022
          name: ssh-automation
        - containerPort: 50001
          name: dbssl
        - containerPort: 50000
          name: db
        - containerPort: 9929
          name: test-comms
        - containerPort: 9300
          name: console-status
        - containerPort: 8998
          name: spark-livy
        - containerPort: 8443
          name: console-https
        - containerPort: 5000
          name: system-manager
        - containerPort: 2379
          name: ha-1
        - containerPort: 2380
          name: ha-2
        - containerPort: 389
          name: ldap
        - containerPort: 22
          name: ssh
        readinessProbe:
          httpGet:
            port: console-https
            scheme: HTTPS
          initialDelaySeconds: 360
          periodSeconds: 30
        volumeMounts:
        - name: clusterfs
          mountPath: /mnt/bludata0
        - name: clusterfs
          mountPath: /mnt/blumeta0
        - name: cgvol
          mountPath: /sys/fs/cgroup
          readOnly: true
        securityContext:
          privileged: true
        tty: true
      hostNetwork: true
      imagePullSecrets:
      - name: dockerstore
      volumes:
      - name: clusterfs
        persistentVolumeClaim:
          claimName: clusterfs
      - name: cgvol
        hostPath:
          path: /sys/fs/cgroup
