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

support to group API #463

Closed
glasswalk3r opened this issue Sep 8, 2020 · 2 comments
Closed

support to group API #463

glasswalk3r opened this issue Sep 8, 2020 · 2 comments

Comments

@glasswalk3r
Copy link

glasswalk3r commented Sep 8, 2020

Hello there,

I've being looking for a way to list/describe resources like ingresses, hpa and deployments, but can't find a way to do that using kubeclient.

I found some older issues mentioned what seems to be a confirmation that such API Groups are supported by this project, but couldn't find any example and/or documentation mentioning how to do that:

I even gave a try using pry, noticed that some methods are defined at runtime (after sending a get_pods, for example), but nothing related those API Groups that I already mentioned.

Am I missing something here, or this support is not complete at the moment?

That's the code I'm using for testing:

config = Kubeclient::Config.read("#{ENV['HOME']}/.kube/config")
context = config.context

client = Kubeclient::Client.new(
  context.api_endpoint,
  'v1',
  ssl_options: context.ssl_options,
  auth_options: context.auth_options
)

Thanks in advance,

Alceu

@glasswalk3r
Copy link
Author

glasswalk3r commented Sep 8, 2020

After reviewing more issues like that and some debugging configuration for restclient (RESTCLIENT_LOG=stdout bundle exec ruby test.rb), I could get a working example:

# frozen_string_literal: true

require 'kubeclient'

def k8s_client
  config = Kubeclient::Config.read("#{ENV['HOME']}/.kube/config")
  context = config.context
  puts context.api_endpoint

  Kubeclient::Client.new(
    "#{context.api_endpoint}/apis/extensions",
    'v1beta1',
    ssl_options: context.ssl_options,
    auth_options: context.auth_options
  )
end

client = k8s_client
puts client.get_ingresses(namespace: 'qa')

Does that mean that I need to create a client instance to be able to execute queries with the "old" API and then create a new instance to query the "v1beta1"?

Or is there any shortcut for configure that on the fly (I saw that the client instance has an api Hash, not sure if it's advisable to change anything directly).

@cben
Copy link
Collaborator

cben commented Sep 9, 2020

Yes, you need a separate client object per API group that you want to use.

See #208 (comment) for overview of various proposals we have to improve this in the future.

BTW, extensions v1beta1 is deprecated:
https://kubernetes.io/blog/2019/07/18/api-deprecations-in-1-16/ lists new API groups that replace it, with version ranges when you can/must switch.

@cben cben closed this as completed Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants