# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you 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.

apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
  name: eg
spec:
  controllerName: gateway.envoyproxy.io/gatewayclass-controller
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: {{ .Release.Name }}-gateway
  annotations:
    {{- if and .Values.gatewayConfig .Values.gatewayConfig.issuer }}
    {{- if eq (default "Issuer" .Values.gatewayConfig.issuerKind) "ClusterIssuer" }}
    cert-manager.io/cluster-issuer: {{ .Values.gatewayConfig.issuer }}
    {{- else }}
    cert-manager.io/issuer: {{ .Values.gatewayConfig.issuer }}
    {{- end }}
    {{- end }}
spec:
  gatewayClassName: eg
  listeners:
    - name: http
      protocol: HTTP
      port: 80
      {{- if and .Values.gatewayConfig .Values.gatewayConfig.hostname }}
      hostname: {{ .Values.gatewayConfig.hostname }}
      {{- end }}
      allowedRoutes:
        namespaces:
          from: Same
    - name: https
      protocol: HTTPS
      port: 443
      {{- if and .Values.gatewayConfig .Values.gatewayConfig.hostname }}
      hostname: {{ .Values.gatewayConfig.hostname }}
      {{- end }}
      allowedRoutes:
        namespaces:
          from: Same
      tls:
        mode: Terminate
        certificateRefs:
          - name: {{ (index .Values "gatewayConfig" "tlsSecretName") | default (printf "%s-cert" .Release.Name) }}
    {{- if .Values.minio.gateway.enabled }}
    - name: minio-http
      protocol: HTTP
      port: 80
      hostname: {{ .Values.minio.gateway.hostname }}
      allowedRoutes:
        namespaces:
          from: Same
    - name: minio-https
      protocol: HTTPS
      port: 443
      hostname: {{ .Values.minio.gateway.hostname }}
      allowedRoutes:
        namespaces:
          from: Same
      tls:
        mode: Terminate
        certificateRefs:
          - name: {{ .Values.minio.gateway.tlsSecretName | default (printf "%s-minio-tls" .Release.Name) }}
    {{- end }}
