Skip to content

Commit

Permalink
add luacheck to lint lua files (kubernetes#2205)
Browse files Browse the repository at this point in the history
  • Loading branch information
halfcrazy authored and aledbf committed Mar 18, 2018
1 parent 5c02d70 commit 977cfcb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
std = 'ngx_lua'
globals = {'_'}
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ services:

language: go

addons:
apt:
packages:
- luarocks

notifications:
email:
on_failure: always
Expand All @@ -32,6 +37,8 @@ jobs:
include:
- stage: Static Check
script:
- sudo luarocks install luacheck
- make luacheck
- go get github.com/golang/lint/golint
- make verify-all
- stage: Coverage
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ cover:
vet:
@go vet $(shell go list ${PKG}/... | grep -v vendor)

.PHONY: luacheck
luacheck:
luacheck -q ./rootfs/etc/nginx/lua/

.PHONY: release
release: all-container all-push
echo "done"
Expand Down
11 changes: 6 additions & 5 deletions rootfs/etc/nginx/lua/balancer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ local lrucache = require("resty.lrucache")
local resty_lock = require("resty.lock")

-- measured in seconds
-- for an Nginx worker to pick up the new list of upstream peers
-- for an Nginx worker to pick up the new list of upstream peers
-- it will take <the delay until controller POSTed the backend object to the Nginx endpoint> + BACKENDS_SYNC_INTERVAL
local BACKENDS_SYNC_INTERVAL = 1

ROUND_ROBIN_LOCK_KEY = "round_robin"
local ROUND_ROBIN_LOCK_KEY = "round_robin"

local round_robin_state = ngx.shared.round_robin_state

Expand All @@ -37,8 +37,8 @@ local function balance()

-- Round-Robin
round_robin_lock:lock(backend_name .. ROUND_ROBIN_LOCK_KEY)
local index = round_robin_state:get(backend_name)
local index, endpoint = next(backend.endpoints, index)
local last_index = round_robin_state:get(backend_name)
local index, endpoint = next(backend.endpoints, last_index)
if not index then
index = 1
endpoint = backend.endpoints[index]
Expand Down Expand Up @@ -96,7 +96,8 @@ function _M.call()

local host, port = balance()

local ok, err = ngx_balancer.set_current_peer(host, port)
local ok
ok, err = ngx_balancer.set_current_peer(host, port)
if ok then
ngx.log(ngx.INFO, "current peer is set to " .. host .. ":" .. port)
else
Expand Down

0 comments on commit 977cfcb

Please sign in to comment.