Skip to content

Commit 8a1b562

Browse files
committed
Improve docs for client.Object
It was brought to my attention that the relationship between client.Object and runtime.Object isn't particularly clear to folks who are not used to working in the guts of client-go & apimachinery, so this adds some docs to helpfully clarify and provide examples.
1 parent f52b618 commit 8a1b562

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

pkg/client/object.go

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,56 @@ import (
2121
"k8s.io/apimachinery/pkg/runtime"
2222
)
2323

24-
// Object is a Kubernetes object, allows functions to work indistinctly with any resource that
25-
// implements both Object interfaces.
24+
// Object is a Kubernetes object, allows functions to work indistinctly with
25+
// any resource that implements both Object interfaces.
26+
//
27+
// Semantically, these are objects which are both serializable (runtime.Object)
28+
// and identifiable (metav1.Object) -- think any object which you could write
29+
// as YAML or JSON, and then `kubectl create`.
30+
//
31+
// Code-wise, this means that any object which embeds both ObjectMeta (which
32+
// provides metav1.Object) and TypeMeta (which provides half of runtime.Object)
33+
// and has a `DeepCopyObject` implementation (the other half of runtime.Object)
34+
// will implement this by default.
35+
//
36+
// For example, nearly all the built-in types are Objects, as well as all
37+
// KubeBuilder-generated CRDs (unless you do something real funky to them).
38+
//
39+
// By and large, most things that implement runtime.Object also implement
40+
// Object -- it's very rare to have *just* a runtime.Object implementation (the
41+
// cases tend to be funky built-in types like Webhook payloads that don't have
42+
// a `metadata` field).
43+
//
44+
// Notice that XYZList types are distinct: they implement ObjectList instead.
2645
type Object interface {
2746
metav1.Object
2847
runtime.Object
2948
}
3049

31-
// ObjectList is a Kubernetes object list, allows functions to work indistinctly with any resource that
32-
// implements both runtime.Object and metav1.ListInterface interfaces.
50+
// ObjectList is a Kubernetes object list, allows functions to work
51+
// indistinctly with any resource that implements both runtime.Object and
52+
// metav1.ListInterface interfaces.
53+
//
54+
// Semantically, this is any object which may be serialized (ObjectMeta), and
55+
// is a kubernetes list wrapper (has items, pagination fields, etc) -- think
56+
// the wrapper used in a response from a `kubectl list --output yaml` call.
57+
//
58+
// Code-wise, this means that any object which embedds both ListMeta (which
59+
// provides metav1.ListInterface) and TypeMeta (which provides half of
60+
// runtime.Object) and has a `DeepCopyObject` implementation (the other half of
61+
// runtime.Object) will implement this by default.
62+
//
63+
// For example, nearly all the built-in XYZList types are ObjectLists, as well
64+
// as the XYZList types for all KubeBuilder-generated CRDs (unless you do
65+
// something real funky to them).
66+
//
67+
// By and large, most things that are XYZList and implement runtime.Object also
68+
// implement ObjectList -- it's very rare to have *just* a runtime.Object
69+
// implementation (the cases tend to be funky built-in types like Webhook
70+
// payloads that don't have a `metadata` field).
71+
//
72+
// This is similar to Object, which is almost always implemented by the items
73+
// in the list themselves.
3374
type ObjectList interface {
3475
metav1.ListInterface
3576
runtime.Object

0 commit comments

Comments
 (0)