apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: snowflake
  namespace: juwan
  labels:
    app: snowflake
spec:
  serviceName: snowflake-headless
  replicas: 1
  selector:
    matchLabels:
      app: snowflake
  template:
    metadata:
      labels:
        app: snowflake
    spec:
      imagePullSecrets:
        - name: registry-creds
      containers:
      - name: snowflake
        image: registry.juwan.xhttp.zip/juwan/snowflake-rpc:latest
        command: ["/bin/sh", "-c"]
        args:
          - |
            export SNOWFLAKE_WORKER_ID="${POD_NAME##*-}"
            exec /app/main -f /app/etc/snowflake.yaml
        env:
          - name: POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: SNOWFLAKE_DATACENTER_ID
            value: "1"
        ports:
        - name: grpc
          containerPort: 8080
        resources:
          requests:
            cpu: 10m
            memory: 32Mi
          limits:
            memory: 512Mi

---
apiVersion: v1
kind: Service
metadata:
  name: snowflake-headless
  namespace: juwan
spec:
  clusterIP: None
  selector:
    app: snowflake
  ports:
    - name: grpc
      port: 8080
      targetPort: 8080

---
apiVersion: v1
kind: Service
metadata:
  name: snowflake-svc
  namespace: juwan
spec:
  ports:
    - name: grpc
      port: 8080
      targetPort: 8080
  selector:
    app: snowflake
