fix nginx

This commit is contained in:
Eugenio Marzo
2021-01-03 08:43:46 +01:00
parent a40c7ea851
commit 283f440da5
3 changed files with 23 additions and 18 deletions

27
kube-linter/kube-linter-parser.sh Normal file → Executable file
View File

@@ -1,9 +1,22 @@
#!/bin/sh
kube-linter lint $1 2>&1 |
while read -r line
do
echo
echo $line |sed -n 's/^\([^\ ]*\)\ \(([^\(]*)\)\ \(.*\)$/\3/p'
echo
done
POD_FILE=/tmp/${3}.yaml
#Getting yaml of pod ${3} through kubernetes API
curl -XGET "{$1}/api/v1/namespaces/{$2}/pods/{$3}" --header "Authorization: Bearer ${4}" --silent -k > ${POD_FILE}
[ ! $? -eq 0 ] && (echo "{}" && exit 0)
#Execute kubelinter against ${POD_FILE}
wcl=$(cat ${POD_FILE} | wc -l )
if [[ $wcl -gt 0 ]];then
kube-linter lint ${POD_FILE} 2>&1 |
while read -r line
do
echo $line | sed -n 's/^\([^\ ]*\)\ \(([^\(]*)\)\ \(.*\)$/\3/p'
done | jq -R -s -c 'split("\n")'
else
echo "{}"
fi

View File

@@ -8,13 +8,9 @@ server {
content_by_lua_block {
local arg = ngx.req.get_uri_args()
ngx.req.read_body()
local request_body = ngx.req.get_body_data()
os.execute("curl -XGET " .. arg['k8s_url'] .. "/api/v1/namespaces/" .. arg['namespace'] .. "/pods/" .. arg['pod_name'] .. " --header 'Authorization: Bearer " .. arg['token'] .. "' -k > /tmp/" .. arg['pod_name'] .. ".yaml")
os.execute("/opt/kube-linter-parser.sh /tmp/" .. arg['pod_name'] .. ".yaml > /tmp/" .. arg['pod_name'] .. ".linter")
local handle = io.popen('jq -R -s -c \'split("\n")\' < /tmp/' .. arg['pod_name'] .. '.linter')
local request_body = ngx.req.get_body_data()
local handle = io.popen("/opt/kube-linter-parser.sh" .. arg['k8s_url'] .. " " .. arg['namespace'] .. " " .. arg['pod_name'] .. " " .. arg['token']")
local result = handle:read("*a")
os.execute("rm -f /tmp/" .. arg['pod_name'] .. ".linter")
os.execute("rm -f /tmp/" .. arg['pod_name'] .. ".yaml")
ngx.say(result)
}
}

View File

@@ -9,12 +9,8 @@ server {
local arg = ngx.req.get_uri_args()
ngx.req.read_body()
local request_body = ngx.req.get_body_data()
os.execute("curl -XGET " .. arg['k8s_url'] .. "/api/v1/namespaces/" .. arg['namespace'] .. "/pods/" .. arg['pod_name'] .. " --header 'Authorization: Bearer " .. arg['token'] .. "' -k > /tmp/" .. arg['pod_name'] .. ".yaml")
os.execute("/opt/kube-linter-parser.sh /tmp/" .. arg['pod_name'] .. ".yaml > /tmp/" .. arg['pod_name'] .. ".linter")
local handle = io.popen('jq -R -s -c \'split("\n")\' < /tmp/' .. arg['pod_name'] .. '.linter')
local handle = io.popen("/opt/kube-linter-parser.sh" .. arg['k8s_url'] .. " " .. arg['namespace'] .. " " .. arg['pod_name'] .. " " .. arg['token']")
local result = handle:read("*a")
os.execute("rm -f /tmp/" .. arg['pod_name'] .. ".linter")
os.execute("rm -f /tmp/" .. arg['pod_name'] .. ".yaml")
ngx.say(result)
}
}