@@ -93,40 +93,38 @@ if action == "list" then
9393 local i = 1
9494 local j = 0
9595 pods [" items" ] = {}
96- for k ,v in ipairs (resp ) do
97- decoded = json .decode (v )
98- if decoded [" kind" ] == " PodList" then
99- for k2 ,v2 in ipairs (decoded [" items" ]) do
100- if v2 [" status" ][" phase" ] == " Running" and v2 [" metadata" ][" labels" ][" chaos-controller" ] ~= " kubeinvaders" then
101- -- ngx.log(ngx.INFO, "found pod " .. v2["metadata"]["name"])
102- local status = " pending"
103- for _ , c in ipairs (v2 [" status" ][" conditions" ]) do
104- if c [" type" ] == " ContainersReady" and c [" status" ] == " True" then
105- status = " ready"
106- break
107- end
96+ decoded = json .decode (table.concat (resp ))
97+ if decoded [" kind" ] == " PodList" then
98+ for k2 ,v2 in ipairs (decoded [" items" ]) do
99+ if v2 [" status" ][" phase" ] == " Running" and v2 [" metadata" ][" labels" ][" chaos-controller" ] ~= " kubeinvaders" then
100+ -- ngx.log(ngx.INFO, "found pod " .. v2["metadata"]["name"])
101+ local status = " pending"
102+ for _ , c in ipairs (v2 [" status" ][" conditions" ]) do
103+ if c [" type" ] == " ContainersReady" and c [" status" ] == " True" then
104+ status = " ready"
105+ break
108106 end
109- pods [" items" ][i ] = { name = v2 [" metadata" ][" name" ], status = status }
110- i = i + 1
111- pods_not_found = false ;
112- elseif v2 [" status" ][" phase" ] == " ContainerCreating" and v2 [" metadata" ][" labels" ][" chaos-controller" ] ~= " kubeinvaders" then
113- -- ngx.log(ngx.INFO, "found pod " .. v2["metadata"]["name"])
114- pods [" items" ][i ] = { name = v2 [" metadata" ][" name" ], status = " pending" }
115- i = i + 1
116- pods_not_found = false ;
117- elseif v2 [" status" ][" phase" ] == " Terminating" and v2 [" metadata" ][" labels" ][" chaos-controller" ] ~= " kubeinvaders" then
118- -- ngx.log(ngx.INFO, "found pod " .. v2["metadata"]["name"])
119- pods [" items" ][i ] = { name = v2 [" metadata" ][" name" ], status = " killed" }
120- i = i + 1
121- pods_not_found = false ;
122- elseif v2 [" status" ][" phase" ] ~= " Running" and v2 [" status" ][" phase" ] ~= " Completed" and v2 [" status" ][" phase" ] ~= " Succeeded" then
123- j = j + 1
124107 end
108+ pods [" items" ][i ] = { name = v2 [" metadata" ][" name" ], status = status }
109+ i = i + 1
110+ pods_not_found = false ;
111+ elseif v2 [" status" ][" phase" ] == " ContainerCreating" and v2 [" metadata" ][" labels" ][" chaos-controller" ] ~= " kubeinvaders" then
112+ -- ngx.log(ngx.INFO, "found pod " .. v2["metadata"]["name"])
113+ pods [" items" ][i ] = { name = v2 [" metadata" ][" name" ], status = " pending" }
114+ i = i + 1
115+ pods_not_found = false ;
116+ elseif v2 [" status" ][" phase" ] == " Terminating" and v2 [" metadata" ][" labels" ][" chaos-controller" ] ~= " kubeinvaders" then
117+ -- ngx.log(ngx.INFO, "found pod " .. v2["metadata"]["name"])
118+ pods [" items" ][i ] = { name = v2 [" metadata" ][" name" ], status = " killed" }
119+ i = i + 1
120+ pods_not_found = false ;
121+ elseif v2 [" status" ][" phase" ] ~= " Running" and v2 [" status" ][" phase" ] ~= " Completed" and v2 [" status" ][" phase" ] ~= " Succeeded" then
122+ j = j + 1
125123 end
126- local red = redis :new ()
127- local okredis , errredis = red :connect (" unix:/tmp/redis.sock" )
128- red :set (" pods_not_running_on_selected_ns" , j )
129124 end
125+ local red = redis :new ()
126+ local okredis , errredis = red :connect (" unix:/tmp/redis.sock" )
127+ red :set (" pods_not_running_on_selected_ns" , j )
130128 end
131129
132130 local red = redis :new ()
0 commit comments