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 custom resources #69
Comments
+1, the ability to list custom resources would be excellent and expand the use cases for this package significantly. |
@jinnovation I agree! I thought of using a shared informer to achieve this. It is a matter of free time. |
It's worth noting here that, at least for the problem of a) listing which resource types are available on a given cluster, and b) retrieving resources of a given resource type, a custom Go backend using the shared informer pattern provided by the Kubernetes client package is arguably unnecessary. For listing resource types, we have: kubectl api-resources For fetching resources of arbitrary type kubectl get t There would naturally be necessary preliminary work to do in the package as a whole to genericize our handling of resources such that hardcodes like those here are no longer present or necessary. However, in terms of raw primitives necessary to enable the package to know of, retrieve, and display rudimentary information about CRDs, I believe we have the necessary primitives in |
To that effect, I've taken the liberty of renaming this issue to—in my opinion—more accurately reflect the body of work in question. Continuing to call this issue "Dynamic client" would amount to putting the cart before the horse, i.e. describing a solution without first outlining the problem we're trying to solve. |
@jinnovation Yes, we should make it generic so that we can remove some of the hard codings as you mentioned. |
Relates to #69. Currently, we define one function for `get`ting all entities of a given resource type, for each of a finite set of resources, e.g. `k8s-kubectl-get-{pods, nodes, ...}`. All of these functions are identical save for the resource type that they retrieve. As such, we generalize to a single implementation—`k8s-kubectl-get`—that accepts the resource type name and performs the `get` accordingly. By extension, we rewire all call sites that assume the existence of per-type `get` functions to use the genericized counterpart—most notably the `kubernetes-state-define-refreshers` macro, which currently literally expects functions of those naming pattern to exist. Similarly, we consolidate unit tests and, finally, remove the granular, per-type `get` functions.
Relates to #69. Currently, we define one function for `delete`-ing all entities of a given resource type, for each of a finite set of resources, e.g. `k8s-kubectl-delete-{pods, nodes, ...}`. All of these functions are identical save for the resource type that they retrieve. As such, we generalize to a single implementation—`k8s-kubectl-delete`—that accepts the resource type name and performs the `delete` accordingly. We additionally clean up unit tests and, finally, remove the granular, per-type `get` functions. In particular, with regards to unit tests, we observe that, once the resource type name is abstracted away, there's no practical reason to have one test case for each resource type. As such, rather than consolidate all per-type test cases into a single test function, we simply keep one case for each of the two scenarios "delete success" and "delete fail," and remove the rest of the test functions as superfluous.
Relates to kubernetes-el#69. Currently, retrieval of resource manifests from package state is handled through resource-specific getters, generated via macro expansion, e.g. `kubernetes-state-pods` for fetching pods and so on. This design is extremely cumbersome and impedes genericization of resource type handling across the package. For instance, consider the scenario where we want to fetch the state of some resource `r` from package state. Doing so currently requires interpolation and redirection gymnastics akin to the following: ```emacs-lisp (funcall (intern (format "kubernetes-state-%s" 'r)) (kubernetes-state)) ``` We can see this pattern throughout the package in its current form. This PR extracts the "backbone" of the generated getters' logic to a genericized analogue: `(kubernetes-state--get STATE TYPE)`. With this change, in the future, the behavior demonstrated above can be simplified to: ```emacs-lisp (kubernetes-state--get (kubernetes-state) 'r) ``` This PR leaves the current behavior intact, meaning that all state access continues to go through the generated getter functions. However, the fact that those generated getters now defer to `kubernetes-state--get` paves the way for us to gradually phase out the generated getters in favor of, at each call site, simply calling `kubernetes-state--get` directly.
Relates to #69. Currently, retrieval of resource manifests from package state is handled through resource-specific getters, generated via macro expansion, e.g. `kubernetes-state-pods` for fetching pods and so on. This design is extremely cumbersome and impedes genericization of resource type handling across the package. For instance, consider the scenario where we want to fetch the state of some resource `r` from package state. Doing so currently requires interpolation and redirection gymnastics akin to the following: ```emacs-lisp (funcall (intern (format "kubernetes-state-%s" 'r)) (kubernetes-state)) ``` We can see this pattern throughout the package in its current form. This PR extracts the "backbone" of the generated getters' logic to a genericized analogue: `(kubernetes-state--get STATE TYPE)`. With this change, in the future, the behavior demonstrated above can be simplified to: ```emacs-lisp (kubernetes-state--get (kubernetes-state) 'r) ``` This PR leaves the current behavior intact, meaning that all state access continues to go through the generated getter functions. However, the fact that those generated getters now defer to `kubernetes-state--get` paves the way for us to gradually phase out the generated getters in favor of, at each call site, simply calling `kubernetes-state--get` directly.
Relates to #69. This PR removes the resource-specific getters for "marked" default k8s resources, e.g. pods and deployments, in favor of the generic counterpart introduced in #200. ## Side Note As we move forward with resource-handling genericization, it might benefit us to likewise look into a more generic handling of marked status for resources, rather than introduce one new field in the state alist for each resource. We can have that discussion elsewhere.
Relates to kubernetes-el#69. This PR extracts the core of the resource-specific `kubernetes-<resource>-refresh-now` functions into the resource-generic `kubernetes-state--refresh-now` function. This function represents the "core" of the function template used to generate the resource-specific force-refresh functions. This PR leaves the resource-specific refresh-now functions in place, re-implementing them as wrappers around the new resource-generic version. The resource-specific functions have test coverage, which provides a vote of confidence as to the safety of this change. We'll leave sunsetting of the resource-specific functions' use to subsequent PRs.
Relates to #69. This PR extracts the core of the resource-specific `kubernetes-<resource>-refresh-now` functions into the resource-generic `kubernetes-state--refresh-now` function. This function represents the "core" of the function template used to generate the resource-specific force-refresh functions. This PR leaves the resource-specific refresh-now functions in place, re-implementing them as wrappers around the new resource-generic version. The resource-specific functions have test coverage, which provides a vote of confidence as to the safety of this change. We'll leave sunsetting of the resource-specific functions' use to subsequent PRs.
I've created a milestone to account for all the disparate tasks that need to be taken care of in order to effectively support CRDs. |
This commit expands our comparison of Kele against `kubernetes-el` to call out the latter's incomplete support of the core API (kubernetes-el/kubernetes-el#306) **in addition** to lack of support for custom resources (kubernetes-el/kubernetes-el#69).
It's now possible to build a Kubernetes client that learns of all possible resource types from the API, and also is able to access arbitrary resource types by name without a pre-compiled model for the types.
Would it be possible to do the same in kubernetes-el? I'd like to be able to list custom resources.
The text was updated successfully, but these errors were encountered: