Skip to content

Commit

Permalink
Merge pull request #11 from robbrockbank/v0.12.1-calico-w-k8s
Browse files Browse the repository at this point in the history
Update Calico confd base image from bacongobbler v0.12.1
  • Loading branch information
robbrockbank committed May 22, 2017
2 parents 346c09e + edf92b2 commit 3fb34be
Show file tree
Hide file tree
Showing 834 changed files with 913 additions and 297,870 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
bin/
.idea
vendor
.go-pkg-cache
51 changes: 51 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

# Disable make's implicit rules, which are not useful for golang, and slow down the build
# considerably.
.SUFFIXES:

all: bin/confd

GO_BUILD_CONTAINER?=calico/go-build:v0.4

# All go files.
GO_FILES:=$(shell find . -type f -name '*.go')

# Figure out the users UID. This is needed to run docker containers
# as the current user and ensure that files built inside containers are
# owned by the current user.
MY_UID:=$(shell id -u)

DOCKER_GO_BUILD := mkdir -p .go-pkg-cache && \
docker run --rm \
--net=host \
$(EXTRA_DOCKER_ARGS) \
-e LOCAL_USER_ID=$(MY_UID) \
-v ${CURDIR}:/go/src/github.com/kelseyhightower/confd:rw \
-v ${CURDIR}/.go-pkg-cache:/go/pkg:rw \
-w /go/src/github.com/kelseyhightower/confd \
$(GO_BUILD_CONTAINER)

# Update the vendored dependencies with the latest upstream versions matching
# our glide.yaml. If there are any changes, this updates glide.lock
# as a side effect. Unless you're adding/updating a dependency, you probably
# want to use the vendor target to install the versions from glide.lock.
.PHONY: update-vendor
update-vendor:
mkdir -p $$HOME/.glide
$(DOCKER_GO_BUILD) glide up --strip-vendor
touch vendor/.up-to-date

# vendor is a shortcut for force rebuilding the go vendor directory.
.PHONY: vendor
vendor vendor/.up-to-date: glide.lock
mkdir -p $$HOME/.glide
$(DOCKER_GO_BUILD) glide install --strip-vendor
touch vendor/.up-to-date

bin/confd: $(GO_FILES) vendor/.up-to-date
@echo Building confd...
mkdir -p bin
$(DOCKER_GO_BUILD) \
sh -c 'go build -v -i -o $@ "github.com/kelseyhightower/confd" && \
( ldd bin/confd 2>&1 | grep -q "Not a valid dynamic program" || \
( echo "Error: bin/confd was not statically linked"; false ) )'
4 changes: 4 additions & 0 deletions backends/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/kelseyhightower/confd/backends/etcd"
"github.com/kelseyhightower/confd/backends/etcdv3"
"github.com/kelseyhightower/confd/backends/file"
"github.com/kelseyhightower/confd/backends/k8s"
"github.com/kelseyhightower/confd/backends/metad"
"github.com/kelseyhightower/confd/backends/rancher"
"github.com/kelseyhightower/confd/backends/redis"
Expand Down Expand Up @@ -80,6 +81,9 @@ func New(config Config) (StoreClient, error) {
return stackengine.NewStackEngineClient(backendNodes, config.Scheme, config.ClientCert, config.ClientKey, config.ClientCaKeys, config.AuthToken)
case "metad":
return metad.NewMetadClient(backendNodes[0])
case "k8s":
log.Info("Backend set to k8s")
return k8s.NewK8sClient(config.Kubeconfig)
}
return nil, errors.New("Invalid backend")
}
1 change: 1 addition & 0 deletions backends/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ type Config struct {
AppID string
UserID string
YAMLFile string
Kubeconfig string
}
16 changes: 9 additions & 7 deletions backends/etcd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,16 @@ func nodeWalk(node *client.Node, vars map[string]string) error {
}

func (c *Client) WatchPrefix(prefix string, keys []string, waitIndex uint64, stopChan chan bool) (uint64, error) {
// return something > 0 to trigger a key retrieval from the store
if waitIndex == 0 {
return 1, nil
resp, err := c.client.Get(context.Background(), prefix, &client.GetOptions{Quorum: true})
if err != nil {
return 0, err
}
return resp.Index, nil
}

// Setting AfterIndex to 0 (default) means that the Watcher
// should start watching for events starting at the current
// index, whatever that may be.
watcher := c.client.Watcher(prefix, &client.WatcherOptions{AfterIndex: uint64(0), Recursive: true})
// Create the watcher.
watcher := c.client.Watcher(prefix, &client.WatcherOptions{AfterIndex: waitIndex, Recursive: true})
ctx, cancel := context.WithCancel(context.Background())
cancelRoutine := make(chan bool)
defer close(cancelRoutine)
Expand Down Expand Up @@ -154,9 +155,10 @@ func (c *Client) WatchPrefix(prefix string, keys []string, waitIndex uint64, sto
// This is not an exact match on the key so there is a chance
// we will still pickup on false positives. The net win here
// is reducing the scope of keys that can trigger updates.
waitIndex = resp.Node.ModifiedIndex
for _, k := range keys {
if strings.HasPrefix(resp.Node.Key, k) {
return resp.Node.ModifiedIndex, err
return waitIndex, err
}
}
}
Expand Down
Loading

0 comments on commit 3fb34be

Please sign in to comment.