Last active
May 23, 2016 18:01
-
-
Save rday/b3416a11dddcc2c2f645bbc39fb1b732 to your computer and use it in GitHub Desktop.
Only add services that can be accessed from outside the cluster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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