Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't work if context isn't called "context" #2

Open
Mart-Bogdan opened this issue Apr 23, 2021 · 5 comments
Open

Don't work if context isn't called "context" #2

Mart-Bogdan opened this issue Apr 23, 2021 · 5 comments

Comments

@Mart-Bogdan
Copy link

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
@Dentrax
Copy link
Owner

Dentrax commented Apr 23, 2021

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'"

@Mart-Bogdan Mart-Bogdan changed the title Dont work if context isn't called "context" Don't work if context isn't called "context" Apr 23, 2021
@Mart-Bogdan
Copy link
Author

@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 " ?

@Mart-Bogdan
Copy link
Author

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?

@Dentrax
Copy link
Owner

Dentrax commented Apr 23, 2021

@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. 🤔

@pkit
Copy link

pkit commented Sep 2, 2021

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants