-
Notifications
You must be signed in to change notification settings - Fork 167
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 multiple apis, detect kind/apiVersion #241
Support multiple apis, detect kind/apiVersion #241
Conversation
These classes are responsible for querying apis and discovering api entities.
Supports lookup by apiVersion/kind or class
Use Entity instances for method generation.
@moolitayer @cben please review. |
@danajp can you please post an example showing new/modified interfaces this PR will expose |
Sure, here you go @moolitayer, I'm not sure all of these actually work yet. config = Kubeclient::Config.read('/home/dana/.kube/config')
# --- constructor changes --------------------------------------------
# older interface, supports /api/v1 only by default
core_client = Kubeclient::Client.new(
config.context.api_endpoint,
:ssl_options => config.context.ssl_options,
:auth_options => config.context.auth_options
)
# older interface, supports only /apis/batch/v1
batch_client = Kubeclient::Client.new(
config.context.api_endpoint + '/apis',
'batch/v1',
:ssl_options => config.context.ssl_options,
:auth_options => config.context.auth_options
)
# new interface, supports all apis in a single instance
all_client = Kubeclient::Client.new(
config.context.api_endpoint,
nil,
:ssl_options => config.context.ssl_options,
:auth_options => config.context.auth_options
)
# --- entity CRUD changes --------------------------------------------
service = Kubeclient::Resource.new
service.kind = 'Service'
service.apiVersion = 'v1'
service.metadata = {}
service.metadata.name = 'foo'
service.metadata.namespace = 'default'
service.spec = {}
service.spec.ports = [
{ :port => 3000, :targetPort => 'http-server', :protocol => 'TCP' }
]
# old api unchanged
all_client.create_service(service)
all_client.update_service(service)
all_client.patch_service(service.metadata.name, service, service.metadata.namespace)
all_client.delete_service(service.metadata.name, service.metadata.namespace)
# new api
all_client.create(service)
all_client.update(service)
all_client.patch(service)
all_client.delete(service) |
I've been seeing lots of code that would benefit from having an interface addition of:
@cben @abonas @simon3z would you tentatively agree to this as an interface ADDITION ? If so maybe we can start off with a PR doing only that? |
Some comments from briefly looking at this PR:
|
Closing this PR as we've pretty much abandoned this approach in our project in favor of something similar to #332. We've got a wrapper around kubeclient that implements a method like this: def get_client(api_version, kind)
# ...
end And then 99% of the time, we've already got a Resource instance that we use to generate the method names: resource = Kubeclient::Resource.new(:kind => "Service", :apiVersion => "v1")
# ...
KubeclientWrapper
.get_client(resource.apiVersion, resource.kind)
.send("create_#{resource.kind.underscore}") |
EDIT: overview of alternatives: #208 (comment)
Fixes #208
This is WIP. There are pretty much no tests. I'm pretty sure it doesn't actually work. At this point I'm just looking for feedback on the approach I'm taking.
This PR does a couple things:
It supports all the kubernetes apiserver apis in a single
Kubeclient::Client
if you do not pass an api version to the constructor.We can support backwards compatibility by doing the following:
It adds new
create
,update
,patch
anddelete
methods which accept aKubeclient::Resource
instance withapiVersion
andkind
keys and uses those to determine which api group and resource to use to create/update/delete the entity.To get there, the api discovery code has been refactored to support this. The new classes are
Kubeclient::Common::Apis
- handles discovery of the api groupsKubeclient::Common::Api
- a single api group, handles discovery of entities in that groupKubeclient::Common::Entity
- a single api entity. This replaces theOpenStructs
that were used to store entities before