---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: rate-limiter
  labels:
    app: rate-limiter
spec:
  replicas: 1
  selector:
    matchLabels:
      app: rate-limiter
  template:
    metadata:
      labels:
        app: rate-limiter
    spec:
      restartPolicy: Always
      containers:
      - name: ratelimiter
        image: khos2ow/ratelimiter:0.3.1
        imagePullPolicy: Always
        command:
          - "ratelimiter"
        args:
           - "--rate-limit=$(RATE_LIMIT)"
           - "--rate-limit=$(RATE_LIMIT)"
           - "--rate-interval=$(RATE_INTERVAL)"
           - "--rate-timeunit=$(RATE_TIMEUNIT)"
           - "--use-redis=$(USE_REDIS)"
           - "--redis-url=$(REDIS_URL)"
           - "--redis-port=$(REDIS_PORT)"
           - "--redis-password=$(REDIS_PASSWORD)"
           - "--backend-server=$(BACKEND_SERVER)"
        ports:
        - name: http
          containerPort: 8080
        # - name: https
        #   containerPort: 8443
        #   protocol: TCP
        resources:
          limits:
            cpu: "1"
            memory: 400Mi
          requests:
            cpu: 200m
            memory: 100Mi
        env:
        - name: RATE_LIMIT
          valueFrom:
            configMapKeyRef:
              name: rate-limiter-config
              key: RATE_LIMIT
        - name: RATE_INTERVAL
          valueFrom:
            configMapKeyRef:
              name: rate-limiter-config
              key: RATE_INTERVAL
        - name: RATE_TIMEUNIT
          valueFrom:
            configMapKeyRef:
              name: rate-limiter-config
              key: RATE_TIMEUNIT
        - name: USE_REDIS
          valueFrom:
            configMapKeyRef:
              name: rate-limiter-config
              key: USE_REDIS
        - name: REDIS_URL
          valueFrom:
            configMapKeyRef:
              name: rate-limiter-config
              key: REDIS_URL
        - name: REDIS_PORT
          valueFrom:
            configMapKeyRef:
              name: rate-limiter-config
              key: REDIS_PORT
        - name: REDIS_PASSWORD
          valueFrom:
            secretKeyRef:
              name: rate-limiter-secret
              key: REDIS_PASSWORD
        - name: BACKEND_SERVER
          valueFrom:
            configMapKeyRef:
              name: rate-limiter-config
              key: BACKEND_SERVER
        # volumeMounts:
        # - name: volume-ssl
        #   mountPath: /app/ssl/
        #   readOnly: true
        readinessProbe:
          httpGet:
            path: /healthz
            port: 8080
      # volumes:
      # - name: volume-ssl
      #   secret:
      #     secretName: rate-limiter-cert
