Skip to content

Commit

Permalink
ClusterIP service support
Browse files Browse the repository at this point in the history
- First pass at addresssing kubernetes-sigs#187 by allowing services with type ClusterIP to be directly supported
  • Loading branch information
Justin Nauman committed May 5, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent d6222a4 commit 69cc1aa
Showing 2 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -42,3 +42,4 @@ cscope.*
# coverage output
cover.out
*.coverprofile
external-dns
24 changes: 21 additions & 3 deletions source/service.go
Original file line number Diff line number Diff line change
@@ -134,14 +134,33 @@ func (sc *serviceSource) endpointsFromTemplate(svc *v1.Service) ([]*endpoint.End
// endpointsFromService extracts the endpoints from a service object
func endpointsFromService(svc *v1.Service) []*endpoint.Endpoint {
var endpoints []*endpoint.Endpoint

// Get the desired hostname of the service from the annotation.
hostname, exists := svc.Annotations[hostnameAnnotationKey]
if !exists {
return nil
}

// Create a corresponding endpoint for each configured external entrypoint.
switch svc.Spec.Type {
case "LoadBalancer":
endpoints = extractLoadBalancerEndpoints(svc, hostname)
case "ClusterIP":
endpoints = extractServiceIps(svc, hostname)
}

return endpoints
}

func extractServiceIps(svc *v1.Service, hostname string) []*endpoint.Endpoint {
if svc.Spec.ClusterIP == "None" {
log.Debugf("Unable to associate %s headless service with a Cluster IP", svc.Name)
return []*endpoint.Endpoint{}
}

return []*endpoint.Endpoint{endpoint.NewEndpoint(hostname, svc.Spec.ClusterIP, "")}
}

func extractLoadBalancerEndpoints(svc *v1.Service, hostname string) []*endpoint.Endpoint {
var endpoints []*endpoint.Endpoint
for _, lb := range svc.Status.LoadBalancer.Ingress {
if lb.IP != "" {
//TODO(ideahitme): consider retrieving record type from resource annotation instead of empty
@@ -151,6 +170,5 @@ func endpointsFromService(svc *v1.Service) []*endpoint.Endpoint {
endpoints = append(endpoints, endpoint.NewEndpoint(hostname, lb.Hostname, ""))
}
}

return endpoints
}

0 comments on commit 69cc1aa

Please sign in to comment.