-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubectl-url-handler.lnav
executable file
·38 lines (32 loc) · 1.93 KB
/
kubectl-url-handler.lnav
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
#
# @synopsis: kubectl-url-handler
# @description: Internal script to handle opening kubectl/oc URLs
#
;SELECT jget(url, '/scheme') AS kubectl_scheme,
jget(url, '/host') AS kubectl_hostname,
jget(url, '/path') AS kubectl_path,
jget(url, '/parameters/all-containers') AS kubectl_param_all_containers,
jget(url, '/parameters/n') AS kubectl_param_n,
jget(url, '/parameters/namespace') AS kubectl_param_namespace,
jget(url, '/parameters/max-log-requests') AS kubectl_param_max_log_requests
FROM (SELECT parse_url($1) AS url)
;SELECT $kubectl_scheme AS executable_program
# exploit NULL behaviour to produce NULL results
;SELECT '--all-containers=' || coalesce('true', $kubectl_param_all_containers) AS all_containers
;SELECT '--namespace=' || coalesce($kubectl_param_n, $kubectl_param_namespace) AS namespace
;SELECT '--max-log-requests=' || $kubectl_param_max_log_requests AS max_log_requests
;SELECT ltrim($kubectl_path, '/') AS payload
;SELECT CASE
$kubectl_hostname
WHEN 'resource' THEN (
-- printf(':sh bash -c "echo user:%s process:%s payload:%s namespace:%s max-log-requests:%s all-containers:%s"', $kubectl_username, $executable_program, $payload, $namespace, $max_log_requests, $all_containers)
printf(':sh %s logs --follow %s %s %s %s', $executable_program, $all_containers, $namespace, $max_log_requests, $payload)
)
WHEN 'selector' THEN (
-- printf(':sh bash -c "echo user:%s process:%s payload:%s namespace:%s max-log-requests:%s all-containers:%s"', $kubectl_username, $executable_program, $payload, $namespace, $max_log_requests, $all_containers)
printf(':sh %s logs --follow %s %s %s --selector=%s', $executable_program, $all_containers, $namespace, $max_log_requests, $payload)
)
ELSE
printf(':alt-msg "%s" not understood as a query strategy, ignoring', $kubectl_hostname)
END AS cmd
:eval ${cmd}