diff --git a/source/gateway_httproute.go b/source/gateway_httproute.go index eca0d690e9..e9e9b25ea9 100644 --- a/source/gateway_httproute.go +++ b/source/gateway_httproute.go @@ -31,9 +31,9 @@ func NewGatewayHTTPRouteSource(clients ClientGenerator, config *Config) (Source, }) } -type gatewayHTTPRoute struct{ route *v1beta1.HTTPRoute } +type gatewayHTTPRoute struct{ route v1beta1.HTTPRoute } // NOTE: Must update TypeMeta in List when changing the APIVersion. -func (rt *gatewayHTTPRoute) Object() kubeObject { return rt.route } +func (rt *gatewayHTTPRoute) Object() kubeObject { return &rt.route } func (rt *gatewayHTTPRoute) Metadata() *metav1.ObjectMeta { return &rt.route.ObjectMeta } func (rt *gatewayHTTPRoute) Hostnames() []v1beta1.Hostname { return rt.route.Spec.Hostnames } func (rt *gatewayHTTPRoute) Protocol() v1beta1.ProtocolType { return v1beta1.HTTPProtocolType } @@ -50,7 +50,14 @@ func (inf gatewayHTTPRouteInformer) List(namespace string, selector labels.Selec } routes := make([]gatewayRoute, len(list)) for i, rt := range list { - routes[i] = &gatewayHTTPRoute{rt} + // List results are supposed to be treated as read-only. + // We make a shallow copy since we're only interested in setting the TypeMeta. + clone := *rt + clone.TypeMeta = metav1.TypeMeta{ + APIVersion: v1beta1.GroupVersion.String(), + Kind: "HTTPRoute", + } + routes[i] = &gatewayHTTPRoute{clone} } return routes, nil } diff --git a/source/gateway_tcproute.go b/source/gateway_tcproute.go index 5badfaff12..687116c198 100644 --- a/source/gateway_tcproute.go +++ b/source/gateway_tcproute.go @@ -32,9 +32,9 @@ func NewGatewayTCPRouteSource(clients ClientGenerator, config *Config) (Source, }) } -type gatewayTCPRoute struct{ route *v1alpha2.TCPRoute } +type gatewayTCPRoute struct{ route v1alpha2.TCPRoute } // NOTE: Must update TypeMeta in List when changing the APIVersion. -func (rt *gatewayTCPRoute) Object() kubeObject { return rt.route } +func (rt *gatewayTCPRoute) Object() kubeObject { return &rt.route } func (rt *gatewayTCPRoute) Metadata() *metav1.ObjectMeta { return &rt.route.ObjectMeta } func (rt *gatewayTCPRoute) Hostnames() []v1beta1.Hostname { return nil } func (rt *gatewayTCPRoute) Protocol() v1beta1.ProtocolType { return v1beta1.TCPProtocolType } @@ -53,7 +53,14 @@ func (inf gatewayTCPRouteInformer) List(namespace string, selector labels.Select } routes := make([]gatewayRoute, len(list)) for i, rt := range list { - routes[i] = &gatewayTCPRoute{rt} + // List results are supposed to be treated as read-only. + // We make a shallow copy since we're only interested in setting the TypeMeta. + clone := *rt + clone.TypeMeta = metav1.TypeMeta{ + APIVersion: v1alpha2.GroupVersion.String(), + Kind: "TCPRoute", + } + routes[i] = &gatewayTCPRoute{clone} } return routes, nil } diff --git a/source/gateway_tlsroute.go b/source/gateway_tlsroute.go index ec5de040e1..d889793e49 100644 --- a/source/gateway_tlsroute.go +++ b/source/gateway_tlsroute.go @@ -32,9 +32,9 @@ func NewGatewayTLSRouteSource(clients ClientGenerator, config *Config) (Source, }) } -type gatewayTLSRoute struct{ route *v1alpha2.TLSRoute } +type gatewayTLSRoute struct{ route v1alpha2.TLSRoute } // NOTE: Must update TypeMeta in List when changing the APIVersion. -func (rt *gatewayTLSRoute) Object() kubeObject { return rt.route } +func (rt *gatewayTLSRoute) Object() kubeObject { return &rt.route } func (rt *gatewayTLSRoute) Metadata() *metav1.ObjectMeta { return &rt.route.ObjectMeta } func (rt *gatewayTLSRoute) Hostnames() []v1beta1.Hostname { return v1b1Hostnames(rt.route.Spec.Hostnames) @@ -55,7 +55,14 @@ func (inf gatewayTLSRouteInformer) List(namespace string, selector labels.Select } routes := make([]gatewayRoute, len(list)) for i, rt := range list { - routes[i] = &gatewayTLSRoute{rt} + // List results are supposed to be treated as read-only. + // We make a shallow copy since we're only interested in setting the TypeMeta. + clone := *rt + clone.TypeMeta = metav1.TypeMeta{ + APIVersion: v1alpha2.GroupVersion.String(), + Kind: "TLSRoute", + } + routes[i] = &gatewayTLSRoute{clone} } return routes, nil } diff --git a/source/gateway_udproute.go b/source/gateway_udproute.go index 20ce5ccc43..c8466821aa 100644 --- a/source/gateway_udproute.go +++ b/source/gateway_udproute.go @@ -32,9 +32,9 @@ func NewGatewayUDPRouteSource(clients ClientGenerator, config *Config) (Source, }) } -type gatewayUDPRoute struct{ route *v1alpha2.UDPRoute } +type gatewayUDPRoute struct{ route v1alpha2.UDPRoute } // NOTE: Must update TypeMeta in List when changing the APIVersion. -func (rt *gatewayUDPRoute) Object() kubeObject { return rt.route } +func (rt *gatewayUDPRoute) Object() kubeObject { return &rt.route } func (rt *gatewayUDPRoute) Metadata() *metav1.ObjectMeta { return &rt.route.ObjectMeta } func (rt *gatewayUDPRoute) Hostnames() []v1beta1.Hostname { return nil } func (rt *gatewayUDPRoute) Protocol() v1beta1.ProtocolType { return v1beta1.UDPProtocolType } @@ -53,7 +53,14 @@ func (inf gatewayUDPRouteInformer) List(namespace string, selector labels.Select } routes := make([]gatewayRoute, len(list)) for i, rt := range list { - routes[i] = &gatewayUDPRoute{rt} + // List results are supposed to be treated as read-only. + // We make a shallow copy since we're only interested in setting the TypeMeta. + clone := *rt + clone.TypeMeta = metav1.TypeMeta{ + APIVersion: v1alpha2.GroupVersion.String(), + Kind: "UDPRoute", + } + routes[i] = &gatewayUDPRoute{clone} } return routes, nil }