diff --git a/changelog/v1.18.0-beta34/cluster-domain.yaml b/changelog/v1.18.0-beta34/cluster-domain.yaml new file mode 100644 index 00000000000..94c38449794 --- /dev/null +++ b/changelog/v1.18.0-beta34/cluster-domain.yaml @@ -0,0 +1,6 @@ +changelog: + - type: FIX + issueLink: https://github.com/solo-io/gloo/issues/10268 + resolvesIssue: false + description: >- + Fix issue where Gloo Gateway did not respect the cluster domain for the xds host address. diff --git a/pkg/utils/kubeutils/dns.go b/pkg/utils/kubeutils/dns.go index ae62e2e7c32..e91f92ec5ae 100644 --- a/pkg/utils/kubeutils/dns.go +++ b/pkg/utils/kubeutils/dns.go @@ -1,18 +1,12 @@ package kubeutils import ( - "fmt" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -const ( - // ClusterInternalDomainName is the internal domain for a Kubernetes Cluster - ClusterInternalDomainName = "cluster.local" + "knative.dev/pkg/network" ) // ServiceFQDN returns the FQDN for the Service, assuming it is being accessed from within the Cluster // https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#services func ServiceFQDN(serviceMeta metav1.ObjectMeta) string { - return fmt.Sprintf("%s.%s.svc.%s", serviceMeta.GetName(), serviceMeta.GetNamespace(), ClusterInternalDomainName) + return network.GetServiceHostname(serviceMeta.Name, serviceMeta.Namespace) } diff --git a/projects/gateway2/utils/upstream.go b/projects/gateway2/utils/upstream.go index 24a50aad1b4..e57728d21bd 100644 --- a/projects/gateway2/utils/upstream.go +++ b/projects/gateway2/utils/upstream.go @@ -1,18 +1,15 @@ package utils import ( - "fmt" - v1 "github.com/solo-io/gloo/projects/gloo/pkg/api/v1" + "knative.dev/pkg/network" ) func GetHostnameForUpstream(us *v1.Upstream) string { // get the upstream name and namespace - // TODO: suppport other suffixes that are not cluster.local - switch uptype := us.GetUpstreamType().(type) { case *v1.Upstream_Kube: - return fmt.Sprintf("%s.%s.svc.cluster.local", uptype.Kube.GetServiceName(), uptype.Kube.GetServiceNamespace()) + return network.GetServiceHostname(uptype.Kube.GetServiceName(), uptype.Kube.GetServiceNamespace()) case *v1.Upstream_Static: hosts := uptype.Static.GetHosts() if len(hosts) == 0 { diff --git a/projects/gloo/pkg/plugins/kubernetes/plugin.go b/projects/gloo/pkg/plugins/kubernetes/plugin.go index 0bbf12d67a5..679ad51e789 100644 --- a/projects/gloo/pkg/plugins/kubernetes/plugin.go +++ b/projects/gloo/pkg/plugins/kubernetes/plugin.go @@ -11,6 +11,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/kubernetes" + "knative.dev/pkg/network" "github.com/solo-io/go-utils/contextutils" corecache "github.com/solo-io/solo-kit/pkg/api/v1/clients/kube/cache" @@ -54,9 +55,10 @@ func (p *plugin) Resolve(u *v1.Upstream) (*url.URL, error) { if !ok { return nil, nil } - return url.Parse(fmt.Sprintf("tcp://%v.%v.svc.cluster.local:%v", + return url.Parse(fmt.Sprintf("tcp://%v.%v.svc.%s:%v", kubeSpec.Kube.GetServiceName(), kubeSpec.Kube.GetServiceNamespace(), + network.GetClusterDomainName(), kubeSpec.Kube.GetServicePort(), )) }