-
Notifications
You must be signed in to change notification settings - Fork 261
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
Update k8s dependencies to v0.20.7 #1344
Changes from all commits
613a3c2
fd9f0d2
e4cb05f
482f036
a0ce056
3b13777
ce625c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,26 +15,30 @@ | |
package fake | ||
|
||
import ( | ||
v1 "k8s.io/api/core/v1" | ||
"context" | ||
|
||
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
dynamicfake "k8s.io/client-go/dynamic/fake" | ||
|
||
"knative.dev/client/pkg/dynamic" | ||
|
||
eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1" | ||
messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1" | ||
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1" | ||
sourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2" | ||
dynamicclientfake "knative.dev/pkg/injection/clients/dynamicclient/fake" | ||
servingv1 "knative.dev/serving/pkg/apis/serving/v1" | ||
) | ||
|
||
// CreateFakeKnDynamicClient gives you a dynamic client for testing containing the given objects. | ||
func CreateFakeKnDynamicClient(testNamespace string, objects ...runtime.Object) dynamic.KnDynamicClient { | ||
scheme := runtime.NewScheme() | ||
scheme.AddKnownTypeWithName(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Service"}, &v1.Service{}) | ||
scheme.AddKnownTypeWithName(schema.GroupVersionKind{Group: "serving.knative.dev", Version: "v1", Kind: "Service"}, &servingv1.Service{}) | ||
scheme.AddKnownTypeWithName(schema.GroupVersionKind{Group: "serving.knative.dev", Version: "v1", Kind: "Route"}, &servingv1.Route{}) | ||
scheme.AddKnownTypeWithName(schema.GroupVersionKind{Group: "eventing.knative.dev", Version: "v1", Kind: "Broker"}, &eventingv1.Broker{}) | ||
scheme.AddKnownTypeWithName(schema.GroupVersionKind{Group: "eventing.knative.dev", Version: "v1", Kind: "Subscription"}, &messagingv1.Subscription{}) | ||
scheme.AddKnownTypeWithName(schema.GroupVersionKind{Group: "messaging.knative.dev", Version: "v1", Kind: "Channel"}, &messagingv1.Channel{}) | ||
client := dynamicfake.NewSimpleDynamicClient(scheme, objects...) | ||
return dynamic.NewKnDynamicClient(client, testNamespace) | ||
servingv1.AddToScheme(scheme) | ||
eventingv1.AddToScheme(scheme) | ||
messagingv1.AddToScheme(scheme) | ||
sourcesv1.AddToScheme(scheme) | ||
sourcesv1beta2.AddToScheme(scheme) | ||
apiextensionsv1.AddToScheme(scheme) | ||
_, dynamicClient := dynamicclientfake.With(context.TODO(), scheme, objects...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dprotaso @navidshaikh wdyt about the above change? It works for our test setup, I've gone through and changed various initialization of fake dynamic client to use the common function. Indeed I had to use Finally, Navid do you see any problem in bringing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah looks good - I might PR a change to k8s to fix this problem but it'll take weeks/months for us to switch over to it |
||
return dynamic.NewKnDynamicClient(dynamicClient, testNamespace) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could technically drop the need for the gvrToListKind if you add the correct types to the scheme
ie. for k8s types invoke
scheme.AddToScheme(scheme)
from https://github.com/kubernetes/client-go/blob/1bccfc8c60977e2ce3235394daff128996818f7b/kubernetes/scheme/register.go#L135You can do this with eventing and serving and save yourself from maintaining this list. Unsure if there's something that prevents you from importing those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also had some issues where I couldn't provide unstructured types to the fake dynamic client. There would be an error with the way the fake client interacts with its object tracker
So I wrote some code for the fake injection client to rewire these schemes to use unstructured.* types
https://github.com/knative/pkg/pull/2145/files#diff-8438a08a79f266761b674dbf8748084e62be792ce56e7d7b598d148c069946e5L40
Unsure if you would need to do the same - if so maybe we pull that bit of logic out out injection and into some sort of fakedynamic package in
knative.dev/pkg