File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,29 @@ var (
107
107
// metav1.PartialObjectMetadata to the client when fetching objects in your
108
108
// reconciler, otherwise you'll end up with a duplicate structured or
109
109
// unstructured cache.
110
+ //
111
+ // When watching a resource with OnlyMetadata, for example the v1.Pod, you
112
+ // should not Get and List using the v1.Pod type. Instead, you should use
113
+ // the special metav1.PartialObjectMetadata type.
114
+ //
115
+ // ❌ Incorrect:
116
+ //
117
+ // pod := &v1.Pod{}
118
+ // mgr.GetClient().Get(ctx, nsAndName, pod)
119
+ //
120
+ // âś… Correct:
121
+ //
122
+ // pod := &metav1.PartialObjectMetadata{}
123
+ // pod.SetGroupVersionKind(schema.GroupVersionKind{
124
+ // Group: "",
125
+ // Version: "v1",
126
+ // Kind: "Pod",
127
+ // })
128
+ // mgr.GetClient().Get(ctx, nsAndName, pod)
129
+ //
130
+ // In the first case, controller-runtime will create another cache for the
131
+ // concrete type on top of the metadata cache; this increases memory
132
+ // consumption and leads to race conditions as caches are not in sync.
110
133
OnlyMetadata = projectAs (projectAsMetadata )
111
134
112
135
_ ForOption = OnlyMetadata
You can’t perform that action at this time.
0 commit comments