Skip to content

Commit

Permalink
fix hard-coded cluster.local domain (#10306)
Browse files Browse the repository at this point in the history
Co-authored-by: soloio-bulldozer[bot] <48420018+soloio-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: Sam Heilbron <[email protected]>
  • Loading branch information
3 people authored Nov 12, 2024
1 parent 0ed35ac commit 208226b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
6 changes: 6 additions & 0 deletions changelog/v1.18.0-beta34/cluster-domain.yaml
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 2 additions & 8 deletions pkg/utils/kubeutils/dns.go
Original file line number Diff line number Diff line change
@@ -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)
}
7 changes: 2 additions & 5 deletions projects/gateway2/utils/upstream.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion projects/gloo/pkg/plugins/kubernetes/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
))
}
Expand Down

0 comments on commit 208226b

Please sign in to comment.