From 5aa5a7ae51d743a7571da3c4bdd1a5a8714ee13f Mon Sep 17 00:00:00 2001 From: Kent Dong Date: Thu, 7 Mar 2024 10:17:59 +0800 Subject: [PATCH] feat: Support configuring routes with Gateway API (#61) * feat: Support configuring routes with Gateway API 1. Fix the Gateway API CRDs support in the API server. 2. Generate a basic GatewayClass and Gateway resource during preparation. 3. Fix the XDS cache issue causing delayed push of Gateway API configuration updates. * Remove PILOT_ENABLE_XDS_CACHE=false since the bug has been fixed --- compose/.env | 2 +- compose/scripts/prepare.sh | 97 +++++++++++++++++++- src/apiserver/pkg/apiserver/apiserver.go | 19 +--- src/apiserver/pkg/converter/gatewayapi.go | 104 ++++++++++++++++++++++ 4 files changed, 200 insertions(+), 22 deletions(-) diff --git a/compose/.env b/compose/.env index bbaf259..f6659ae 100644 --- a/compose/.env +++ b/compose/.env @@ -8,7 +8,7 @@ NACOS_PASSWORD='' NACOS_DATA_ENC_KEY='0123456789abcdef0123456789abcdef' NACOS_SERVER_TAG='v2.2.3' HIGRESS_RUNNER_TAG='0.0.3' -HIGRESS_API_SERVER_TAG='0.0.13' +HIGRESS_API_SERVER_TAG='0.0.14' HIGRESS_CONTROLLER_TAG='1.3.5' HIGRESS_PILOT_TAG='1.3.5' HIGRESS_GATEWAY_TAG='1.3.5' diff --git a/compose/scripts/prepare.sh b/compose/scripts/prepare.sh index a44fa9f..95a206c 100644 --- a/compose/scripts/prepare.sh +++ b/compose/scripts/prepare.sh @@ -33,7 +33,12 @@ checkConfigExists() { if [[ "$configGroupVersion" == *"/"* ]]; then uriPrefix="/apis" fi - local url="${API_SERVER_BASE_URL}{$uriPrefix}/${configGroupVersion}/namespaces/${namespace}/${configType}/${configName}" + local url; + if [ -z "$namespace" ]; then + url="${API_SERVER_BASE_URL}${uriPrefix}/${configGroupVersion}/${configType}/${configName}" + else + url="${API_SERVER_BASE_URL}${uriPrefix}/${configGroupVersion}/namespaces/${namespace}/${configType}/${configName}" + fi statusCode=$(curl -s -o /dev/null -w "%{http_code}" "${url}" -k) if [ $statusCode -eq 200 ]; then return 0 @@ -60,7 +65,12 @@ getConfig() { if [[ "$configGroupVersion" == *"/"* ]]; then uriPrefix="/apis" fi - local url="${API_SERVER_BASE_URL}{$uriPrefix}/${configGroupVersion}/namespaces/${namespace}/${configType}/${configName}" + local url; + if [ -z "$namespace" ]; then + url="${API_SERVER_BASE_URL}${uriPrefix}/${configGroupVersion}/${configType}/${configName}" + else + url="${API_SERVER_BASE_URL}${uriPrefix}/${configGroupVersion}/namespaces/${namespace}/${configType}/${configName}" + fi local tmpFile=$(mktemp /tmp/higress-precheck-config.XXXXXXXXX.cfg) local statusCode=$(curl -s -o "$tmpFile" -w "%{http_code}" "${url}" -k -H "Accept: application/yaml") if [ $statusCode -eq 200 ]; then @@ -92,7 +102,12 @@ publishConfig() { if [[ "$configGroupVersion" == *"/"* ]]; then uriPrefix="/apis" fi - local url="${API_SERVER_BASE_URL}{$uriPrefix}/${configGroupVersion}/namespaces/${namespace}/${configType}" + local url; + if [ -z "$namespace" ]; then + url="${API_SERVER_BASE_URL}${uriPrefix}/${configGroupVersion}/${configType}" + else + url="${API_SERVER_BASE_URL}${uriPrefix}/${configGroupVersion}/namespaces/${namespace}/${configType}" + fi statusCode="$(curl -s -o /dev/null -w "%{http_code}" "$url" -k -X POST -H "Content-Type: application/yaml" -d "$content")" if [ $statusCode -ne 201 ]; then echo " Publishing config ${configType}.${configName} to namespace ${namespace} failed with ${statusCode}" @@ -218,6 +233,7 @@ data: {"authority":"%REQ(:AUTHORITY)%","bytes_received":"%BYTES_RECEIVED%","bytes_sent":"%BYTES_SENT%","downstream_local_address":"%DOWNSTREAM_LOCAL_ADDRESS%","downstream_remote_address":"%DOWNSTREAM_REMOTE_ADDRESS%","duration":"%DURATION%","istio_policy_status":"%DYNAMIC_METADATA(istio.mixer:status)%","method":"%REQ(:METHOD)%","path":"%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%","protocol":"%PROTOCOL%","request_id":"%REQ(X-REQUEST-ID)%","requested_server_name":"%REQUESTED_SERVER_NAME%","response_code":"%RESPONSE_CODE%","response_flags":"%RESPONSE_FLAGS%","route_name":"%ROUTE_NAME%","start_time":"%START_TIME%","trace_id":"%REQ(X-B3-TRACEID)%","upstream_cluster":"%UPSTREAM_CLUSTER%","upstream_host":"%UPSTREAM_HOST%","upstream_local_address":"%UPSTREAM_LOCAL_ADDRESS%","upstream_service_time":"%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%","upstream_transport_failure_reason":"%UPSTREAM_TRANSPORT_FAILURE_REASON%","user_agent":"%REQ(USER-AGENT)%","x_forwarded_for":"%REQ(X-FORWARDED-FOR)%"} configSources: - address: xds://controller:15051 + - address: k8s:// defaultConfig: disableAlpnH2: true discoveryAddress: pilot:15012 @@ -310,7 +326,82 @@ EOF fi } +checkGatewayApi() { + echo "Checking Gateway API configurations..." + + checkConfigExists "higress-system" "v1" "services" "higress-gateway" + if [ $? -ne 0 ]; then + echo " The Service resource \"higress-gateway\" doesn't exist. Create it now..." + read -r -d '' content <