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

Logs never returns an error code #305

Merged
merged 1 commit into from
Oct 22, 2021
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
86 changes: 45 additions & 41 deletions c2cciutils/scripts/k8s/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,54 +20,58 @@ def main() -> None:
if args.namespace:
subprocess.run(["kubectl", "config", "set-context", "--current", "--namespace=default"], check=True)

_print("::group::Events")
subprocess.run(["kubectl", "get", "events"], check=True)
_print("::endgroup::")
try:
_print("::group::Events")
subprocess.run(["kubectl", "get", "events"], check=False)
_print("::endgroup::")

_print("::group::Deployments")
subprocess.run(["kubectl", "get", "deployments", "--output=wide"], check=True)
_print("::endgroup::")
_print("::group::Deployments")
subprocess.run(["kubectl", "get", "deployments", "--output=wide"], check=False)
_print("::endgroup::")

_print("::group::Pods")
subprocess.run(["kubectl", "get", "pods", "--output=wide"], check=True)
_print("::endgroup::")
_print("::group::Pods")
subprocess.run(["kubectl", "get", "pods", "--output=wide"], check=False)
_print("::endgroup::")

for name in (
subprocess.run(["kubectl", "get", "pods", "--output=name"], check=True, stdout=subprocess.PIPE)
.stdout.decode()
.split("\n")
):
if name:
_print(f"::group::{name}: Describe")
subprocess.run(["kubectl", "describe", name], check=True)
_print("::endgroup::")
for name in (
subprocess.run(["kubectl", "get", "pods", "--output=name"], check=True, stdout=subprocess.PIPE)
.stdout.decode()
.split("\n")
):
if name:
_print(f"::group::{name}: Describe")
subprocess.run(["kubectl", "describe", name], check=False)
_print("::endgroup::")

for container in (
subprocess.run(
["kubectl", "get", name, "--output=jsonpath={.spec.initContainers[*].name}"],
check=True,
stdout=subprocess.PIPE,
)
.stdout.decode()
.split()
):
if name:
_print(f"::group::{name} {container}: Logs")
subprocess.run(["kubectl", "logs", name, container], check=False)
_print("::endgroup::")

for container in (
subprocess.run(
["kubectl", "get", name, "--output=jsonpath={.spec.initContainers[*].name}"],
check=True,
stdout=subprocess.PIPE,
)
.stdout.decode()
.split()
):
if name:
for container in (
subprocess.run(
["kubectl", "get", name, "--output=jsonpath={.spec.containers[*].name}"],
check=True,
stdout=subprocess.PIPE,
)
.stdout.decode()
.split()
):
_print(f"::group::{name} {container}: Logs")
subprocess.run(["kubectl", "logs", name, container], check=False)
_print("::endgroup::")

for container in (
subprocess.run(
["kubectl", "get", name, "--output=jsonpath={.spec.containers[*].name}"],
check=True,
stdout=subprocess.PIPE,
)
.stdout.decode()
.split()
):
_print(f"::group::{name} {container}: Logs")
subprocess.run(["kubectl", "logs", name, container], check=False)
_print("::endgroup::")
except subprocess.CalledProcessError as exception:
# No exit error
print(exception)


if __name__ == "__main__":
Expand Down