#!/command/with-contenv /bin/bash
# shellcheck shell=bash
# shellcheck disable=SC1091,SC1090

export POD_NAME="higress-controller"
export POD_NAMESPACE="higress-system"
export CONTROLLER_KEEP_XDS_CONFIG_LABELS="false"
export CONTROLLER_KEEP_XDS_CONFIG_ANNOTATIONS="false"
export PILOT_ENABLE_GATEWAY_API="false"
export PILOT_ENABLE_ALPHA_GATEWAY_API="false"
export ENABLE_LEADER_ELECTION="false"

SCRIPT_ROOT=/etc/s6-overlay/scripts
source "$SCRIPT_ROOT/base.sh"
source "$GPUSTACK_GATEWAY_CONFIG"
source "$SCRIPT_ROOT/default-variables.sh"

echo "GATEWAY_HTTP_PORT=$GATEWAY_HTTP_PORT"
echo "GATEWAY_HTTPS_PORT=$GATEWAY_HTTPS_PORT"

set -e

exec 2>&1
exec s6-notifyoncheck \
    -d -w 5000 -n 10 -s 3000 \
    -- \
    /usr/local/bin/higress \
    serve \
    --kubeconfig="${EMBEDDED_KUBECONFIG_PATH}" \
    --gatewaySelectorKey=higress \
    --gatewaySelectorValue=higress-system-higress-gateway \
    --gatewayHttpPort="$GATEWAY_HTTP_PORT" \
    --gatewayHttpsPort="$GATEWAY_HTTPS_PORT" \
    --ingressClass= \
    --httpAddress=localhost:8888 \
    --grpcAddress=localhost:15051
