Skip to content

Commit 8387703

Browse files
committed
Clarifying API Conventions regarding Kind and Resource in object refs
1 parent 75d002a commit 8387703

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

contributors/devel/sig-architecture/api-conventions.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,55 @@ fooRef:
10051005

10061006
Although not always necessary to help a controller identify a resource type, “group” is included to avoid ambiguity when the resource exists in multiple groups. It also provides clarity to end users and enables copy-pasting of a reference without the referenced type changing due to a different controller handling the reference.
10071007

1008+
##### Kind vs. Resource
1009+
1010+
A common point of confusion in object references is whether to construct
1011+
references with a "kind" or "resource" field. Historically most object
1012+
references in Kubernetes have used "kind". This is not as precise as "resource".
1013+
Although each combination of "group" and "resource" must be unique within
1014+
Kubernetes, the same is not always true for "group" and "kind". It is possible
1015+
for multiple resources to make use of the same "kind".
1016+
1017+
Typically all objects in Kubernetes have a canonical primary resource - such as
1018+
“pods” representing the way to create and delete resources of the “Pod” schema.
1019+
While it is possible a resource schema cannot be directly created, such as a
1020+
“Scale” object which is only used within the “scale” subresource of a number of
1021+
workloads, most object references address the primary resource via its schema.
1022+
In the context of object references, "kind" refers to the schema, not the
1023+
resource.
1024+
1025+
If implementations of an object reference will always have a clear way to map
1026+
kinds to resources, it is acceptable to use "kind" in the object reference. In
1027+
general, this requires implementations to have a predefined mapping between
1028+
kinds and resources (this is the case for built-in references which use "kind").
1029+
Relying on dynamic kind to resource mapping is not safe. Even if a "kind" only
1030+
dynamically maps to a single resource initially, it's possible for another
1031+
resource to be mounted that refers to the same "kind", potentially breaking any
1032+
dynamic resource mapping.
1033+
1034+
If an object reference may be used to reference resources of arbitrary types and
1035+
the mapping between kind and resource could be ambiguous, "resource" should be
1036+
used in the object reference.
1037+
1038+
The Ingress API provides a good example of where "kind" is acceptable for an
1039+
object reference. The API supports a backend reference as an extension point.
1040+
Implementations can use this to support forwarding traffic to custom targets
1041+
such as a storage bucket. Importantly, the supported target types are clearly
1042+
defined by each implementation of the API and there is no ambiguity for which
1043+
resource a kind maps to. This is because each Ingress implementation has a
1044+
hard-coded mapping of kind to resource.
1045+
1046+
The object reference above would look like this if it were using "kind" instead
1047+
of "resource":
1048+
1049+
```yaml
1050+
fooRef:
1051+
group: sns.services.k8s.aws
1052+
kind: Topic
1053+
name: foo
1054+
namespace: foo-namespace
1055+
```
1056+
10081057
##### Controller behavior
10091058

10101059
The operator can store a map of (group,resource) to the version of that resource it desires. From there, it can construct the full path to the resource, and retrieve the object.

0 commit comments

Comments
 (0)