Skip to content

Commit

Permalink
Merge pull request #25 from alena1108/emptyenv
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
Alena Prokharchyk committed Jan 14, 2016
2 parents 862dbd0 + 450d47d commit 4a659b1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 22 additions & 3 deletions metadata/metadata.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,52 @@
package metadata

import (
"fmt"
"github.com/Sirupsen/logrus"
"github.com/rancher/external-dns/dns"
"github.com/rancher/go-rancher-metadata/metadata"
"time"
)

const (
metadataUrl = "http://rancher-metadata/latest"
metadataUrl = "http://rancher-metadata/2015-07-25"
)

type MetadataClient struct {
MetadataClient *metadata.Client
EnvironmentName string
}

func getEnvironmentName(m *metadata.Client) (string, error) {
timeout := 30 * time.Second
var err error
var stack metadata.Stack
for i := 1 * time.Second; i < timeout; i *= time.Duration(2) {
stack, err = m.GetSelfStack()
if err != nil {
logrus.Errorf("Error reading stack info: %v...will retry", err)
time.Sleep(i)
} else {
return stack.EnvironmentName, nil
}
}
return "", fmt.Errorf("Error reading stack info: %v", err)
}

func NewMetadataClient() (*MetadataClient, error) {
m, err := metadata.NewClientAndWait(metadataUrl)
if err != nil {
logrus.Fatalf("Failed to configure rancher-metadata: %v", err)
}
selfStack, err := m.GetSelfStack()

envName, err := getEnvironmentName(m)
if err != nil {
logrus.Fatalf("Error reading stack info: %v", err)
}

return &MetadataClient{
MetadataClient: m,
EnvironmentName: selfStack.EnvironmentName,
EnvironmentName: envName,
}, nil
}

Expand Down

0 comments on commit 4a659b1

Please sign in to comment.