-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkdes
More file actions
executable file
·82 lines (62 loc) · 1.95 KB
/
kdes
File metadata and controls
executable file
·82 lines (62 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
"""
kdes — describe a pod selected by regex
Usage:
kdes [-N NAMESPACE] <pod-regex> [kubectl describe args...]
Examples:
kdes app
kdes -N production app
kdes app --show-events
"""
import argparse
import sys
# Import utilities from the same directory
from k8s_lib import print_error, print_info, resolve_pod, run_command
def parse_args() -> argparse.Namespace:
"""Parse command line arguments."""
parser = argparse.ArgumentParser(
description="Describe a pod selected by regex",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
kdes app
kdes -N production app
kdes app --show-events
"""
)
parser.add_argument(
'-N', '--namespace',
help='Kubernetes namespace (optional)'
)
parser.add_argument(
'pod_regex',
help='ERE matched against pod names (single pod must match)'
)
parser.add_argument(
'kubectl_args',
nargs=argparse.REMAINDER,
help='Additional arguments to pass to kubectl describe'
)
return parser.parse_args()
def main() -> None:
"""Main function."""
args = parse_args()
try:
# Resolve the pod, discovering namespace when not specified
namespace, pod_name = resolve_pod(args.pod_regex, args.namespace)
# Build kubectl describe command
cmd = ['kubectl', '-n', namespace, 'describe', 'pod', pod_name]
# Add any additional kubectl describe arguments
if args.kubectl_args:
cmd.extend(args.kubectl_args)
print_info(f"Describing pod: {namespace}/{pod_name}")
# Execute the command
run_command(cmd, capture_output=False, check=False)
except KeyboardInterrupt:
print("\nInterrupted by user", file=sys.stderr)
sys.exit(1)
except Exception as e:
print_error(str(e))
sys.exit(1)
if __name__ == '__main__':
main()