github.com/cilium/cilium@v1.16.2/operator/pkg/gateway-api/routechecks/hostnames.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package routechecks 5 6 import ( 7 gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" 8 9 "github.com/cilium/cilium/operator/pkg/model" 10 ) 11 12 func computeHosts[T ~string](gw *gatewayv1.Gateway, hostnames []T, excludeHostNames []T) []string { 13 hosts := make([]string, 0, len(hostnames)) 14 for _, listener := range gw.Spec.Listeners { 15 hosts = append(hosts, computeHostsForListener(&listener, hostnames, excludeHostNames)...) 16 } 17 18 return hosts 19 } 20 21 func computeHostsForListener[T ~string](listener *gatewayv1.Listener, hostnames []T, excludeHostNames []T) []string { 22 return model.ComputeHosts(toStringSlice(hostnames), (*string)(listener.Hostname), toStringSlice(excludeHostNames)) 23 } 24 25 func toStringSlice[T ~string](s []T) []string { 26 res := make([]string, 0, len(s)) 27 for _, h := range s { 28 res = append(res, string(h)) 29 } 30 return res 31 }