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

generic kubernetes resource improvements #3404

Closed
lburgazzoli opened this issue Aug 13, 2021 · 5 comments · Fixed by #3525
Closed

generic kubernetes resource improvements #3404

lburgazzoli opened this issue Aug 13, 2021 · 5 comments · Fixed by #3525
Assignees

Comments

@lburgazzoli
Copy link
Contributor

To make it easy to deal with generic kubernetes resources, it would be nice to have:

  • support for HasMetadata resources out of the box
  • support for automatic creation of the related ResourceDefinitionContext

As today to implement such logic, I have the following utility method in place:

void createOrReplace(HasMetadata resource) {
    var generic = Serialization.jsonMapper().convertValue(resource, GenericKubernetesResource.class);
    var context = asResourceDefinitionContext(resource);
    
    kubernetesClient
        .genericKubernetesResources(context)
        .createOrReplace(generic)
}

It would be nice to be able to do something like:

void createOrReplace(HasMetadata resource) {    
    kubernetesClient
        .genericKubernetesResources()
        .createOrReplace(resource)
}
@shawkins
Copy link
Contributor

shawkins commented Aug 13, 2021

If your HasMetadata is properly annotated you can now do:

kubernetesClient.resources(resource.class).createOrReplace(resource);

Or

kubernetesClient.resource(resource).createOrReplace();

The latter one though is a slightly different set of apis, which I'm trying to align with Resource #3364

@lburgazzoli
Copy link
Contributor Author

Does this work also if the HasMetadata is an instance of GenericKubernetesResource ?

@shawkins
Copy link
Contributor

Does this work also if the HasMetadata is an instance of GenericKubernetesResource ?

With just the base type, no. The longer answer is that it's eventually possible for kubernetesClient.resource(resource) to use the resource to get the groupVersion and lookup the additional metadata if needed. I was going to try and start that with #3294

@shawkins shawkins self-assigned this Oct 8, 2021
@shawkins
Copy link
Contributor

shawkins commented Oct 8, 2021

I'll see if I can get the full generic logic in 5.9 or shortly thereafter.

shawkins added a commit to shawkins/kubernetes-client that referenced this issue Oct 11, 2021
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Oct 11, 2021
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Oct 11, 2021
@shawkins shawkins linked a pull request Oct 11, 2021 that will close this issue
11 tasks
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

Successfully merging a pull request may close this issue.

3 participants