From bff9087a2a307d9afbdf3dbdcb6458dbb4062822 Mon Sep 17 00:00:00 2001 From: stubenhuang Date: Mon, 24 Apr 2023 20:33:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BD=AC=E5=8F=91=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=88=B0=E5=AE=B9=E5=99=A8=E5=8C=96=E7=BD=91=E5=85=B3=E6=97=B6?= =?UTF-8?q?=E5=B8=A6=E4=B8=8Atoken=20#8725?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gateway/core/backend.conf | 4 ++++ src/gateway/core/lua/util/loadbalance_util.lua | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/gateway/core/backend.conf b/src/gateway/core/backend.conf index 1210a6b63bf..15886200607 100644 --- a/src/gateway/core/backend.conf +++ b/src/gateway/core/backend.conf @@ -156,6 +156,10 @@ location ~ /(ms/|)([\w-_]+)/api/service/(.*) { set $service $2; set $path $3; set $target ''; + set $devops_token ''; + + proxy_set_header X-DEVOPS-TOKEN $devops_token; + access_by_lua_file 'conf/lua/router_srv.lua'; # 设置proxy header的变量 diff --git a/src/gateway/core/lua/util/loadbalance_util.lua b/src/gateway/core/lua/util/loadbalance_util.lua index e5132d2976b..57e61b51775 100644 --- a/src/gateway/core/lua/util/loadbalance_util.lua +++ b/src/gateway/core/lua/util/loadbalance_util.lua @@ -34,6 +34,9 @@ function _M:getTarget(devops_tag, service_name, cache_tail, ns_config) -- 转发到容器环境里 if not in_container and string.find(devops_tag, '^kubernetes-') then + if config.gw_token ~= nil and ngx.var.devops_token == '' then + ngx.var.devops_token = config.gw_token + end local kubernetes_domain = nil if gateway_project == 'codecc' then kubernetes_domain = config.kubernetes.codecc.domain