Skip to content

Commit

Permalink
Merge pull request #42 from janeczku/check-container-state
Browse files Browse the repository at this point in the history
Include only running/healthy containers
  • Loading branch information
janeczku authored Jul 27, 2016
2 parents 7003e99 + 26dcef8 commit a7280c0
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 16 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.

27 changes: 21 additions & 6 deletions metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

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

type MetadataClient struct {
Expand Down Expand Up @@ -71,7 +71,7 @@ func (m *MetadataClient) getContainersDnsRecords(dnsEntries map[string]utils.Dns
}

for _, container := range containers {
if len(container.ServiceName) == 0 {
if len(container.ServiceName) == 0 || len(container.Ports) == 0 || !containerStateOK(container) {
continue
}

Expand All @@ -84,10 +84,6 @@ func (m *MetadataClient) getContainersDnsRecords(dnsEntries map[string]utils.Dns
}
}

if len(container.Ports) == 0 {
continue
}

hostUUID := container.HostUUID
if len(hostUUID) == 0 {
logrus.Debugf("Container's %v host_uuid is empty", container.Name)
Expand Down Expand Up @@ -126,3 +122,22 @@ func addToDnsEntries(dnsEntry utils.DnsRecord, dnsEntries map[string]utils.DnsRe
dnsEntry = utils.DnsRecord{dnsEntry.Fqdn, records, "A", config.TTL}
dnsEntries[dnsEntry.Fqdn] = dnsEntry
}

func containerStateOK(container metadata.Container) bool {
switch container.State {
case "starting":
case "running":
default:
return false
}

switch container.HealthState {
case "healthy":
case "updating-healthy":
case "":
default:
return false
}

return true
}

0 comments on commit a7280c0

Please sign in to comment.