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

gateway-api: patch route informer results with TypeMeta #3271

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions source/gateway_httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
}
13 changes: 10 additions & 3 deletions source/gateway_tcproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
}
Expand Down
13 changes: 10 additions & 3 deletions source/gateway_tlsroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
13 changes: 10 additions & 3 deletions source/gateway_udproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
}