From aa5c3ec0109402eb83f033e5f9d5f673f1fb8def Mon Sep 17 00:00:00 2001 From: Ricardo Katz Date: Sun, 8 Sep 2024 12:42:33 -0300 Subject: [PATCH] Fix reviews on inline lua --- .github/workflows/ci.yaml | 4 +-- hack/verify-lualint.sh | 1 - .../ingress/controller/template/template.go | 36 ------------------- .../nginx/lua/nginx/ngx_conf_log_block.lua | 1 - rootfs/etc/nginx/lua/nginx/ngx_not_found.lua | 1 - .../etc/nginx/lua/nginx/ngx_srv_redirect.lua | 5 +-- rootfs/etc/nginx/lua/util.lua | 3 +- rootfs/etc/nginx/template/nginx.tmpl | 2 +- 8 files changed, 5 insertions(+), 48 deletions(-) delete mode 100644 rootfs/etc/nginx/lua/nginx/ngx_not_found.lua diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 61ed2915b..43384f23f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -83,10 +83,10 @@ jobs: - name: Checkout uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - - name: Luacheck linter + - name: Lint Lua uses: lunarmodules/luacheck@v1 with: - args: --codes --globals lua_ingress --globals configuration --globals balancer --globals monitor --globals certificate --globals plugins --globals tcp_udp_configuration --globals tcp_udp_balancer --no-max-comment-line-length -q rootfs/etc/nginx/lua/ + args: --codes --globals lua_ingress --globals configuration --globals balancer --globals monitor --globals certificate --globals tcp_udp_configuration --globals tcp_udp_balancer --no-max-comment-line-length -q rootfs/etc/nginx/lua/ test-go: runs-on: ubuntu-latest diff --git a/hack/verify-lualint.sh b/hack/verify-lualint.sh index 395c8c6cb..769d7a6cd 100755 --- a/hack/verify-lualint.sh +++ b/hack/verify-lualint.sh @@ -23,7 +23,6 @@ luacheck --codes --globals lua_ingress \ --globals balancer \ --globals monitor \ --globals certificate \ - --globals plugins \ --globals tcp_udp_configuration \ --globals tcp_udp_balancer \ --no-max-comment-line-length -q rootfs/etc/nginx/lua/ diff --git a/internal/ingress/controller/template/template.go b/internal/ingress/controller/template/template.go index 4b92519d3..d2c8a05a9 100644 --- a/internal/ingress/controller/template/template.go +++ b/internal/ingress/controller/template/template.go @@ -291,7 +291,6 @@ var funcMap = text_template.FuncMap{ "filterRateLimits": filterRateLimits, "buildRateLimitZones": buildRateLimitZones, "buildRateLimit": buildRateLimit, - "configForLua": configForLua, "locationConfigForLua": locationConfigForLua, "buildResolvers": buildResolvers, "buildUpstreamName": buildUpstreamName, @@ -418,41 +417,6 @@ func luaConfigurationRequestBodySize(c interface{}) string { return dictKbToStr(size) } -// configForLua returns some general configuration as Lua table represented as string -func configForLua(input interface{}) string { - all, ok := input.(config.TemplateConfig) - if !ok { - klog.Errorf("expected a 'config.TemplateConfig' type but %T was given", input) - return "{}" - } - - return fmt.Sprintf(`{ - use_forwarded_headers = %t, - use_proxy_protocol = %t, - is_ssl_passthrough_enabled = %t, - http_redirect_code = %v, - listen_ports = { ssl_proxy = "%v", https = "%v" }, - - hsts = %t, - hsts_max_age = %v, - hsts_include_subdomains = %t, - hsts_preload = %t, - - }`, - all.Cfg.UseForwardedHeaders, - all.Cfg.UseProxyProtocol, - all.IsSSLPassthroughEnabled, - all.Cfg.HTTPRedirectCode, - all.ListenPorts.SSLProxy, - all.ListenPorts.HTTPS, - - all.Cfg.HSTS, - all.Cfg.HSTSMaxAge, - all.Cfg.HSTSIncludeSubdomains, - all.Cfg.HSTSPreload, - ) -} - // locationConfigForLua formats some location specific configuration into Lua table represented as string func locationConfigForLua(l, a interface{}) string { location, ok := l.(*ingress.Location) diff --git a/rootfs/etc/nginx/lua/nginx/ngx_conf_log_block.lua b/rootfs/etc/nginx/lua/nginx/ngx_conf_log_block.lua index 021952b74..72f6a6430 100644 --- a/rootfs/etc/nginx/lua/nginx/ngx_conf_log_block.lua +++ b/rootfs/etc/nginx/lua/nginx/ngx_conf_log_block.lua @@ -4,7 +4,6 @@ local monitor = require("monitor") local luaconfig = ngx.shared.luaconfig local enablemetrics = luaconfig:get("enablemetrics") - balancer.log() if enablemetrics then diff --git a/rootfs/etc/nginx/lua/nginx/ngx_not_found.lua b/rootfs/etc/nginx/lua/nginx/ngx_not_found.lua deleted file mode 100644 index 296323acf..000000000 --- a/rootfs/etc/nginx/lua/nginx/ngx_not_found.lua +++ /dev/null @@ -1 +0,0 @@ -ngx.exit(ngx.HTTP_NOT_FOUND) \ No newline at end of file diff --git a/rootfs/etc/nginx/lua/nginx/ngx_srv_redirect.lua b/rootfs/etc/nginx/lua/nginx/ngx_srv_redirect.lua index db0a95d7e..4b9445d00 100644 --- a/rootfs/etc/nginx/lua/nginx/ngx_srv_redirect.lua +++ b/rootfs/etc/nginx/lua/nginx/ngx_srv_redirect.lua @@ -4,7 +4,6 @@ local redirect_to = ngx.arg[1] local luaconfig = ngx.shared.luaconfig local use_forwarded_headers = luaconfig:get("use_forwarded_headers") - if string.sub(request_uri, -1) == "/" then request_uri = string.sub(request_uri, 1, -2) end @@ -21,7 +20,5 @@ if use_forwarded_headers then end end - return string.format("%s://%s:%s%s", redirectScheme, - redirect_to, redirectPort, request_uri) - + redirect_to, redirectPort, request_uri) \ No newline at end of file diff --git a/rootfs/etc/nginx/lua/util.lua b/rootfs/etc/nginx/lua/util.lua index 1469f4dde..1e4cd7c01 100644 --- a/rootfs/etc/nginx/lua/util.lua +++ b/rootfs/etc/nginx/lua/util.lua @@ -147,8 +147,7 @@ function _M.is_blank(str) end function _M.string_to_bool(str) - if str == "true" then return true end - return false + return str == "true" end -- this implementation is taken from: diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index 2f6d2f2c9..f32860dc2 100644 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -679,7 +679,7 @@ http { } location / { - content_by_lua_file /etc/nginx/lua/nginx/ngx_not_found.lua; + return 404; } } }