Skip to content

Commit

Permalink
Merge pull request #11 from cloudwatt/opt-consul-tag
Browse files Browse the repository at this point in the history
Add an option to change consul tag
  • Loading branch information
Marc Fouché authored Apr 17, 2018
2 parents d2df900 + 918ed1c commit 0c5de9e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Kube2consul runs in a kubernetes cluster by default. It is able to work out of c
| Command line option | Environment option | Default value |
| ------------------- | -------------------- | ------------------------- |
| `-consul-api` | `K2C_CONSUL_API` | `"127.0.0.1:8500"` |
| `-consul-tag` | `K2C_CONSUL_TAG` | `"kube2consul"` |
| `-consul-token` | `K2C_CONSUL_TOKEN` | `""` |
| `-kubeconfig` | `K2C_KUBECONFIG` | `""` |
| `-kubernetes-api` | `K2C_KUBERNETES_API` | `""` |
| `-resync-period` | `K2C_RESYNC_PERIOD` | `30` |
| `-kubeconfig` | `K2C_KUBECONFIG` | `""` |
7 changes: 4 additions & 3 deletions consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"

"github.com/golang/glog"
consulapi "github.com/hashicorp/consul/api"
)
Expand All @@ -27,7 +28,7 @@ func (k2c *kube2consul) registerEndpoint(e Endpoint) error {
return nil
}

consulServices, _, err := k2c.consulCatalog.Service(e.Name, consulTag, nil)
consulServices, _, err := k2c.consulCatalog.Service(e.Name, opts.consulTag, nil)
if err != nil {
return fmt.Errorf("Failed to get services: %v", err)
}
Expand All @@ -41,7 +42,7 @@ func (k2c *kube2consul) registerEndpoint(e Endpoint) error {
service := &consulapi.AgentService{
Service: e.Name,
Port: int(e.Port),
Tags: []string{consulTag},
Tags: []string{opts.consulTag},
}

reg := &consulapi.CatalogRegistration{
Expand Down Expand Up @@ -70,7 +71,7 @@ func endpointExists(refName, address string, port int, endpoints []Endpoint) boo

func (k2c *kube2consul) removeDeletedEndpoints(serviceName string, endpoints []Endpoint) error {
updatedNodes := make(map[string]struct{})
services, _, err := k2c.consulCatalog.Service(serviceName, consulTag, nil)
services, _, err := k2c.consulCatalog.Service(serviceName, opts.consulTag, nil)
if err != nil {
return fmt.Errorf("Failed to get services: %v", err)
}
Expand Down
8 changes: 3 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ var (
lockCh <-chan struct{}
)

const (
consulTag = "kube2consul"
)

type kube2consul struct {
consulCatalog *consulapi.Catalog
endpointsStore kcache.Store
Expand All @@ -48,6 +44,7 @@ type cliOpts struct {
lock bool
lockKey string
noHealth bool
consulTag string
}

func init() {
Expand All @@ -60,6 +57,7 @@ func init() {
flag.BoolVar(&opts.lock, "lock", false, "Acquires a lock with consul to ensure that only one instance of kube2consul is running")
flag.StringVar(&opts.lockKey, "lock-key", "locks/kube2consul/.lock", "Key used for locking")
flag.BoolVar(&opts.noHealth, "no-health", false, "Disable endpoint /health on port 8080")
flag.StringVar(&opts.consulTag, "consul-tag", "kube2consul", "Tag setted on services to identify services managed by kube2consul in Consul")
}

func inSlice(value string, slice []string) bool {
Expand Down Expand Up @@ -87,7 +85,7 @@ func (k2c *kube2consul) RemoveDNSGarbage() {
}

for name, tags := range services {
if !inSlice(consulTag, tags) {
if !inSlice(opts.consulTag, tags) {
continue
}

Expand Down

0 comments on commit 0c5de9e

Please sign in to comment.