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

Generated injection code is broken when there's a mismatch in type #2537

Closed
carlisia opened this issue Jun 28, 2022 · 4 comments
Closed

Generated injection code is broken when there's a mismatch in type #2537

carlisia opened this issue Jun 28, 2022 · 4 comments
Assignees
Labels
area/networking kind/bug Categorizes issue or PR as related to a bug.

Comments

@carlisia
Copy link
Member

carlisia commented Jun 28, 2022

There is a problem with the injection code logic where if a type ReferencePolicyList struct contains an item such as the first one below the generated code will work, but if the included item is of a different type, then the code generated is of one type but expects the other.

  • Items []ReferencePolicy - works as an element of type ReferencePolicyList struct
  • Items []ReferenceGrant - does not work as an element of type ReferencePolicyList struct

We got to see this happening in this PR:
⬆️ Bump Gateway API version to v0.5.0-rc1 by carlisia · Pull Request #315 · knative-sandbox/net-gateway-api

We "fixed" it by deleting this piece of the generated code after the script was run, since it wasn't actually being used.

/area networking
/kind bug

This works:

pkg/informer.go at 177751338ddc41979885ecf39679f5a900c00111 · knative/pkg

type [ReferencePolicyList](https://github.com/kubernetes-sigs/gateway-api/blob/v0.4.0/apis/v1alpha2/referencepolicy_types.go#L54) [¶](https://pkg.go.dev/sigs.k8s.io/gateway-api@v0.4.0/apis/v1alpha2?utm_source=gopls#ReferencePolicyList)
type ReferencePolicyList struct {
	[metav1](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1).[TypeMeta](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#TypeMeta) `json:",inline"`
	[metav1](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1).[ListMeta](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#ListMeta) `json:"metadata,omitempty"`
	Items           [][ReferencePolicy](https://pkg.go.dev/sigs.k8s.io/gateway-api@v0.4.0/apis/v1alpha2?utm_source=gopls#ReferencePolicy) `json:"items"`
}

This does not work:

type [ReferencePolicyList](https://github.com/kubernetes-sigs/gateway-api/blob/v0.5.0-rc1/apis/v1alpha2/referencepolicy_types.go#L58) [¶](https://pkg.go.dev/sigs.k8s.io/gateway-api@v0.5.0-rc1/apis/v1alpha2?utm_source=gopls#ReferencePolicyList)
type ReferencePolicyList struct {
	[metav1](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1).[TypeMeta](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#TypeMeta) `json:",inline"`
	[metav1](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1).[ListMeta](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#ListMeta) `json:"metadata,omitempty"`
	Items           [][ReferenceGrant](https://pkg.go.dev/sigs.k8s.io/gateway-api@v0.5.0-rc1/apis/v1alpha2?utm_source=gopls#ReferenceGrant) `json:"items"`
}
# knative.dev/net-gateway-api/pkg/client/gatewayapi/injection/informers/apis/v1alpha2/referencepolicy
pkg/client/gatewayapi/injection/informers/apis/v1alpha2/referencepolicy/referencepolicy.go:107:15: cannot use &lo.Items[idx] (type *"sigs.k8s.io/gateway-api/apis/v1alpha2".ReferenceGrant) as type *"sigs.k8s.io/gateway-api/apis/v1alpha2".ReferencePolicy in append

# knative.dev/net-gateway-api/pkg/client/gatewayapi/injection/informers/apis/v1alpha2/referencepolicy/filtered
pkg/client/gatewayapi/injection/informers/apis/v1alpha2/referencepolicy/filtered/referencepolicy.go:126:15: cannot use &lo.Items[idx] (type *"sigs.k8s.io/gateway-api/apis/v1alpha2".ReferenceGrant) as type *"sigs.k8s.io/gateway-api/apis/v1alpha2".ReferencePolicy in append

/assign @dprotaso

Expected Behavior

Actual Behavior

Steps to Reproduce the Problem

Additional Info

@knative-prow knative-prow bot added area/networking kind/bug Categorizes issue or PR as related to a bug. labels Jun 28, 2022
@dprotaso
Copy link
Member

Hopefully they can fix the type to what it was before

kubernetes-sigs/gateway-api#1239

Otherwise I'll make changes to the injection-gen

@evankanderson
Copy link
Member

If we fix this on the Knative side, the code is probably here: https://github.com/knative/pkg/blob/main/codegen/cmd/injection-gen/generators/client.go#L542

@dprotaso
Copy link
Member

Gateway API change merged - so we should be good

@carlisia
Copy link
Member Author

Thanks for fixing this @dprotaso! I was convinced that had been done intentionally 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/networking kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

3 participants