traefik/vendor/github.com/rancher/go-rancher-metadata/main.go
Martin Baillie 9cb07d026f Refactor into dual Rancher API/Metadata providers
Introduces Rancher's metadata service as an optional provider source for
Traefik, enabled by setting `rancher.MetadataService`.

The provider uses a long polling technique to watch the metadata service and
obtain near instantaneous updates. Alternatively it can be configured to poll
the metadata service every `rancher.RefreshSeconds` by setting
`rancher.MetadataPoll`.

The refactor splits API and metadata service code into separate source
files respectively, and specific configuration is deferred to
sub-structs.

Incorporates bugfix #1414
2017-06-20 19:08:53 +02:00

31 lines
637 B
Go

package main
import (
"time"
"github.com/Sirupsen/logrus"
"github.com/rancher/go-rancher-metadata/metadata"
)
const (
metadataUrl = "http://rancher-metadata/2015-12-19"
)
func main() {
m := metadata.NewClient(metadataUrl)
version := "init"
for {
newVersion, err := m.GetVersion()
if err != nil {
logrus.Errorf("Error reading metadata version: %v", err)
} else if version == newVersion {
logrus.Debug("No changes in metadata version")
} else {
logrus.Debugf("Metadata version has changed, oldVersion=[%s], newVersion=[%s]", version, newVersion)
version = newVersion
}
time.Sleep(5 * time.Second)
}
}