-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathklog
More file actions
executable file
·34 lines (25 loc) · 846 Bytes
/
klog
File metadata and controls
executable file
·34 lines (25 loc) · 846 Bytes
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
#!/usr/bin/env python3
"""klog - follow logs for a pod matching a regex.
Searches all namespaces unless -n is given. Extra flags pass through
to kubectl logs.
Usage: klog [-n NAMESPACE] <pod-regex> [kubectl logs options...]
Examples:
klog nginx
klog frontend --tail=100
klog myapp -n my-namespace
"""
import argparse
import os
import sys
from k8s_lib import print_info, resolve_pod
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('-n', '--namespace')
known, remaining = parser.parse_known_args()
if not remaining:
print(__doc__.strip(), file=sys.stderr)
sys.exit(1)
pod_regex = remaining.pop(0)
namespace, pod = resolve_pod(pod_regex, known.namespace, case_insensitive=True)
cmd = ['kubectl', '-n', namespace, 'logs', pod, '-f'] + remaining
print_info(f"→ {' '.join(cmd)}")
os.execvp('kubectl', cmd)