tczekajlo / kube-consul-register

a tool to register Kubernetes PODs as Consul Services
Apache License 2.0
105 stars 50 forks source link

fix example for registering only key from labels #28

Closed odinsy closed 6 years ago

odinsy commented 6 years ago

In current example service would be registering with key-value pair tag. Correct is production: "tag"

func (p *PodInfo) labelsToTags(containerName string) []string {
    var tags []string
    tags = append(tags, fmt.Sprintf("pod:%s", p.Name))
    tags = append(tags, fmt.Sprintf("node:%s", p.NodeName))
    tags = append(tags, fmt.Sprintf("container:%s", containerName))

    for key, value := range p.Labels {
        // if value is equal to "tag" then set only key as tag
        if value == "tag" {
            tags = append(tags, key)
        } else {
            tags = append(tags, fmt.Sprintf("%s:%s", key, value))
        }
    }
    return tags
}

https://github.com/tczekajlo/kube-consul-register/blob/master/controller/pods/controller.go#L521

tczekajlo commented 6 years ago

Thanks for your PR :)