From 5cc116fa100e30b882a162bf5a1829d3f93ebb39 Mon Sep 17 00:00:00 2001 From: Elvin Efendi Date: Wed, 24 Oct 2018 22:42:40 +0400 Subject: [PATCH] fix bug with balancer.lua configuration --- rootfs/etc/nginx/template/nginx.tmpl | 8 ++++++-- test/e2e/lua/dynamic_configuration.go | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index 22db89b4d..a7c2c7287 100644 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -884,8 +884,8 @@ stream { rewrite_by_lua_block { balancer.rewrite() } - {{ if shouldConfigureLuaRestyWAF $all.Cfg.DisableLuaRestyWAF $location.LuaRestyWAF.Mode }} access_by_lua_block { + {{ if shouldConfigureLuaRestyWAF $all.Cfg.DisableLuaRestyWAF $location.LuaRestyWAF.Mode }} local lua_resty_waf = require("resty.waf") local waf = lua_resty_waf:new() @@ -912,16 +912,21 @@ stream { {{ end }} waf:exec() + {{ end }} } header_filter_by_lua_block { + {{ if shouldConfigureLuaRestyWAF $all.Cfg.DisableLuaRestyWAF $location.LuaRestyWAF.Mode }} local lua_resty_waf = require "resty.waf" local waf = lua_resty_waf:new() waf:exec() + {{ end }} } body_filter_by_lua_block { + {{ if shouldConfigureLuaRestyWAF $all.Cfg.DisableLuaRestyWAF $location.LuaRestyWAF.Mode }} local lua_resty_waf = require "resty.waf" local waf = lua_resty_waf:new() waf:exec() + {{ end }} } log_by_lua_block { @@ -933,7 +938,6 @@ stream { balancer.log() monitor.call() } - {{ end }} {{ if (and (not (empty $server.SSLCert.PemFileName)) $all.Cfg.HSTS) }} if ($scheme = https) { diff --git a/test/e2e/lua/dynamic_configuration.go b/test/e2e/lua/dynamic_configuration.go index a2bbc1fbc..a3f8c7037 100644 --- a/test/e2e/lua/dynamic_configuration.go +++ b/test/e2e/lua/dynamic_configuration.go @@ -53,7 +53,20 @@ var _ = framework.IngressNginxDescribe("Dynamic Configuration", func() { ensureIngress(f, "foo.com") }) - It("should set nameservers for Lua", func() { + It("configures balancer Lua middleware correctly", func() { + err := f.WaitForNginxConfiguration(func(cfg string) bool { + return strings.Contains(cfg, "balancer.init_worker()") && strings.Contains(cfg, "balancer.balance()") + }) + Expect(err).NotTo(HaveOccurred()) + + host := "foo.com" + err = f.WaitForNginxServer(host, func(server string) bool { + return strings.Contains(server, "balancer.rewrite()") && strings.Contains(server, "balancer.log()") + }) + Expect(err).NotTo(HaveOccurred()) + }) + + It("sets nameservers for Lua", func() { err := f.WaitForNginxConfiguration(func(cfg string) bool { r := regexp.MustCompile(`configuration.nameservers = { [".,0-9a-zA-Z]+ }`) return r.MatchString(cfg)