-
Notifications
You must be signed in to change notification settings - Fork 490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace ObjectReference, TypedLocalObjectReference #73
Replace ObjectReference, TypedLocalObjectReference #73
Conversation
Welcome @Miciah! |
Hi @Miciah. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@@ -156,7 +156,7 @@ type ListenerTLS struct { | |||
// | |||
// Support: Core (Kubernetes Secrets) | |||
// Support: Implementation-specific (Other resource types) | |||
Certificates []core.TypedLocalObjectReference `json:"certificates,omitempty"` | |||
Certificates []CertificateObjectReference `json:"certificates,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we assume that the referenced object is a Kubernetes object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep the assumption for now, we can discuss in a separate issue/PR
} | ||
|
||
// GatewayObjectReference identifies a Gateway object. | ||
type GatewayObjectReference struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this definition be in gateway_types.go
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, will be used by more than http imagine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put that in a follow on PR.
Hey @Miciah, thanks for all the work on this! The concept of using entirely new types for each object reference is new to me, though the comments you linked to do make sense. This does seem like it adds a lot of potential overhead though with all the new types. It seems like each one of these new object reference types are identical and parallel the core Do you know if there are any existing examples of this kind of pattern of defining custom reference types is being used in place of the core types? Is there any more official documentation providing more clarity here? If not, it might be good to first PR some kind of clarification to the contributor guide describing this approach to object references in more detail and getting a wider audience on this. It looks like @deads2k originally added the warning on the |
/assign @robscott |
/ok-to-test |
If the struct is basically the same as the type in
|
Right, most of the reasons against using By "overhead", do you mean lines of code? I agree it is verbose. The flip side of that argument is that we get much clearer output in generated API references and
The
I think so. Migrating old APIs may not be possible, and we will be among the first to adopt the new API.
I think we should avoid
Would that be acceptable? |
The gist of the type alias is two things:
I'm ok with decoupling from |
Given a that this is a reference to an API object, having API in the field name is redundant. With 20/20 hindsight on an APIReference type, you wouldn't have APIGroup, APIVersion, APIResource as the fields. |
The argument for using "Group" instead of "APIGroup" is that the referent is necessarily an API object, so "API" is redundant (and the other fields do not have "API" in their names even though they all identify an API object). That said, "APIGroup" is not wrong (in the way that "Kind" is wrong), so per your request, I have changed the field name in the new types to "APIGroup" for consistency with the deprecated type.
Some things (such as changing "Kind" to "Resource") we cannot reasonably change once the API is GA, but point taken.
All right. I have updated the PR to use type aliases. Because the CRD generation omits godoc on types, it is not useful to document fields in types' godoc, so I have moved some godoc to the reference fields. Here is an example of how this looks, from forwardTo:
description: ForwardTo sends requests to the referenced
- object.
+ object. The resource may be "service" (use the empty
+ string for the group), or an implementation may support
+ other resources (for example, resource "myroutetarget"
+ in group "networking.acme.io").
properties:
- group:
- description: Group is the group of the referent. For
- example, "networking.acme.io". The empty string
- represents the core API group.
+ apiGroup:
+ description: APIGroup is the group of the referent. The
+ empty string represents the core API group.
type: string
name:
description: Name is the name of the referent.
type: string
resource:
- description: Resource is the resource of the referent. For
- example, "service" or "myroutetarget".
+ description: Resource is the resource of the referent.
type: string Thanks for the feedback! |
9840162
to
eb5e068
Compare
Rebased. |
Sorry, I just saw David's comment. I am happy to change "APIGroup" back to "Group" if we can reach a consensus. |
api/v1alpha1/gateway_types.go
Outdated
// | ||
// +kubebuilder:validation:Required | ||
// +required | ||
APIGroup string `json:"apiGroup"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with Group, as long as it is going to be consistent going forward.
Thanks, this looks great. /lgtm |
Looks like the deepcopy generation does not like type aliases:
The definition on line 27 is the following: // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *CertificateObjectReference) DeepCopyInto(out *CertificateObjectReference) {
*out = *in
} The definition on line 157 is the following: // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *GatewayClassParametersObjectReference) DeepCopyInto(out *GatewayClassParametersObjectReference) {
*out = *in
} Both types ( |
I think I need to add |
Define well focused reference types and use them instead of ObjectReference and TypedLocalObjectReference, which should be avoided for all the reasons described in the ObjectReference godoc[1]. 1. https://github.com/kubernetes/api/blob/6e59bf7a52c237aadf4cc1f905c66b5f178c30b9/core/v1/types.go#L4985-L4996 * api/v1alpha1/gateway_types.go (GatewaySpec): Replace TypedLocalObjectReference with RouteObjectReference. (Listener): Replace TypedLocalObjectReference with ListenerExtensionObjectReference. (ListenerTLS): Replace TypedLocalObjectReference with CertificateObjectReference. (LocalObjectReference): New type. Identify an API object within a known namespace. (CertificateObjectReference): New type alias for LocalObjectReference. Identify a certificate object. (ListenerExtensionObjectReference): New type alias for LocalObjectReference. Identify a listener extension object. (RouteObjectReference): New type alias for LocalObjectReference. Identify a route object. * api/v1alpha1/gatewayclass_types.go (GatewayClassSpec): Replace ObjectReference with GatewayClassParametersObjectReference. (GatewayClassParametersObjectReference): New type alias for LocalObjectReference. Identify a parameters object for a GatewayClass object. * api/v1alpha1/httproute_types.go (HTTPRouteHost): Replace TypedLocalObjectReference with RouteHostExtensionObjectReference. (HTTPRouteMatch): Replace TypedLocalObjectReference with RouteMatchExtensionObjectReference. (RouteMatchExtensionObjectReference): New type alias for LocalObjectReference. Identify a route-match extension object. (HTTPRouteFilter): Replace TypedLocalObjectReference with RouteFilterExtensionObjectReference. (RouteFilterExtensionObjectReference): New type alias for LocalObjectReference. Identify a route-filter extension object. (HTTPHeaderFilter): Replace TypedLocalObjectReference with RouteActionTargetObjectReference and RouteActionExtensionObjectReference. (RouteActionTargetObjectReference): New type alias for LocalObjectReference. Identify a target object for a route action. (RouteActionExtensionObjectReference): New type alias for LocalObjectReference. Identify a route-action extension object. (RouteHostExtensionObjectReference): New type alias for LocalObjectReference. Identify a route-host extension object. (HTTPRouteStatus): Replace ObjectReference with GatewayObjectReference. (GatewayObjectReference): New type. Identify a Gateway object. * api/v1alpha1/zz_generated.deepcopy.go: * config/crd/bases/networking.x.k8s.io_gatewayclasses.yaml: * config/crd/bases/networking.x.k8s.io_gateways.yaml: * config/crd/bases/networking.x.k8s.io_httproutes.yaml: Regenerate.
eb5e068
to
32b64f4
Compare
Latest push changes "APIGroup" to "Group", adds |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bowei, Miciah The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
…es/single-cluster-gke-l7-gxlb added recipe for single cluster global lb gateway
Define well focused reference types and use them instead of
ObjectReference
andTypedLocalObjectReference
, which should be avoided for all the reasons described in theObjectReference
godoc.api/v1alpha1/gateway_types.go
(GatewaySpec
): ReplaceTypedLocalObjectReference
withRouteObjectReference
.(
Listener
): ReplaceTypedLocalObjectReference
withListenerExtensionObjectReference
.(
ListenerTLS
): ReplaceTypedLocalObjectReference
withCertificateObjectReference
.(
LocalObjectReference
): New type. Identify an API object within a known namespace.(
CertificateObjectReference
): New type alias forLocalObjectReference
. Identify a certificate object.(
ListenerExtensionObjectReference
): New type alias forLocalObjectReference
. Identify a listener extension object.(
RouteObjectReference
): New type alias forLocalObjectReference
. Identify a route object.api/v1alpha1/gatewayclass_types.go
(GatewayClassSpec
): ReplaceObjectReference
withGatewayClassParametersObjectReference
.(
GatewayClassParametersObjectReference
): New type alias forLocalObjectReference
. Identify a parameters object for aGatewayClass
object.api/v1alpha1/httproute_types.go
(HTTPRouteHost
): ReplaceTypedLocalObjectReference
withRouteHostExtensionObjectReference
.(
HTTPRouteMatch
): ReplaceTypedLocalObjectReference
withRouteMatchExtensionObjectReference
.(
RouteMatchExtensionObjectReference
): New type alias forLocalObjectReference
. Identify a route-match extension object.(
HTTPRouteFilter
): Replace TypedLocalObjectReference with RouteFilterExtensionObjectReference.(
RouteFilterExtensionObjectReference
): New type alias forLocalObjectReference
. Identify a route-filter extension object.(
HTTPHeaderFilter
): ReplaceTypedLocalObjectReference
withRouteActionTargetObjectReference
andRouteActionExtensionObjectReference
.(
RouteActionTargetObjectReference
): New type alias forLocalObjectReference
. Identify a target object for a route action.(
RouteActionExtensionObjectReference
): New type alias forLocalObjectReference
. Identify a route-action extension object.(
RouteHostExtensionObjectReference
): New type alias forLocalObjectReference
. Identify a route-host extension object.(
HTTPRouteStatus
): ReplaceObjectReference
withGatewayObjectReference
.(
GatewayObjectReference
): New type. Identify aGateway
object.api/v1alpha1/zz_generated.deepcopy.go
:config/crd/bases/networking.x.k8s.io_gatewayclasses.yaml
:config/crd/bases/networking.x.k8s.io_gateways.yaml
:config/crd/bases/networking.x.k8s.io_httproutes.yaml
: Regenerate.