Skip to content

Instantly share code, notes, and snippets.

@rday
Last active May 23, 2016 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rday/b3416a11dddcc2c2f645bbc39fb1b732 to your computer and use it in GitHub Desktop.
Save rday/b3416a11dddcc2c2f645bbc39fb1b732 to your computer and use it in GitHub Desktop.
Only add services that can be accessed from outside the cluster
if msg.Type == ADDED || msg.Type == MODIFIED {
var service discovery.Service
// ClusterIP services are only accessible inside the cluster. They
// should be located with env vars provided by k8s. We will only announce
// externally available services here.
if msg.Object.Spec.Type == LOADBALANCER {
endpoints := make([]string, 0, len(msg.Object.Spec.Ports)*len(msg.Object.Status.LoadBalancer.Ingress))
for _, ingress := range msg.Object.Status.LoadBalancer.Ingress {
for _, port := range msg.Object.Spec.Ports {
endpoints = append(endpoints, fmt.Sprintf("%s:%d", ingress.Hostname, port.Port))
}
}
service = discovery.Service{
Name: msg.Object.Meta.Name,
Description: "Autodetected service",
Endpoints: endpoints,
}
}
glog.Info("Announcing service ", service)
manager.AnnounceService(&service)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment