forked from kubernetes/ingress-nginx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor balancer into more testable and extensible interface
- Loading branch information
1 parent
1b5db4b
commit e9dc275
Showing
20 changed files
with
363 additions
and
462 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
std = 'ngx_lua' | ||
globals = {'_'} | ||
globals = { | ||
'_TEST' | ||
} | ||
exclude_files = {'./rootfs/etc/nginx/lua/test/**/*.lua'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
local balancer_resty = require("balancer.resty") | ||
local resty_chash = require("resty.chash") | ||
local util = require("util") | ||
|
||
local _M = balancer_resty:new({ factory = resty_chash, name = "chash" }) | ||
|
||
function _M.new(self, backend) | ||
local nodes = util.get_nodes(backend.endpoints) | ||
local o = { instance = self.factory:new(nodes), hash_by = backend["upstream-hash-by"] } | ||
setmetatable(o, self) | ||
self.__index = self | ||
return o | ||
end | ||
|
||
function _M.balance(self) | ||
local key = util.lua_ngx_var(self.hash_by) | ||
local endpoint_string = self.instance:find(key) | ||
return util.split_pair(endpoint_string, ":") | ||
end | ||
|
||
return _M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.