You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- switched from kind to resource.
- extended examples to four kinds of object references.
- clarified use of JSON Pointer to determine the path to the field.
Copy file name to clipboardExpand all lines: contributors/devel/sig-architecture/api-conventions.md
+69-23Lines changed: 69 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -874,11 +874,6 @@ Examples:
874
874
875
875
## Object references
876
876
877
-
Object references should either be called `fooName` if referring to an object of
878
-
kind `Foo` by just the name (within the current namespace, if a namespaced
879
-
resource), or should be called `fooRef`, and should contain a subset of the
880
-
fields of the `ObjectReference` type.
881
-
882
877
Object references on a namespaced type should usually refer only to objects in
883
878
the same namespace. Because namespaces are a security boundary, cross namespace
884
879
references can have unexpected impacts, including:
@@ -900,35 +895,86 @@ clearly described and the permissions issues should be resolved.
900
895
This could be done with a double opt-in (an opt-in from both the referrer and the refer-ee) or with secondary permissions
901
896
checks performed in admission.
902
897
903
-
TODO: Plugins, extensions, headers
898
+
### References to a single resource type
899
+
900
+
A single kind object reference is straightforward in that the controller can hard-code most qualifiers needed to identify the object. As such as the only value needed to be provided is the name (and namespace, although cross-namespace references are discouraged):
901
+
902
+
```yaml
903
+
# for a single resource, the suffix should be Ref, with the field name
904
+
# providing an indication as to the resource type referenced.
905
+
secretRef:
906
+
name: foo
907
+
# namespace would generally not be needed and is discouraged,
908
+
# as explained above.
909
+
namespace: foo-namespace
910
+
```
911
+
912
+
#### Controller behavior
913
+
914
+
The operator is expected to know the version, group, and resource name of the object it needs to retrieve the value from, and can use the discovery client or construct the API path directly.
915
+
916
+
### References which can point to multiple resource types
917
+
918
+
Multi-kind object references are used when there is a bounded set of valid resource types that a reference can point to.
919
+
920
+
As with a single-kind object reference, the operator can supply missing fields, provided that the fields that are present are sufficient to uniquely identify the object resource type among the set of supported types.
921
+
922
+
```yaml
923
+
# guidance for the field name is the same as a single resource.
924
+
fooRef:
925
+
group: sns.services.k8s.aws
926
+
resource: topics
927
+
name: foo
928
+
namespace: foo-namespace
929
+
```
930
+
931
+
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.
932
+
933
+
#### Controller behavior
934
+
935
+
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.
904
936
905
-
### Handling references to multiple kinds
937
+
### Generic object reference
906
938
907
-
References which can refer to multiple kinds should use a single field, and select the target kind via `apiVersion` and `kind` fields.
939
+
A generic object reference is used when the desire is to provide a pointer to some object to simplify discovery for the user. For example, this could be used to reference a target object for a `core.v1.Event` that occurred.
908
940
909
-
For example, if one can retrieving a referenced value from a `ConfigMap` or a `Secret` kind, the schema for the reference should be of the form:
941
+
With a generic object reference, it is not possible to extract any information about the referenced object aside from what is standard (e.g. ObjectMeta). Since any standard fields exist in any version of a resource, it is possible to not include version in this case:
910
942
911
943
```yaml
912
-
# preferred pattern
913
-
valueFrom:
914
-
kind: Secret # alternatively ConfigMap
915
-
name: resource-name
916
-
optional: true
944
+
fooObjectRef:
945
+
group: operator.openshift.io
946
+
resource: OpenShiftAPIServer
947
+
name: cluster
948
+
# namespace is unset if the resource is cluster-scoped, or lives in the
949
+
# same namespace as the referrer.
917
950
```
918
951
919
-
Rather than:
952
+
#### Controller behavior
953
+
954
+
The operator would be expected to find the resource via the discovery client (as the version is not supplied).
955
+
956
+
### Field reference
957
+
958
+
A field reference is used when the desire is to extract a value from a specific field in a referenced object.
959
+
960
+
Field references differ from other reference types, as the operator has no knowledge of the object prior to the reference. Since the schema of an object can differ for different versions of a resource, this means that a “version” is required for this type of reference.
920
961
921
962
```yaml
922
-
# discouraged pattern
923
-
valueFrom:
924
-
configMapRef:
925
-
name: resource-name
926
-
optional: true
927
-
secretRef:
928
-
name: resource-name
929
-
optional: true
963
+
fooFieldRef:
964
+
version: v1 # version of the resource
965
+
# group is elided in the ConfigMap example, since it has a blank group in the OpenAPI spec.
966
+
resource: configmaps
967
+
fieldPath: data/foo
930
968
```
931
969
970
+
The fieldPath should point to a single value, and use JSON Pointer syntax to specify the desired field, from the root of the object.
971
+
972
+
#### Controller behavior
973
+
974
+
In this scenario, all required attributes are required, so the operator may query the API directly.
975
+
976
+
TODO: Plugins, extensions, headers
977
+
932
978
## HTTP Status codes
933
979
934
980
The server will respond with HTTP status codes that match the HTTP spec. See the
0 commit comments