Skip to content
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

Add spec.gatewayClassName selectable field to Gateway #3519

Open
pmalek opened this issue Dec 20, 2024 · 4 comments
Open

Add spec.gatewayClassName selectable field to Gateway #3519

pmalek opened this issue Dec 20, 2024 · 4 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.

Comments

@pmalek
Copy link
Contributor

pmalek commented Dec 20, 2024

What would you like to be added:

Kubernetes 1.31 has promoted CRD selectable field to beta and enabled it by default. 1.32 has promoted it to GA.

This proposal is about adding a selectable field (1 or more if the community finds that there's appetite for more) to Gateway, specifically: spec.gatewayClassName.

This proposal can be followed up by separate issues for other types / fields if deemed worthy of doing.

Why this is needed:

This will allow listing Gateways that match a particular GatewayClass more efficient (useful when used with controller-runtime's EnqueueRequestsFromMapFunc

	var gateways gatewayv1.GatewayList
	if err := r.Client.List(ctx, &gateways); err != nil {
		// handle
		return
	}
        var recs []reconcile.Request
	for _, gateway := range gateways.Items {
		if gateway.Spec.GatewayClassName == gatewayv1.ObjectName(gatewayClass.Name) {
			recs = append(recs, reconcile.Request{
				NamespacedName: types.NamespacedName{
					Namespace: gateway.Namespace,
					Name:      gateway.Name,
				},
			})
		}
	}

Becomes:

	var gateways gatewayv1.GatewayList
	if err := r.Client.List(ctx, gateways,
		client.MatchingFieldsSelector{
			Selector: fields.OneTermEqualSelector("spec.gatewayClassName",gatewayClass.Name),
		},
	); err != nil {
		// handle
		return
	}

        recs := ([]reconcile.Request, 0, len(gateways.Items))
	for _, gateway := range gateways.Items {
		recs = append(recs, reconcile.Request{
			NamespacedName: types.NamespacedName{
				Namespace: gateway.Namespace,
				Name:      gateway.Name,
			},
		})
	}
@pmalek pmalek added the kind/feature Categorizes issue or PR as related to a new feature. label Dec 20, 2024
@pmalek
Copy link
Contributor Author

pmalek commented Dec 20, 2024

Just tested selectable fields on 1.29 (where they were not supported) and the CRD won't apply:

make crd
kubectl kustomize config/crd | kubectl apply -f -
customresourcedefinition.apiextensions.k8s.io/gatewayclasses.gateway.networking.k8s.io created
customresourcedefinition.apiextensions.k8s.io/grpcroutes.gateway.networking.k8s.io created
customresourcedefinition.apiextensions.k8s.io/httproutes.gateway.networking.k8s.io created
customresourcedefinition.apiextensions.k8s.io/referencegrants.gateway.networking.k8s.io created
Error from server (BadRequest): error when creating "STDIN": CustomResourceDefinition in version "v1" cannot be handled as a CustomResourceDefinition: strict decoding error: unknown field "spec.versions[0].selectableFields"

I assume this warrants that we need to wait until k8s 1.35 is out to introduce this (given the support policy at https://gateway-api.sigs.k8s.io/concepts/versioning/#supported-versions).

@mlavacca
Copy link
Member

Thanks for creating this issue, @pmalek!

I think this would be a great improvement, but as you already said, it's something we necessarily need to put off because of our support policy. We'll have to wait for at least Kubernetes 1.35 to leverage this feature.

@mlavacca mlavacca added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Dec 20, 2024
@howardjohn
Copy link
Contributor

Also tracked in #2862

@pmalek
Copy link
Contributor Author

pmalek commented Dec 20, 2024

/lifecycle frozen

@k8s-ci-robot k8s-ci-robot added the lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.
Projects
None yet
Development

No branches or pull requests

4 participants