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

how to get apiGroupList use kubernetes-client? #3294

Closed
gewei2000 opened this issue Jul 2, 2021 · 10 comments · Fixed by #3487
Closed

how to get apiGroupList use kubernetes-client? #3294

gewei2000 opened this issue Jul 2, 2021 · 10 comments · Fixed by #3487
Assignees
Labels
component/kubernetes-client Deals with the kubernetes-client feature
Milestone

Comments

@gewei2000
Copy link

how to get apiGroupList use kubernetes-client?

@rohanKanojia
Copy link
Member

Do you mean ApiService? If yes, you can get them like this:

try (KubernetesClient client = new DefaultKubernetesClient()) {
    client.apiServices().list().getItems().stream()
            .map(APIService::getMetadata)
            .map(ObjectMeta::getName)
            .forEach(System.out::println);
}

@gewei2000
Copy link
Author

Do you mean ApiService? If yes, you can get them like this:

try (KubernetesClient client = new DefaultKubernetesClient()) {
    client.apiServices().list().getItems().stream()
            .map(APIService::getMetadata)
            .map(ObjectMeta::getName)
            .forEach(System.out::println);
}

io.fabric8.kubernetes.api.model.APIGroupList,this model

@gewei2000
Copy link
Author

Do you mean ApiService? If yes, you can get them like this:

try (KubernetesClient client = new DefaultKubernetesClient()) {
    client.apiServices().list().getItems().stream()
            .map(APIService::getMetadata)
            .map(ObjectMeta::getName)
            .forEach(System.out::println);
}

I want to get preferred version, but I don't how to get APIGroupList use this client

@rohanKanojia
Copy link
Member

rohanKanojia commented Jul 2, 2021

@gewei2000 : ohk, we're missing support for this. We don't have DSL support for it yet. We'll provide it's support before upcoming release. Internally we're using APIGroup by manually hitting using okhttp:

OkHttpClient httpClient = clientWithOpenShiftOAuthInterceptor(((BaseClient)client).getHttpClient(), config);
try {
Request.Builder requestBuilder = new Request.Builder()
.get()
.url(URLUtils.join(masterUrl.toString(), APIS));
Response response = httpClient.newCall(requestBuilder.build()).execute();
APIGroupList apiGroupList = Serialization.unmarshal(response.body().string(), APIGroupList.class);

@rohanKanojia rohanKanojia added feature component/kubernetes-client Deals with the kubernetes-client labels Jul 2, 2021
@manusa
Copy link
Member

manusa commented Jul 5, 2021

This would be really useful to get the cluster available API groups and API resources:

$ kubectl proxy --port=8081
$ curl localhost:8081/apis
# For any of the available groups
$ curl localhost:8081/apis/apps/v1

The response for the APIResourceList provides the required information to interact with any group/resource in K8s. This is really useful when we need to deal with Custom Resources and we don't have a definition (CRD) for them.
An improvement for the GenericKubernetesResource operations DSL method, might include querying these endpoints and then retrieving the necessary data to infer the plural and scope of the resource.

Relates to #2929

@shawkins
Copy link
Contributor

shawkins commented Aug 11, 2021

I could take this for 5.8. ApiGroup is now annotated appropriately, so it will just take a couple of other changes to expose it via the dsl.

@manusa
Copy link
Member

manusa commented Aug 11, 2021

Take into account that this is not really a resource, just an additional HTTP endpoint exposed by Kubernetes.

So not the same operations that apply to the rest of resources apply for this. It makes sense in the scope of an API group (e.g. client.apps() or client.network()).

So if API groups and versions could be interfaced appropriately should be easy.

@manusa
Copy link
Member

manusa commented Aug 11, 2021

But maybe as a first approach, something to be able to request information for a specific group, version is what we really want here.

@shawkins
Copy link
Contributor

Sure, I was initially thinking that it would be something like getting a handler for the ApiGroup / ApiGroupList and exposing only the list operation. But looking at it more, that doesn't work so well with the expectations in base operation. It would be simpler to move the isAdaptable logic into a
ApiGroupLIst KubernetesClient.getApiGroups() method. and/or support getting a single one as well.

@manusa
Copy link
Member

manusa commented Aug 12, 2021

ApiGroupLIst KubernetesClient.getApiGroups() method. and/or support getting a single one as well.

Yes, so basically we are looking at what was exposed in my comment, get a list of the available groups and then for each group, be able to retrieve the available resources with their required info (plural, scope, etc.)

These new methods can be then used by the GenericResource loader to perform operations on any available resource (as discussed #3392 (comment) & #3392 (comment)).

Some pseudo-logic:

  1. Check in client cache if a given group exists
  1. Check in client cache if a given resource (group+version+kind) exists
  1. Use the information from the cached ApiResource(s) to determine the required plural and scope for the GenericKubernetesResourceOperationsImpl

shawkins added a commit to shawkins/kubernetes-client that referenced this issue Aug 14, 2021
also trying to consolidate existing logic about openshift adapting
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Aug 14, 2021
also trying to consolidate existing logic about openshift adapting
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Aug 14, 2021
also trying to consolidate existing logic about openshift adapting
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Aug 31, 2021
also trying to consolidate existing logic about openshift adapting
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Aug 31, 2021
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Aug 31, 2021
also trying to consolidate existing logic about openshift adapting
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Aug 31, 2021
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Sep 1, 2021
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Sep 14, 2021
manusa pushed a commit to manusa/kubernetes-client that referenced this issue Sep 22, 2021
@manusa manusa added this to the 5.9.0 milestone Sep 23, 2021
manusa pushed a commit to manusa/kubernetes-client that referenced this issue Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/kubernetes-client Deals with the kubernetes-client feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants