From 3e26a71ce7c8d3050c54dabff0505a76757c2198 Mon Sep 17 00:00:00 2001 From: yandongxiao Date: Wed, 26 Jun 2024 14:17:43 +0800 Subject: [PATCH] [BugFix] Fix FE proxy will fail when FE external service is recreated (#557) Signed-off-by: yandongxiao --- .golangci.yml | 1 + pkg/subcontrollers/feproxy/feproxy_configmap.go | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index d83f019b..c1e85e7a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -155,6 +155,7 @@ run: timeout: 5m skip-files: - ".*_test\\.go" + - pkg/subcontrollers/feproxy/feproxy_configmap.go skip-dirs: - test/testdata_etc # test files - internal/cache # extracted from Go code diff --git a/pkg/subcontrollers/feproxy/feproxy_configmap.go b/pkg/subcontrollers/feproxy/feproxy_configmap.go index 5910ecdf..4cd865fe 100644 --- a/pkg/subcontrollers/feproxy/feproxy_configmap.go +++ b/pkg/subcontrollers/feproxy/feproxy_configmap.go @@ -27,7 +27,7 @@ func (controller *FeProxyController) SyncConfigMap(ctx context.Context, src *sra feSearchServiceName := service.SearchServiceName(src.Name, feSpec) feExternalServiceName := service.ExternalServiceName(src.Name, feSpec) - proxyPass := fmt.Sprintf("http://%s:%d", feExternalServiceName, httpPort) + proxyPass := fmt.Sprintf("http://%s.%s.%s:%d", feExternalServiceName, src.GetNamespace(), "svc.cluster.local", httpPort) resolver := feProxySpec.Resolver if resolver == "" { @@ -72,7 +72,7 @@ http { server { listen 8080; - resolver %[1]s; + resolver %[1]s valid=10s; proxy_intercept_errors on; recursive_error_pages on; @@ -82,7 +82,9 @@ http { } location / { - proxy_pass %[2]s; + # see https://serverfault.com/questions/240476/how-to-force-nginx-to-resolve-dns-of-a-dynamic-hostname-everytime-when-doing-p/593003#593003 for why we use set + set $fe_service "%[2]s"; + proxy_pass $fe_service; proxy_set_header Expect $http_expect; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -91,7 +93,8 @@ http { } location /api/transaction/load { - proxy_pass %[2]s; + set $fe_service "%[2]s"; + proxy_pass $fe_service; proxy_pass_request_body off; proxy_set_header Expect $http_expect; proxy_set_header Host $host; @@ -101,7 +104,8 @@ http { } location ~ ^/api/.*/.*/_stream_load$ { - proxy_pass %[2]s; + set $fe_service "%[2]s"; + proxy_pass $fe_service; proxy_pass_request_body off; proxy_set_header Expect $http_expect; proxy_set_header Host $host;