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
- switching fieldpath syntax to reference best practices already in the
spec
- clarifying naming of the object reference field
- fixing a poor example with a kind used where a resource value should
have been.
Copy file name to clipboardExpand all lines: contributors/devel/sig-architecture/api-conventions.md
+32-11Lines changed: 32 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -895,7 +895,28 @@ clearly described and the permissions issues should be resolved.
895
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
896
896
checks performed in admission.
897
897
898
-
### References to a single resource type
898
+
### Naming of the reference field
899
+
900
+
The name of the reference field should be of the format "{field}Ref", with "Ref" always included in the suffix.
901
+
902
+
The "{field}" component should be named to indicate the purpose of the reference. For example, "targetRef" in an
903
+
endpoint indicates that the object reference specifies the target.
904
+
905
+
It is okay to have the "{field}" component indicate the resource type. For example, "secretRef" when referencing
906
+
a secret. However, this comes with the risk off the field being a misnomer in the case that the field is expanded to
907
+
reference more than one type.
908
+
909
+
### Object References Examples
910
+
911
+
The following sections illustrate recommended schemas for various object references scenarios.
912
+
913
+
The schemas outlined below are designed to enable purely additive fields as the types of referencable
914
+
objects expand, and therefore are backwards compatible.
915
+
916
+
For example, it is possible to go from a single resource type to multiple resource types without
917
+
a breaking change in the schema.
918
+
919
+
#### References to a single resource type
899
920
900
921
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
922
@@ -909,11 +930,11 @@ secretRef:
909
930
namespace: foo-namespace
910
931
```
911
932
912
-
#### Controller behavior
933
+
##### Controller behavior
913
934
914
935
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
936
916
-
### References which can point to multiple resource types
937
+
#### References which can point to multiple resource types
917
938
918
939
Multi-kind object references are used when there is a bounded set of valid resource types that a reference can point to.
919
940
@@ -930,11 +951,11 @@ fooRef:
930
951
931
952
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
953
933
-
#### Controller behavior
954
+
##### Controller behavior
934
955
935
956
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.
936
957
937
-
### Generic object reference
958
+
#### Generic object reference
938
959
939
960
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.
940
961
@@ -943,17 +964,17 @@ With a generic object reference, it is not possible to extract any information a
943
964
```yaml
944
965
fooObjectRef:
945
966
group: operator.openshift.io
946
-
resource: OpenShiftAPIServer
967
+
resource: openshiftapiservers
947
968
name: cluster
948
969
# namespace is unset if the resource is cluster-scoped, or lives in the
949
970
# same namespace as the referrer.
950
971
```
951
972
952
-
#### Controller behavior
973
+
##### Controller behavior
953
974
954
975
The operator would be expected to find the resource via the discovery client (as the version is not supplied).
955
976
956
-
### Field reference
977
+
#### Field reference
957
978
958
979
A field reference is used when the desire is to extract a value from a specific field in a referenced object.
959
980
@@ -964,12 +985,12 @@ fooFieldRef:
964
985
version: v1 # version of the resource
965
986
# group is elided in the ConfigMap example, since it has a blank group in the OpenAPI spec.
966
987
resource: configmaps
967
-
fieldPath: data/foo
988
+
fieldPath: data.foo
968
989
```
969
990
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.
991
+
The fieldPath should point to a single value, and use [the recommended field selector notation](#selecting-fields) to denote the field path.
971
992
972
-
#### Controller behavior
993
+
##### Controller behavior
973
994
974
995
In this scenario, all required attributes are required, so the operator may query the API directly.
0 commit comments