# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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: v1
kind: PersistentVolumeClaim
metadata:
  name: banyand-metadata
spec:
  resources:
    requests:
      storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: banyand-measure
spec:
  resources:
    requests:
      storage: 100Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: banyand-stream
spec:
  resources:
    requests:
      storage: 100Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: banyand
spec:
  replicas: 1
  selector:
    matchLabels:
      app: banyand
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: banyand
    spec:
      initContainers:
      - image: busybox
        command: ["/bin/sh"]
        args: ["-c", "rm -rf /tmp/measure/* && rm -rf /tmp/stream/*"]
        name: cleanup
        volumeMounts:
        - name:  measure
          mountPath: /tmp/measure
        - name:  stream
          mountPath: /tmp/stream
      containers:
      - name: banyand
        image: apache/skywalking-banyandb:v0.0.0-dev
        args:
        - "standalone"
        - "--measure-idx-batch-wait-sec=30"
        - "--logging.level=warn"
        imagePullPolicy: Always
        livenessProbe:
          failureThreshold: 5
          httpGet:
            path: /api/healthz
            port: 17913
            scheme: HTTP
          initialDelaySeconds: 20
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 10
        resources:
          limits:
            memory: "8G"
            cpu: "4"
        ports:
        - containerPort: 17912
        - containerPort: 17913
        - containerPort: 2121
        - containerPort: 6060
        volumeMounts:
        - name:  metadata
          mountPath: /tmp/metadata
        - name:  measure
          mountPath: /tmp/measure
        - name:  stream
          mountPath: /tmp/stream
      - image: busybox
        command: ["/bin/sh"]
        args: ["-c", "while true; do ls /tmp; sleep 300s;done"]
        name: debug-entry 
        # resources:
        #   limits:
        #     memory: "10"
        #     cpu: "100mi"
        volumeMounts:
        - name:  metadata
          mountPath: /tmp/metadata
        - name:  measure
          mountPath: /tmp/measure
        - name:  stream
          mountPath: /tmp/stream
      nodeSelector:
        group: banyandb
      tolerations:
      - effect: NoSchedule
        key: group
        operator: Equal
        value: banyandb
      volumes:
        - name: metadata
          persistentVolumeClaim:
            claimName: banyand-metadata
        - name: measure
          persistentVolumeClaim:
            claimName: banyand-measure
        - name: stream
          persistentVolumeClaim:
            claimName: banyand-stream

---
apiVersion: v1
kind: Service
metadata:
  name: banyand
spec:
  selector:
    app: banyand
  ports:
  - port: 17912
    targetPort: 17912

---
apiVersion: v1
kind: Service
metadata:
  name: api
spec:
  selector:
    app: banyand
  ports:
  - port: 17913
    targetPort: 17913
  type: LoadBalancer
