---
apiVersion: v1
kind: Namespace
metadata:
  name: gooddata-cn
---
apiVersion: v1
stringData:
  GDCN_LICENSE_KEY: "<<Enter your GDCN CE license key>>"
kind: Secret
metadata:
  name: credentials
  namespace: gooddata-cn

---
kind: StatefulSet
apiVersion: apps/v1
metadata:
  name: gooddata-cn-ce
  namespace: gooddata-cn
  labels:
    app: gooddata-cn-ce
spec:
  persistentVolumeClaimRetentionPolicy:
    whenDeleted: Retain
    whenScaled: Retain
  podManagementPolicy: Parallel
  serviceName: gooddata-cn-ce
  replicas: 1
  selector:
    matchLabels:
      app: gooddata-cn-ce
  template:
    metadata:
        labels:
          app: gooddata-cn-ce
    spec:
      containers:
        - name: gooddata-cn-ce
          image: gooddata/gooddata-cn-ce:3.8.0
          ports:
            - name: http
              containerPort: 3000
              protocol: TCP
            - name: postgres
              containerPort: 5432
              protocol: TCP
            - name: healthz
              containerPort: 8079
              protocol: TCP
          envFrom:
            - secretRef:
                name: credentials
                optional: false
          env:
            - name: GDCN_SKIP_RESOURCE_CHECK
              value: '1'
            # Temporary workaround
            - name: PULSAR_STANDALONE_USE_ZOOKEEPER
              value: '1'
            - name: GDCN_PUBLIC_URL
              value: https://localhost
            # - name: PULSAR_LOGLEVEL
            #   value: DEBUG
            - name: SPRING_SECURITY_OAUTH2_CLIENT_COOKIES_SAMESITE
              value: "None"
          imagePullPolicy: IfNotPresent
          resources:
            limits:
              memory: 8Gi
              # cpu: 3500m
            requests:
              cpu: 150m
              memory: 5Gi
          volumeMounts:
            - name: gd-volume
              mountPath: /data
          livenessProbe:
            httpGet:
              path: /healthz
              port: healthz
              scheme: HTTP
            timeoutSeconds: 5
            periodSeconds: 15
            successThreshold: 1
            failureThreshold: 5
          startupProbe:
            httpGet:
              path: /healthz
              port: healthz
              scheme: HTTP
            initialDelaySeconds: 240
            timeoutSeconds: 1
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3
  updateStrategy:
    type: RollingUpdate
  volumeClaimTemplates:
  - apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: gd-volume
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 5Gi
      volumeMode: Filesystem
      # storageClassName: local-path
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  labels:
    app: gooddata-cn-ce
  name: gooddata-cn-ce
  namespace: gooddata-cn
spec:
  # ingressClassName: traefik
  rules:
  - host: localhost
    http:
      paths:
      - backend:
          service:
            name: gooddata-cn-ce
            port:
              name: http
        path: /
        pathType: Prefix
  tls:
  - hosts:
    - localhost
    # secretName: localhost-tls
---
apiVersion: v1
kind: Service
metadata:
  name: gooddata-cn-ce
  namespace: gooddata-cn
  labels:
    app: gooddata-cn-ce
spec:
  ports:
    - name: http
      port: 3000
      targetPort: 3000
  selector:
    app: gooddata-cn-ce
  type: ClusterIP