java icon indicating copy to clipboard operation
java copied to clipboard

Can CustomObjectsApi support all kind of kubernetesObject?

Open simsnow opened this issue 2 years ago • 7 comments

We have many project use k8s-sdk controll the cluster, I am writing a self-sdk for our projects, I want to use CustomObjectsApi to process all kind of kubernetesObject, I found it hard code "/apis/{group}/{version}/", some "/api/{group}/{version}" not suitable for use,

I will hack it by "if group is empty use api, else use apis"

is that right, any other point that may happen?

simsnow avatar Aug 17 '23 09:08 simsnow

Here is the link to CustomObjectsApi. Maybe i can give a patch to make it more compatible...

https://github.com/kubernetes-client/java/blob/master/kubernetes/src/main/java/io/kubernetes/client/openapi/apis/CustomObjectsApi.java#L80

simsnow avatar Aug 17 '23 09:08 simsnow

"/api/{group}/{version}"

the "/api" prefix only applies to those oldest legacy API such as pod, node. custom resources will be automatically registered under "/apis". you can also use "DynamicKuberentesClient" to build a path agnostic client

yue9944882 avatar Aug 17 '23 17:08 yue9944882

@yue9944882 Thank you for help. I can't found a method like "listClusterCustomObjectCall" in DynamicKubernetesApi.

My basic business is "render a yaml, load the yaml, create some kubeObjects, watch the status, delete the kubeObjects"

Here is my code using informer to watch status

        CustomObjectsApi customObjectsApi = new CustomObjectsApi(client);
        GroupVersionResource groupVersionResource = ModelMapper.getGroupVersionResourceByClass(getApiType());
        SharedIndexInformer<T> informer = factory.sharedIndexInformerFor((CallGeneratorParams params) -> {
            return customObjectsApi.listClusterCustomObjectCall(groupVersionResource.getGroup(), groupVersionResource.getVersion(),
                    groupVersionResource.getResource(), null, null, null, null, null, null, params.resourceVersion, null, params.timeoutSeconds,
                    params.watch, null);
        }, getApiType(), getListType());

        informer.addEventHandler(new ResourceEventHandler<T>() {...});

simsnow avatar Aug 18 '23 01:08 simsnow

DynamicKubernetesApi features a private call that does what you want:

https://github.com/kubernetes-client/java/blob/master/util/src/main/java/io/kubernetes/client/util/generic/GenericKubernetesApi.java#L627

@yue9944882 we should consider making that public so that people can watch dynamic objects?

brendandburns avatar Aug 21 '23 15:08 brendandburns

hey, I am use customObject too. And I found that patchNamespacedCustomObject is only support json.

public okhttp3.Call patchNamespacedCustomObjectCall {
...
final String[] localVarContentTypes = {
      "application/json-patch+json", "application/merge-patch+json"
    };
    final String localVarContentType =
        localVarApiClient.selectHeaderContentType(localVarContentTypes);
    localVarHeaderParams.put("Content-Type", localVarContentType);
...
}
public String selectHeaderContentType(String[] contentTypes) {
    if (contentTypes.length == 0 || contentTypes[0].equals("*/*")) {
      return "application/json";
    }
    for (String contentType : contentTypes) {
      if (isJsonMime(contentType)) {
        return contentType;
      }
    }
    return contentTypes[0];
  }

selectHeaderContentType will return directly at the first parmeter. right?

InfiniteZh avatar Aug 31 '23 07:08 InfiniteZh

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Jan 27 '24 09:01 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Feb 26 '24 10:02 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-triage-robot avatar Mar 27 '24 11:03 k8s-triage-robot

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar Mar 27 '24 11:03 k8s-ci-robot