Skip to content

Commit

Permalink
We now properly detects crashloobpack and failure
Browse files Browse the repository at this point in the history
and print failure reason if any when using -l

Signed-off-by: Chmouel Boudjnah <[email protected]>
  • Loading branch information
chmouel committed Dec 14, 2023
1 parent e888ed9 commit cb47bd6
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions kss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ import re
import subprocess
import sys

failed_containers = (
"ImagePullBackOff",
"CrashLoopBackOff",
)


def colourText(text, color):
colours = {
Expand Down Expand Up @@ -51,6 +56,7 @@ def show_log(kctl, args, container, pod):

def overcnt(jeez, kctl, pod, args):
for container in jeez:
errmsg = ""
if args.restrict:
if len(re.findall(args.restrict, container["name"])) == 0:
continue
Expand All @@ -64,29 +70,37 @@ def overcnt(jeez, kctl, pod, args):
else:
state = colourText("SUCCESS", "green")
elif state == "Waiting":
state = colourText(
state + " " + container["state"]["waiting"]["reason"], "grey"
)
reason = container["state"]["waiting"]["reason"]
if reason in failed_containers:
state = colourText(reason, "red")
errmsg = container["lastState"]["terminated"]["message"]
else:
state = colourText(state + " " + reason, "yellow")

cname = colourText(container["name"], "white")

line_new = " {:60} {:>20}".format(cname, state)
print(line_new)

if args.showlog:
outputlog = show_log(kctl, args, container["name"], pod)
if outputlog:
if errmsg:
print()
print(outputlog)
print(errmsg)
print()
else:
outputlog = show_log(kctl, args, container["name"], pod)
if outputlog:
print()
print(outputlog)
print()


def lensc(jeez):
s = 0
for i in jeez:
if (
"waiting" in i["state"]
and i["state"]["waiting"]["reason"] == "ImagePullBackOff"
and i["state"]["waiting"]["reason"] in failed_containers
):
s += 1
if "terminated" in i["state"] and i["state"]["terminated"]["exitCode"] == 0:
Expand All @@ -98,7 +112,7 @@ def hasfailure(jeez):
for i in jeez:
if (
"waiting" in i["state"]
and i["state"]["waiting"]["reason"] == "ImagePullBackOff"
and i["state"]["waiting"]["reason"] in failed_containers
):
return True
if "terminated" in i["state"] and i["state"]["terminated"]["exitCode"] != 0:
Expand Down

0 comments on commit cb47bd6

Please sign in to comment.