MCPcopy
hub / github.com/kubernetes/client-go / NewSimpleClientset

Function NewSimpleClientset

kubernetes/fake/clientset_generated.go:106–128  ·  view source on GitHub ↗

NewSimpleClientset returns a clientset that will respond with the provided objects. It's backed by a very simple object tracker that processes creates, updates and deletions as-is, without applying any validations and/or defaults. It shouldn't be considered a replacement for a real clientset and is

(objects ...runtime.Object)

Source from the content-addressed store, hash-verified

104// without applying any validations and/or defaults. It shouldn't be considered a replacement
105// for a real clientset and is mostly useful in simple unit tests.
106func NewSimpleClientset(objects ...runtime.Object) *Clientset {
107 o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder())
108 for _, obj := range objects {
109 if err := o.Add(obj); err != nil {
110 panic(err)
111 }
112 }
113
114 cs := &Clientset{tracker: o}
115 cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake}
116 cs.AddReactor("*", "*", testing.ObjectReaction(o))
117 cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) {
118 gvr := action.GetResource()
119 ns := action.GetNamespace()
120 watch, err := o.Watch(gvr, ns)
121 if err != nil {
122 return false, nil, err
123 }
124 return true, watch, nil
125 })
126
127 return cs
128}
129
130// Clientset implements clientset.Interface. Meant to be embedded into a
131// struct to get a default implementation. This makes faking out just the method

Callers 1

TestFakeClientFunction · 0.92

Calls 8

AddMethod · 0.95
WatchMethod · 0.95
NewObjectTrackerFunction · 0.92
ObjectReactionFunction · 0.92
AddReactorMethod · 0.80
AddWatchReactorMethod · 0.80
GetResourceMethod · 0.65
GetNamespaceMethod · 0.65

Tested by 1

TestFakeClientFunction · 0.74