Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/SK-608 | Update kube controller app status logic #2

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions event_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
USERNAME = os.environ.get("EVENT_LISTENER_USERNAME", None)
PASSWORD = os.environ.get("EVENT_LISTENER_PASSWORD", None)

K8S_STATUS_MAP = {
"CrashLoopBackOff": "Error",
"Completed": "Retrying...",
"ContainerCreating": "Created",
"PodInitializing": "Pending",
}

token = None

# Number of retries
Expand Down Expand Up @@ -128,8 +135,10 @@ def init_event_listener():


def get_status(pod):
print("Getting status...")

"""
Returns the status of a pod by looping through each container
and checking the status.
"""
container_statuses = pod.status.container_statuses

if container_statuses is not None:
Expand All @@ -140,23 +149,27 @@ def get_status(pod):
terminated = state.terminated

if terminated is not None:
return terminated.reason
reason = terminated.reason
return mapped_status(reason)

waiting = state.waiting

if waiting is not None:
return waiting.reason

running = state.running
reason = waiting.reason
return mapped_status(reason)
else:
running = state.running
ready = container_status.ready
if running and ready:
return "Running"
else:
return "Pending"

if running is not None:
return "Running"
return pod.status.phase

print("Last state not found.")
else:
print("Container statuses not found.")

return pod.status.phase
def mapped_status(reason: str) -> str:
return K8S_STATUS_MAP.get(reason, reason)


def post(url, data):
Expand Down