mirror of
https://github.com/kubernetes/sample-controller.git
synced 2025-02-20 23:56:23 +08:00
Expose object tracker for fake clientsets
Not every object kind can be registered via tracker .Add() called as part of SimpleClientset initialization. This is because .Add() relies on UnsafeGuessKindToResource to convert object kinds into resource type names, which is broken for some resources. An example of an affected kind is NetworkAttachmentDefinitions CRD that uses network-attachment-definitions as its resource type name. When UnsafeGuessKindToResource is called for this kind, it returns networkattachmentdefinitions (without dashes). As per the comment inside .Add, kinds affected by UnsafeGuessKindToResource deficiencies should instead register objects using tracker .Create() method. Problem is, current SimpleClientset struct definition doesn't expose the object tracker in any way, which makes it impossible to properly register these kinds at all. To address the issue, this change modifies the definition of SimpleClientset struct to expose the object tracker used via Tracker() method. Kubernetes-commit: d68cd8a0c7e6137ca4219078a3d651ecff03c21f
This commit is contained in:
parent
88ec96fa3c
commit
5a81ef4b43
@ -41,7 +41,7 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset {
|
||||
}
|
||||
}
|
||||
|
||||
cs := &Clientset{}
|
||||
cs := &Clientset{tracker: o}
|
||||
cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake}
|
||||
cs.AddReactor("*", "*", testing.ObjectReaction(o))
|
||||
cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) {
|
||||
@ -63,12 +63,17 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset {
|
||||
type Clientset struct {
|
||||
testing.Fake
|
||||
discovery *fakediscovery.FakeDiscovery
|
||||
tracker testing.ObjectTracker
|
||||
}
|
||||
|
||||
func (c *Clientset) Discovery() discovery.DiscoveryInterface {
|
||||
return c.discovery
|
||||
}
|
||||
|
||||
func (c *Clientset) Tracker() testing.ObjectTracker {
|
||||
return c.tracker
|
||||
}
|
||||
|
||||
var _ clientset.Interface = &Clientset{}
|
||||
|
||||
// SamplecontrollerV1alpha1 retrieves the SamplecontrollerV1alpha1Client
|
||||
|
Loading…
Reference in New Issue
Block a user