# apiVersion: v1
# kind: PersistentVolume
# metadata:
#   name: cassandra-pv
# spec:
#   accessModes:
#     - ReadWriteOnce
#   capacity:
#     storage: 10Gi
#   persistentVolumeReclaimPolicy: Retain
#   storageClassName: standard
#   gcePersistentDisk:
#     fsType: ext4
#     pdName: apache-fineract-pd

# ---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: cassandra-pvc
  namespace: {{ .Values.namespace }}
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  # volumeName: cassandra-pv

---

apiVersion: v1
kind: Service
metadata:
  name: cassandra-cluster
  namespace: {{ .Values.namespace }}
spec:
  selector:
    app: cassandra
  ports:
    - port: 9042
      targetPort: 9042
  type: LoadBalancer

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: cassandra-cluster
  namespace: {{ .Values.namespace }}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: cassandra
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: cassandra
    spec:
      containers:
        - image: {{ .Values.cassandra.image }}
          imagePullPolicy: IfNotPresent
          name: cassandra
          ports:
            - containerPort: 9042
              name: cql
          livenessProbe:
            exec:
              command:
                - cqlsh
                - --help
            initialDelaySeconds: 10
            timeoutSeconds: 1
            periodSeconds: 10
            failureThreshold: 3
          volumeMounts:
            - mountPath: /var/lib/cassandra
              name: cassandra-storage
      volumes:
        - name: cassandra-storage
          persistentVolumeClaim:
            claimName: cassandra-pvc
