diff --git a/vendor.conf b/vendor.conf index cdd30b7..ee93168 100644 --- a/vendor.conf +++ b/vendor.conf @@ -18,7 +18,7 @@ github.com/juju/ratelimit 77ed1c8 github.com/kolo/xmlrpc 0826b98 github.com/miekg/dns 48ab660 github.com/prasmussen/gandi-api 13205dc -github.com/rancher/go-rancher-metadata/metadata cd79328 +github.com/rancher/go-rancher-metadata/metadata 2ba6d4e github.com/rancher/go-rancher/client 37c17e4 github.com/tent/http-link-go ac974c6 github.com/valyala/fasttemplate 3b87495 diff --git a/vendor/github.com/rancher/go-rancher-metadata/metadata/change.go b/vendor/github.com/rancher/go-rancher-metadata/metadata/change.go index ac0fc2c..8d6c175 100644 --- a/vendor/github.com/rancher/go-rancher-metadata/metadata/change.go +++ b/vendor/github.com/rancher/go-rancher-metadata/metadata/change.go @@ -9,8 +9,10 @@ import ( ) func (m *client) OnChangeWithError(intervalSeconds int, do func(string)) error { - version := "init" + return m.onChangeFromVersionWithError("init", intervalSeconds, do) +} +func (m *client) onChangeFromVersionWithError(version string, intervalSeconds int, do func(string)) error { for { newVersion, err := m.waitVersion(intervalSeconds, version) if err != nil { @@ -28,20 +30,35 @@ func (m *client) OnChangeWithError(intervalSeconds int, do func(string)) error { } func (m *client) OnChange(intervalSeconds int, do func(string)) { + version := "init" + updateVersionAndDo := func(v string) { + version = v + do(version) + } interval := time.Duration(intervalSeconds) for { - if err := m.OnChangeWithError(intervalSeconds, do); err != nil { + if err := m.onChangeFromVersionWithError(version, intervalSeconds, updateVersionAndDo); err != nil { logrus.Errorf("Error reading metadata version: %v", err) } time.Sleep(interval * time.Second) } } -func (m *client) waitVersion(maxWait int, version string) (string, error) { - resp, err := m.SendRequest(fmt.Sprintf("/version?wait=true&value=%s&maxWait=%d", version, maxWait)) - if err != nil { - return "", err - } - err = json.Unmarshal(resp, &version) - return version, err +type timeout interface { + Timeout() bool +} + +func (m *client) waitVersion(maxWait int, version string) (string, error) { + for { + resp, err := m.SendRequest(fmt.Sprintf("/version?wait=true&value=%s&maxWait=%d", version, maxWait)) + if err != nil { + t, ok := err.(timeout) + if ok && t.Timeout() { + continue + } + return "", err + } + err = json.Unmarshal(resp, &version) + return version, err + } } diff --git a/vendor/github.com/rancher/go-rancher-metadata/metadata/types.go b/vendor/github.com/rancher/go-rancher-metadata/metadata/types.go index 3e2836a..20b1c2e 100644 --- a/vendor/github.com/rancher/go-rancher-metadata/metadata/types.go +++ b/vendor/github.com/rancher/go-rancher-metadata/metadata/types.go @@ -74,11 +74,13 @@ type Container struct { } type Network struct { - Name string `json:"name"` - UUID string `json:"uuid"` - Metadata map[string]interface{} `json:"metadata"` - HostPorts bool `json:"host_ports"` - Default bool `json:"is_default"` + Name string `json:"name"` + UUID string `json:"uuid"` + Metadata map[string]interface{} `json:"metadata"` + HostPorts bool `json:"host_ports"` + Default bool `json:"is_default"` + Policy []NetworkPolicyRule `json:"policy,omitempty"` + DefaultPolicyAction string `json:"default_policy_action"` } type Host struct { @@ -123,3 +125,21 @@ type LBStickinessPolicy struct { Postonly bool `json:"postonly"` Mode string `json:"mode"` } + +type NetworkPolicyRuleBetween struct { + Selector string `yaml:"selector,omitempty"` + GroupBy string `yaml:"groupBy,omitempty"` +} + +type NetworkPolicyRuleMember struct { + Selector string `yaml:"selector,omitempty"` +} + +type NetworkPolicyRule struct { + From *NetworkPolicyRuleMember `yaml:"from"` + To *NetworkPolicyRuleMember `yaml:"to"` + Ports []string `yaml:"ports"` + Within string `yaml:"within"` + Between *NetworkPolicyRuleBetween `yaml:"between"` + Action string `yaml:"action"` +}