Skip to content

Commit fed5c1e

Browse files
committed
Addressing feedback
- 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.
1 parent e5fb87e commit fed5c1e

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

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

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,28 @@ clearly described and the permissions issues should be resolved.
895895
This could be done with a double opt-in (an opt-in from both the referrer and the refer-ee) or with secondary permissions
896896
checks performed in admission.
897897

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
899920

900921
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):
901922

@@ -909,11 +930,11 @@ secretRef:
909930
namespace: foo-namespace
910931
```
911932

912-
#### Controller behavior
933+
##### Controller behavior
913934

914935
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.
915936

916-
### References which can point to multiple resource types
937+
#### References which can point to multiple resource types
917938

918939
Multi-kind object references are used when there is a bounded set of valid resource types that a reference can point to.
919940

@@ -930,11 +951,11 @@ fooRef:
930951

931952
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.
932953

933-
#### Controller behavior
954+
##### Controller behavior
934955

935956
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.
936957

937-
### Generic object reference
958+
#### Generic object reference
938959

939960
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.
940961

@@ -943,17 +964,17 @@ With a generic object reference, it is not possible to extract any information a
943964
```yaml
944965
fooObjectRef:
945966
group: operator.openshift.io
946-
resource: OpenShiftAPIServer
967+
resource: openshiftapiservers
947968
name: cluster
948969
# namespace is unset if the resource is cluster-scoped, or lives in the
949970
# same namespace as the referrer.
950971
```
951972

952-
#### Controller behavior
973+
##### Controller behavior
953974

954975
The operator would be expected to find the resource via the discovery client (as the version is not supplied).
955976

956-
### Field reference
977+
#### Field reference
957978

958979
A field reference is used when the desire is to extract a value from a specific field in a referenced object.
959980

@@ -964,12 +985,12 @@ fooFieldRef:
964985
version: v1 # version of the resource
965986
# group is elided in the ConfigMap example, since it has a blank group in the OpenAPI spec.
966987
resource: configmaps
967-
fieldPath: data/foo
988+
fieldPath: data.foo
968989
```
969990

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.
971992

972-
#### Controller behavior
993+
##### Controller behavior
973994

974995
In this scenario, all required attributes are required, so the operator may query the API directly.
975996

0 commit comments

Comments
 (0)