Add k8s external service CNAMEs (#677)
* Add external service cnames * remove cruft * update CI k8s version * change CI k8s version * min k8s ver for ext services * trying k8s 1.5 * k8s 1.5 requires ports spec * remove kruft * update dns schema version
This commit is contained in:
parent
2f2c90f391
commit
d917ff5ac2
11 changed files with 293 additions and 16 deletions
|
@ -55,7 +55,7 @@ const (
|
|||
// PodModeInsecure is where pod requests are answered without verfying they exist
|
||||
PodModeInsecure = "insecure"
|
||||
// DNSSchemaVersion is the schema version: https://github.com/kubernetes/dns/blob/master/docs/specification.md
|
||||
DNSSchemaVersion = "1.0.0"
|
||||
DNSSchemaVersion = "1.0.1"
|
||||
)
|
||||
|
||||
type endpoint struct {
|
||||
|
@ -97,7 +97,7 @@ func (k *Kubernetes) Services(state request.Request, exact bool, opt middleware.
|
|||
}
|
||||
|
||||
switch state.Type() {
|
||||
case "A", "SRV":
|
||||
case "A", "CNAME":
|
||||
if state.Type() == "A" && isDefaultNS(state.Name(), r) {
|
||||
// If this is an A request for "ns.dns", respond with a "fake" record for coredns.
|
||||
// SOA records always use this hardcoded name
|
||||
|
@ -106,6 +106,16 @@ func (k *Kubernetes) Services(state request.Request, exact bool, opt middleware.
|
|||
}
|
||||
s, e := k.Records(r)
|
||||
return s, nil, e // Haven't implemented debug queries yet.
|
||||
case "SRV":
|
||||
s, e := k.Records(r)
|
||||
// SRV for external services is not yet implemented, so remove those records
|
||||
noext := []msg.Service{}
|
||||
for _, svc := range s {
|
||||
if t, _ := svc.HostType(); t != dns.TypeCNAME {
|
||||
noext = append(noext, svc)
|
||||
}
|
||||
}
|
||||
return noext, nil, e
|
||||
case "TXT":
|
||||
err := k.recordsForTXT(r, &svcs)
|
||||
return svcs, nil, err
|
||||
|
@ -373,6 +383,14 @@ func (k *Kubernetes) getRecordsForK8sItems(services []service, pods []pod, zone
|
|||
Port: int(p.Port)}
|
||||
records = append(records, s)
|
||||
}
|
||||
// If the addr is not an IP (i.e. an external service), add the record ...
|
||||
s := msg.Service{
|
||||
Key: strings.Join([]string{zonePath, "svc", svc.namespace, svc.name}, "/"),
|
||||
Host: svc.addr}
|
||||
if t, _ := s.HostType(); t == dns.TypeCNAME {
|
||||
records = append(records, s)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -466,8 +484,16 @@ func (k *Kubernetes) findServices(r recordRequest) ([]service, error) {
|
|||
if nsWildcard && (len(k.Namespaces) > 0) && (!dnsstrings.StringInSlice(svc.Namespace, k.Namespaces)) {
|
||||
continue
|
||||
}
|
||||
s := service{name: svc.Name, namespace: svc.Namespace, addr: svc.Spec.ClusterIP}
|
||||
if s.addr != api.ClusterIPNone {
|
||||
s := service{name: svc.Name, namespace: svc.Namespace}
|
||||
// External Service
|
||||
if svc.Spec.ExternalName != "" {
|
||||
s.addr = svc.Spec.ExternalName
|
||||
resultItems = append(resultItems, s)
|
||||
continue
|
||||
}
|
||||
// ClusterIP service
|
||||
if svc.Spec.ClusterIP != api.ClusterIPNone {
|
||||
s.addr = svc.Spec.ClusterIP
|
||||
for _, p := range svc.Spec.Ports {
|
||||
if !(symbolMatches(r.port, strings.ToLower(p.Name), portWildcard) && symbolMatches(r.protocol, strings.ToLower(string(p.Protocol)), protocolWildcard)) {
|
||||
continue
|
||||
|
@ -478,6 +504,7 @@ func (k *Kubernetes) findServices(r recordRequest) ([]service, error) {
|
|||
continue
|
||||
}
|
||||
// Headless service
|
||||
s.addr = svc.Spec.ClusterIP
|
||||
endpointsList := k.APIConn.EndpointsList()
|
||||
|
||||
for _, ep := range endpointsList.Items {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue