-
Notifications
You must be signed in to change notification settings - Fork 301
Proposal: Improve KubernetesClient API Organization for Better Discoverability #1622
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
Comments
It is a long story. the .XXX was introduced in #850, to maintain backward compatibility, I hope the SDK bridge the gap with The SDK no longer depends on |
Thank you for your reply, I have seen LibubernetesGenerator and now all APIs are generated by it, which means we only need to change it. But if we are sure to change it, we can only do it in a major version. |
lets wait for more input from @brendandburns |
Thank you so much |
Is there any way that we could do both for a few releases? fwiw, we have a more modular API structure in the Javascript client and we had a user complain that it was too complicated and they wanted a flat API: kubernetes-client/javascript#2339 So whatever we do here, I'm not sure we're going to make everyone happy :) |
Thank you for your reply. If we implement both methods at the same time, we may need to redefine the implementation of the IKubernetes interface. We provide both methods for users to choose from, or we can keep the previous method on the Kubernetes Object and re-add the method. /// Default client
var kubernetes = new k8s.Kubernetes();
kubernetes.CoreV1.ListNamespacedPodWithHttpMessagesAsync()
/// Add new method
kubernetes.CoreV1.Pods.ListAsync("default");
/// New client
var newKubernetes = new k8s.NewKubernetes();
await newKubernetes.CoreV1.Pods.ListAsync("default"); |
I think that if we do this, it would make sense to make the new modular methods live in their own namespaces (e.g. |
Is this what you mean? public interface ICoreV1
{
public PodClient Pods { get; }
public ServiceClient Services { get; }
}
public class CoreV1Client (IKubernetes kubernetes) : ICoreV1
{
public PodClient Pods { get; }= new PodClient(kubernetes);
}
public class PodClient
{
private readonly IKubernetes _kubernetes;
public PodClient(IKubernetes kubernetes)
{
_kubernetes = kubernertes;
}
Task<List<Pod>> ListAsync(string namespace)
{
/// Implement IKubernetes
}
Task<Pod> GetAsync(string name, string namespace)
{
/// Implement IKubernetes
}
}
public class ServiceClient
{
private readonly IKubernetes kubernetes;
Task<List<Service>> ListAsync(string namespace)
{
/// Implement IKubernetes
}
Task<Service> GetAsync(string name, string namespace)
{
/// Implement IKubernetes
}
}
IKubernetes client = new Kubernetes(config);
var core = new CoreV1Client (client);
core.Pods.ListAsync(namespace) |
Yeah, something like that looks good to me. |
Background & Problem Statement
While working with the KubernetesClient (.NET client library), I noticed that all API methods are currently grouped under a single flat hierarchy. This design makes it challenging to discover specific methods, especially when working with different resource types across API groups/versions.
For example, in the official Go client (client-go), methods are logically organized with clear resource hierarchy:
However, in the current .NET implementation, similar operations lack this intuitive grouping:
This flat structure leads to:
Proposed Improvement
Adopt a hierarchical organization pattern similar to client-go's Clientset structure:
Key Benefits
Improved Discoverability
Methods are grouped by API group/version and resource types
Consistency
Aligns with Kubernetes API structure and client-go patterns
Type Safety
Stronger typing through dedicated resource classes
Scalability
Easier to maintain and extend for future API versions
Implementation Approach
Hierarchical Structure:
Backward Compatibility
Maintain existing flat methods (marked obsolete) while introducing new hierarchy
Resource-Specific Classes
Create dedicated classes for each resource type with relevant operations:
Example Usage
If we agree on this proposal, I would be happy to submit a PR. I'm genuinely enthusiastic about contributing to the community and would love to help implement this improvement.
The text was updated successfully, but these errors were encountered: