apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    plugins.cloudminds.com/loki: loki-gateway
    app.kubernetes.io/name: '{{ ansible_operator_meta.name }}-loki-gateway'
  name: '{{ ansible_operator_meta.name }}-loki-gateway-conf'
  namespace: '{{ ansible_operator_meta.namespace }}'
data:
  nginx.conf: |-
    worker_processes  8;
    error_log  /dev/stderr;
    pid        /tmp/nginx.pid;
    worker_rlimit_nofile 8192;
    events {
      worker_connections  4096;
    }
    http {
      client_max_body_size 1024M;
      resolver kube-dns.kube-system.svc.cluster.local valid=30s;
      default_type application/octet-stream;
      access_log   /dev/stdout;
      sendfile     on;
      tcp_nopush   on;
      server {
        listen               3100 default_server;
        location = / {
          proxy_pass      http://{{ansible_operator_meta.name}}-loki-system.{{ansible_operator_meta.namespace}}.svc.cluster.local:3100/ready;
        }
        location = /ring {
          proxy_pass      http://{{ansible_operator_meta.name}}-loki-system.{{ansible_operator_meta.namespace}}.svc.cluster.local:3100$request_uri;
        }
        location = /api/prom/push {
          proxy_pass       http://{{ansible_operator_meta.name}}-loki-system.{{ansible_operator_meta.namespace}}.svc.cluster.local:3100$request_uri;
        }
        location = /api/prom/tail {
          proxy_pass       http://{{ansible_operator_meta.name}}-loki-system.{{ansible_operator_meta.namespace}}.svc.cluster.local:3100$request_uri;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
        }
        location ~ /api/prom/.* {
          proxy_pass       http://{{ansible_operator_meta.name}}-loki-frontend.{{ansible_operator_meta.namespace}}.svc.cluster.local:3100$request_uri;
        }
        location = /loki/api/v1/push {
          proxy_pass       http://{{ansible_operator_meta.name}}-loki-system.{{ansible_operator_meta.namespace}}.svc.cluster.local:3100$request_uri;
        }
        location = /loki/api/v1/tail {
          proxy_pass       http://{{ansible_operator_meta.name}}-loki-system.{{ansible_operator_meta.namespace}}.svc.cluster.local:3100$request_uri;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
        }
        location ~ /loki/api/.* {
          proxy_pass       http://{{ansible_operator_meta.name}}-loki-frontend.{{ansible_operator_meta.namespace}}.svc.cluster.local:3100$request_uri;
        }
      }
    }