sigs.k8s.io/external-dns@v0.14.1/source/gateway_httproute.go (about) 1 /* 2 Copyright 2021 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package source 18 19 import ( 20 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 "k8s.io/apimachinery/pkg/labels" 22 v1 "sigs.k8s.io/gateway-api/apis/v1" 23 informers "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions" 24 informers_v1 "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions/apis/v1" 25 ) 26 27 // NewGatewayHTTPRouteSource creates a new Gateway HTTPRoute source with the given config. 28 func NewGatewayHTTPRouteSource(clients ClientGenerator, config *Config) (Source, error) { 29 return newGatewayRouteSource(clients, config, "HTTPRoute", func(factory informers.SharedInformerFactory) gatewayRouteInformer { 30 return &gatewayHTTPRouteInformer{factory.Gateway().V1().HTTPRoutes()} 31 }) 32 } 33 34 type gatewayHTTPRoute struct{ route v1.HTTPRoute } // NOTE: Must update TypeMeta in List when changing the APIVersion. 35 36 func (rt *gatewayHTTPRoute) Object() kubeObject { return &rt.route } 37 func (rt *gatewayHTTPRoute) Metadata() *metav1.ObjectMeta { return &rt.route.ObjectMeta } 38 func (rt *gatewayHTTPRoute) Hostnames() []v1.Hostname { return rt.route.Spec.Hostnames } 39 func (rt *gatewayHTTPRoute) Protocol() v1.ProtocolType { return v1.HTTPProtocolType } 40 func (rt *gatewayHTTPRoute) RouteStatus() v1.RouteStatus { return rt.route.Status.RouteStatus } 41 42 type gatewayHTTPRouteInformer struct { 43 informers_v1.HTTPRouteInformer 44 } 45 46 func (inf gatewayHTTPRouteInformer) List(namespace string, selector labels.Selector) ([]gatewayRoute, error) { 47 list, err := inf.HTTPRouteInformer.Lister().HTTPRoutes(namespace).List(selector) 48 if err != nil { 49 return nil, err 50 } 51 routes := make([]gatewayRoute, len(list)) 52 for i, rt := range list { 53 // List results are supposed to be treated as read-only. 54 // We make a shallow copy since we're only interested in setting the TypeMeta. 55 clone := *rt 56 clone.TypeMeta = metav1.TypeMeta{ 57 APIVersion: v1.GroupVersion.String(), 58 Kind: "HTTPRoute", 59 } 60 routes[i] = &gatewayHTTPRoute{clone} 61 } 62 return routes, nil 63 }