mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Append both the zone and the region to the federation query responses, not just the zone.
This commit is contained in:
parent
e70434a19f
commit
6894e74027
@ -595,12 +595,13 @@ func (kd *KubeDNS) federationRecords(queryPath []string) ([]skymsg.Service, erro
|
|||||||
// domain path components, i.e. kd.domainPath, from the query.
|
// domain path components, i.e. kd.domainPath, from the query.
|
||||||
path = path[:len(path)-len(kd.domainPath)]
|
path = path[:len(path)-len(kd.domainPath)]
|
||||||
|
|
||||||
// Append the zone name (zone in the cloud provider terminology, not a DNS zone)
|
// Append the zone name (zone in the cloud provider terminology, not a DNS
|
||||||
zone, err := kd.getClusterZone()
|
// zone) and the region name.
|
||||||
|
zone, region, err := kd.getClusterZoneAndRegion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to obtain the cluster zone: %v", err)
|
return nil, fmt.Errorf("failed to obtain the cluster zone and region: %v", err)
|
||||||
}
|
}
|
||||||
path = append(path, zone)
|
path = append(path, zone, region)
|
||||||
|
|
||||||
// We have already established that the map entry exists for the given federation,
|
// We have already established that the map entry exists for the given federation,
|
||||||
// we just need to retrieve the domain name, validate it and append it to the path.
|
// we just need to retrieve the domain name, validate it and append it to the path.
|
||||||
@ -620,21 +621,23 @@ func (kd *KubeDNS) federationRecords(queryPath []string) ([]skymsg.Service, erro
|
|||||||
return []skymsg.Service{{Host: name}}, nil
|
return []skymsg.Service{{Host: name}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// getClusterZone returns the name of the zone the cluster is running in. It arbitrarily selects
|
// getClusterZoneAndRegion returns the name of the zone and the region the
|
||||||
// a node and reads the failure domain annotation on the node. An alternative is to obtain this
|
// cluster is running in. It arbitrarily selects a node and reads the failure
|
||||||
// pod's (i.e. kube-dns pod's) name using the downward API, get the pod, get the node the pod is
|
// domain label on the node. An alternative is to obtain this pod's
|
||||||
// bound to and retrieve that node's annotations. But even just by reading those steps, it looks
|
// (i.e. kube-dns pod's) name using the downward API, get the pod, get the
|
||||||
// complex and it is not entirely clear what that complexity is going to buy us. So taking a
|
// node the pod is bound to and retrieve that node's labels. But even just by
|
||||||
// simpler approach here.
|
// reading those steps, it looks complex and it is not entirely clear what
|
||||||
// Also note that zone here means the zone in cloud provider terminology, not the DNS zone.
|
// that complexity is going to buy us. So taking a simpler approach here.
|
||||||
func (kd *KubeDNS) getClusterZone() (string, error) {
|
// Also note that zone here means the zone in cloud provider terminology, not
|
||||||
|
// the DNS zone.
|
||||||
|
func (kd *KubeDNS) getClusterZoneAndRegion() (string, string, error) {
|
||||||
var node *kapi.Node
|
var node *kapi.Node
|
||||||
|
|
||||||
objs := kd.nodesStore.List()
|
objs := kd.nodesStore.List()
|
||||||
if len(objs) > 0 {
|
if len(objs) > 0 {
|
||||||
var ok bool
|
var ok bool
|
||||||
if node, ok = objs[0].(*kapi.Node); !ok {
|
if node, ok = objs[0].(*kapi.Node); !ok {
|
||||||
return "", fmt.Errorf("expected node object, got: %T", objs[0])
|
return "", "", fmt.Errorf("expected node object, got: %T", objs[0])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// An alternative to listing nodes each time is to set a watch, but that is totally
|
// An alternative to listing nodes each time is to set a watch, but that is totally
|
||||||
@ -643,31 +646,37 @@ func (kd *KubeDNS) getClusterZone() (string, error) {
|
|||||||
// TODO(madhusudancs): Move this to external/v1 API.
|
// TODO(madhusudancs): Move this to external/v1 API.
|
||||||
nodeList, err := kd.kubeClient.Core().Nodes().List(kapi.ListOptions{})
|
nodeList, err := kd.kubeClient.Core().Nodes().List(kapi.ListOptions{})
|
||||||
if err != nil || len(nodeList.Items) == 0 {
|
if err != nil || len(nodeList.Items) == 0 {
|
||||||
return "", fmt.Errorf("failed to retrieve the cluster nodes: %v", err)
|
return "", "", fmt.Errorf("failed to retrieve the cluster nodes: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select a node (arbitrarily the first node) that has `LabelZoneFailureDomain` set.
|
// Select a node (arbitrarily the first node) that has `LabelZoneFailureDomain` set.
|
||||||
for _, nodeItem := range nodeList.Items {
|
for _, nodeItem := range nodeList.Items {
|
||||||
if _, ok := nodeItem.Labels[unversioned.LabelZoneFailureDomain]; !ok {
|
_, zfound := nodeItem.Labels[unversioned.LabelZoneFailureDomain]
|
||||||
|
_, rfound := nodeItem.Labels[unversioned.LabelZoneRegion]
|
||||||
|
if !zfound || !rfound {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Make a copy of the node, don't rely on the loop variable.
|
// Make a copy of the node, don't rely on the loop variable.
|
||||||
node = &(*(&nodeItem))
|
node = &(*(&nodeItem))
|
||||||
if err := kd.nodesStore.Add(node); err != nil {
|
if err := kd.nodesStore.Add(node); err != nil {
|
||||||
return "", fmt.Errorf("couldn't add the retrieved node to the cache: %v", err)
|
return "", "", fmt.Errorf("couldn't add the retrieved node to the cache: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if node == nil {
|
if node == nil {
|
||||||
return "", fmt.Errorf("Could not find any nodes")
|
return "", "", fmt.Errorf("Could not find any nodes")
|
||||||
}
|
}
|
||||||
|
|
||||||
zone, ok := node.Labels[unversioned.LabelZoneFailureDomain]
|
zone, ok := node.Labels[unversioned.LabelZoneFailureDomain]
|
||||||
if !ok || zone == "" {
|
if !ok || zone == "" {
|
||||||
return "", fmt.Errorf("unknown cluster zone")
|
return "", "", fmt.Errorf("unknown cluster zone")
|
||||||
}
|
}
|
||||||
return zone, nil
|
region, ok := node.Labels[unversioned.LabelZoneRegion]
|
||||||
|
if !ok || region == "" {
|
||||||
|
return "", "", fmt.Errorf("unknown cluster region")
|
||||||
|
}
|
||||||
|
return zone, region, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kd *KubeDNS) getServiceFQDN(service *kapi.Service) string {
|
func (kd *KubeDNS) getServiceFQDN(service *kapi.Service) string {
|
||||||
|
@ -387,12 +387,12 @@ func testValidFederationQueries(t *testing.T, kd *KubeDNS) {
|
|||||||
// Federation suffix is just a domain.
|
// Federation suffix is just a domain.
|
||||||
{
|
{
|
||||||
q: "mysvc.myns.myfederation.svc.cluster.local.",
|
q: "mysvc.myns.myfederation.svc.cluster.local.",
|
||||||
a: "mysvc.myns.myfederation.svc.testcontinent-testreg-testzone.example.com.",
|
a: "mysvc.myns.myfederation.svc.testcontinent-testreg-testzone.testcontinent-testreg.example.com.",
|
||||||
},
|
},
|
||||||
// Federation suffix is a subdomain.
|
// Federation suffix is a subdomain.
|
||||||
{
|
{
|
||||||
q: "secsvc.default.secondfederation.svc.cluster.local.",
|
q: "secsvc.default.secondfederation.svc.cluster.local.",
|
||||||
a: "secsvc.default.secondfederation.svc.testcontinent-testreg-testzone.second.example.com.",
|
a: "secsvc.default.secondfederation.svc.testcontinent-testreg-testzone.testcontinent-testreg.second.example.com.",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,6 +438,7 @@ func newNodes() *kapi.NodeList {
|
|||||||
// format used by the cloud providers to name their zones. But that shouldn't matter
|
// format used by the cloud providers to name their zones. But that shouldn't matter
|
||||||
// for these tests here.
|
// for these tests here.
|
||||||
unversioned.LabelZoneFailureDomain: "testcontinent-testreg-testzone",
|
unversioned.LabelZoneFailureDomain: "testcontinent-testreg-testzone",
|
||||||
|
unversioned.LabelZoneRegion: "testcontinent-testreg",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user