kubesql
kubesql copied to clipboard
Don't work if context isn't called "context"
I've installed from cargo and tried query from readme
# RUST_BACKTRACE=1 kubesql --query "SELECT namespace FROM context WHERE pod.status.phase = 'Running'"
thread 'main' panicked at 'Given contexts ["context"] not found in your KUBECONFIG!', src/validator.rs:29:9
stack backtrace:
0: rust_begin_unwind
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:483
1: std::panicking::begin_panic_fmt
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:437
2: kubesql::validator::validate_contexts
3: kubesql::main::{{closure}}
4: std::thread::local::LocalKey<T>::with
5: tokio::park::thread::CachedParkThread::block_on
6: tokio::runtime::thread_pool::ThreadPool::block_on
7: tokio::runtime::Runtime::block_on
8: kubesql::main
It seems application is trying to find context with name context, not using current-context
that is set with kubectl config use-context
~/.kube/config
11 │ contexts:
12 │ - context:
13 │ cluster: XXXXXXXXXXXXXXXXXXX
14 │ user: XXXXXXXXXXXXXXXX
15 │ name: org_name-kube-dev
16 │ - context:
17 │ cluster: YYYYYYYYYYYYYYYYYYYY
18 │ user: YYYYYYYYYYYYYYYYY
19 │ name: org_name-kube-prod
20 │ current-context: org_name-kube-dev
Hey, context
is actually represented your contests[*].name
. In this case, could you please try:
$ kubesql --query "SELECT default FROM org_name-kube-dev WHERE pod.status.phase = 'Running'"
@Dentrax yay, it works!
would be nice if following could work too
SELECT default FROM current-context WHERE pod.status.phase = 'Running'
P.S. strange, - arent's allowed in identifiers in SQL. Would integer expressions be evaluated in your tool? perhaps we should escape "table names" with ` or "
?
I see, hyphens are used all across k8s so you are replacing it before SQL parser.
Hm, I'm still wondering is it possible to use math operators inside where?
@Mart-Bogdan Using context
or current-context
in FROM is cool idea, I think. We have to get current-context from KUBECONFIG. And in case if current-context
is set to org_name-kube-dev
and if we send a query like:
$ SELECT default FROM current-context, org_name-kube-dev WHERE pod.status.phase = 'Running'
...then we should print from only one context since current-context == org_name-kube-dev
.
In my theory, you able to evaluate math operators as long as sqlparser-rs are supported and if field-selectors returns numeric values. But needs some implementations. 🤔
Will not work for EKS contexts as they have a '/' inside the name
current-context: arn:aws:eks:us-east-1:11111111111:cluster/cluster-1
Supporting double-quoted identifiers will help here.
Have no idea how it's done in Rust though, but it looks like even the GenericParser is capable of correctly working with SELECT * FROM "table"