# Copyright 2019 Google LLC
#
# Licensed 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.

kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-config-sender
data:
  nginx.conf: |-
    worker_processes 1;
    worker_rlimit_nofile 4096;
    error_log /proc/1/fd/1 warn;
    pid /var/run/nginx.pid;
    events {
      worker_connections 4096;
      accept_mutex off;
    }
    http {
      server_tokens off;
      include /etc/nginx/mime.types;
      default_type application/octet-stream;
      log_format  main  '[nginx] method=$request_method path=$request_uri '
                        'status=$status duration=$request_time size=$body_bytes_sent '
                        '"$remote_user" "$http_referer" "$http_user_agent"';
      access_log /proc/1/fd/1 main;

      server {
        listen 3550 http2;
        location / {
          grpc_ssl_verify off;
          grpc_pass grpcs://{{ required "A valid .Values.nginx_listener_1_ip entry required!" .Values.nginx_listener_1_ip }}:4443;
        }
      }
      server {
        listen 7000 http2;
        location / {
          grpc_ssl_verify off;
          grpc_pass grpcs://{{ required "A valid .Values.nginx_listener_1_ip entry required!" .Values.nginx_listener_1_ip }}:4444;
        }
      }
      server {
        listen 7070 http2;
        location / {
          grpc_ssl_verify off;
          grpc_pass grpcs://{{ required "A valid .Values.nginx_listener_1_ip entry required!" .Values.nginx_listener_1_ip }}:4445;
        }
      }
      server {
        listen 8080 http2;
        location / {
          grpc_ssl_verify off;
          grpc_pass grpcs://{{ required "A valid .Values.nginx_listener_1_ip entry required!" .Values.nginx_listener_1_ip }}:4446;
        }
      }
      server {
        listen 50051 http2;
        location / {
          grpc_ssl_verify off;
          grpc_pass grpcs://{{ required "A valid .Values.nginx_listener_1_ip entry required!" .Values.nginx_listener_1_ip }}:4447;
        }
      }
      server {
        listen 9555 http2;
        location / {
          grpc_ssl_verify off;
          grpc_pass grpcs://{{ required "A valid .Values.nginx_listener_2_ip entry required!" .Values.nginx_listener_2_ip }}:4448;
        }
      }
      server {
        listen 5000 http2;
        location / {
          grpc_ssl_verify off;
          grpc_pass grpcs://{{ required "A valid .Values.nginx_listener_2_ip entry required!" .Values.nginx_listener_2_ip }}:4449;
        }
      }
    }
