Skip to content

Commit

Permalink
Merge pull request #305 from camptocamp/no-error
Browse files Browse the repository at this point in the history
Logs never returns an error code
  • Loading branch information
sbrunner authored Oct 22, 2021
2 parents 24d89b4 + 621f623 commit a8da725
Showing 1 changed file with 45 additions and 41 deletions.
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

0 comments on commit a8da725

Please sign in to comment.