Skip to content

Commit 06628af

Browse files
committed
clarify that new usages of generic *Reference structs are discouraged
1 parent 4580490 commit 06628af

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

staging/src/k8s.io/api/core/v1/types.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6779,13 +6779,23 @@ type ObjectReference struct {
67796779

67806780
// LocalObjectReference contains enough information to let you locate the
67816781
// referenced object inside the same namespace.
6782+
// ---
6783+
// New uses of this type are discouraged because of difficulty describing its usage when embedded in APIs.
6784+
// 1. Invalid usage help. It is impossible to add specific help for individual usage. In most embedded usages, there are particular
6785+
// restrictions like, "must refer only to types A and B" or "UID not honored" or "name must be restricted".
6786+
// Those cannot be well described when embedded.
6787+
// 2. Inconsistent validation. Because the usages are different, the validation rules are different by usage, which makes it hard for users to predict what will happen.
6788+
// 3. We cannot easily change it. Because this type is embedded in many locations, updates to this type
6789+
// will affect numerous schemas. Don't make new APIs embed an underspecified API type they do not control.
6790+
//
6791+
// Instead of using this type, create a locally provided and used type that is well-focused on your reference.
6792+
// For example, ServiceReferences for admission registration: https://github.com/kubernetes/api/blob/release-1.17/admissionregistration/v1/types.go#L533 .
67826793
// +structType=atomic
67836794
type LocalObjectReference struct {
67846795
// Name of the referent.
67856796
// This field is effectively required, but due to backwards compatibility is
67866797
// allowed to be empty. Instances of this type with an empty value here are
67876798
// almost certainly wrong.
6788-
// TODO: Add other useful fields. apiVersion, kind, uid?
67896799
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
67906800
// +optional
67916801
// +default=""
@@ -6796,6 +6806,20 @@ type LocalObjectReference struct {
67966806

67976807
// TypedLocalObjectReference contains enough information to let you locate the
67986808
// typed referenced object inside the same namespace.
6809+
// ---
6810+
// New uses of this type are discouraged because of difficulty describing its usage when embedded in APIs.
6811+
// 1. Invalid usage help. It is impossible to add specific help for individual usage. In most embedded usages, there are particular
6812+
// restrictions like, "must refer only to types A and B" or "UID not honored" or "name must be restricted".
6813+
// Those cannot be well described when embedded.
6814+
// 2. Inconsistent validation. Because the usages are different, the validation rules are different by usage, which makes it hard for users to predict what will happen.
6815+
// 3. The fields are both imprecise and overly precise. Kind is not a precise mapping to a URL. This can produce ambiguity
6816+
// during interpretation and require a REST mapping. In most cases, the dependency is on the group,resource tuple
6817+
// and the version of the actual struct is irrelevant.
6818+
// 4. We cannot easily change it. Because this type is embedded in many locations, updates to this type
6819+
// will affect numerous schemas. Don't make new APIs embed an underspecified API type they do not control.
6820+
//
6821+
// Instead of using this type, create a locally provided and used type that is well-focused on your reference.
6822+
// For example, ServiceReferences for admission registration: https://github.com/kubernetes/api/blob/release-1.17/admissionregistration/v1/types.go#L533 .
67996823
// +structType=atomic
68006824
type TypedLocalObjectReference struct {
68016825
// APIGroup is the group for the resource being referenced.

0 commit comments

Comments
 (0)