-
Notifications
You must be signed in to change notification settings - Fork 104
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
Enhancement: Able to get controller-runtime Client from the Resources #146
Comments
Hi @dmvolod |
Hi @vladimirvivien |
@dmvolod Is this not what you are looking ? e2e-framework/klient/k8s/resources/resources.go Lines 51 to 70 in e93ce38
Are you looking for a way to access the |
Assess("Do Something", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
r, err := resources.New(c.Client().RESTConfig())
if err != nil {
t.Fail()
}
var sc v1.StorageClass
err = r.Get(ctx, "test", "", &sc)
if err != nil && errors.IsNotFound(err) {
t.Skip("No tests are there is missing storage class")
}
if sc.AllowVolumeExpansion == nil || !*sc.AllowVolumeExpansion {
t.Skip("Skipping test as the volume expansion is not allowed")
}
// Do something
return ctx
}). @dmvolod What you are looking for can be achieved this way too. |
Thanks, @harshanarayana , I know how to do this, but we have a dozens of functions and don't won't to repeate code of them in the tests instead of just provider one parameter with the cr.Client |
I see. So
this is what you are looking for ? |
Yes, exactly, @harshanarayana , missed your first comment. |
@dmvolod can you provide a code snippet of what you are doing with the controller-client once you get it? I ask because that can be useful functionality worth adding directly in the framework itself. How are you using the client to detect StorageClass enabled ? Or is it the fact that you have existing code that you don't want to change and exposing the client would make integration easier ? |
In our kubernetes operator, we use a dedicated struct to provide all parameters to iterate with the k8s cluster. One of these parameters is controller-runtime Client cr client.Client:
And as @dmvolod said before we also have a lot of functions (based on native k8s controller-runtime client functions like Get(), List() etc.). And also we have a method to validate StorageClass Volume Expansion:
Thus, to test this (and another) method in our e2e tests we have to re-implement them all in accordance with your klient.Klient client instead if just import our package and use it as it is. Much better would be have helper function something like @dmvolod mention above:
|
I think this is a good suggestion and exposing the controller-runtime client does not break the current API. |
/assign |
@vladimirvivien @Lxrdknows77 @dmvolod I have a draft PR with two ways of fetching the controller runtime client. TPAL when time permits. |
Thanks for the implementetion, @harshanarayana. Is NewControllerRuntimeClient just an option to directly get a client without using *Resources? |
@Lxrdknows77 Yes and also lets you inject your own custom |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
@harshanarayana Will you fix it or I can recreate PR? |
@Lxrdknows77 Sorry, this one totally skipped my list of TODO items. Please feel free to recreate the PR. If you can wait until end of the week, I will have the PR ready |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
/remove-lifecycle rotten |
@harshanarayana Have you gotten a chance to finalize this so we can merge? |
@vladimirvivien I have already update the PR #156 with some of the comments addressed. |
In most of the cases, we need to get and utilize controller-runtime Client internally for the intermediate functions
It would be nice to have a functions GetClient() inside the
klient/k8s/resources/resources.go
to get controller-runtime Client for this case.Alternatively, we could probably have a helper function in the
klient
package returning Client asThe text was updated successfully, but these errors were encountered: