mirror of https://github.com/k3s-io/k3s
parent
5b43a12775
commit
b9dfe1b737
|
@ -352,18 +352,35 @@ func getServerByName(client *gophercloud.ServiceClient, name string) (*servers.S
|
||||||
return &serverList[0], nil
|
return &serverList[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func findAddrs(netblob interface{}) []string {
|
func getAddressesByName(client *gophercloud.ServiceClient, name string) ([]api.NodeAddress, error) {
|
||||||
// Run-time types for the win :(
|
srv, err := getServerByName(client, name)
|
||||||
ret := []string{}
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
addrs := []api.NodeAddress{}
|
||||||
|
|
||||||
|
for network, netblob := range srv.Addresses {
|
||||||
list, ok := netblob.([]interface{})
|
list, ok := netblob.([]interface{})
|
||||||
if !ok {
|
if !ok {
|
||||||
return ret
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range list {
|
for _, item := range list {
|
||||||
|
var addressType api.NodeAddressType
|
||||||
|
|
||||||
props, ok := item.(map[string]interface{})
|
props, ok := item.(map[string]interface{})
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extIPType, ok := props["OS-EXT-IPS:type"]
|
||||||
|
if (ok && extIPType == "floating") || (!ok && network == "public") {
|
||||||
|
addressType = api.NodeExternalIP
|
||||||
|
} else {
|
||||||
|
addressType = api.NodeInternalIP
|
||||||
|
}
|
||||||
|
|
||||||
tmp, ok := props["addr"]
|
tmp, ok := props["addr"]
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
|
@ -372,38 +389,53 @@ func findAddrs(netblob interface{}) []string {
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ret = append(ret, addr)
|
|
||||||
|
api.AddToNodeAddresses(&addrs,
|
||||||
|
api.NodeAddress{
|
||||||
|
Type: addressType,
|
||||||
|
Address: addr,
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return ret
|
}
|
||||||
|
|
||||||
|
// AccessIPs are usually duplicates of "public" addresses.
|
||||||
|
if srv.AccessIPv4 != "" {
|
||||||
|
api.AddToNodeAddresses(&addrs,
|
||||||
|
api.NodeAddress{
|
||||||
|
Type: api.NodeExternalIP,
|
||||||
|
Address: srv.AccessIPv4,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if srv.AccessIPv6 != "" {
|
||||||
|
api.AddToNodeAddresses(&addrs,
|
||||||
|
api.NodeAddress{
|
||||||
|
Type: api.NodeExternalIP,
|
||||||
|
Address: srv.AccessIPv6,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return addrs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAddressByName(api *gophercloud.ServiceClient, name string) (string, error) {
|
func getAddressByName(client *gophercloud.ServiceClient, name string) (string, error) {
|
||||||
srv, err := getServerByName(api, name)
|
addrs, err := getAddressesByName(client, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
} else if len(addrs) == 0 {
|
||||||
|
|
||||||
var s string
|
|
||||||
if s == "" {
|
|
||||||
if tmp := findAddrs(srv.Addresses["private"]); len(tmp) >= 1 {
|
|
||||||
s = tmp[0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if s == "" {
|
|
||||||
if tmp := findAddrs(srv.Addresses["public"]); len(tmp) >= 1 {
|
|
||||||
s = tmp[0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if s == "" {
|
|
||||||
s = srv.AccessIPv4
|
|
||||||
}
|
|
||||||
if s == "" {
|
|
||||||
s = srv.AccessIPv6
|
|
||||||
}
|
|
||||||
if s == "" {
|
|
||||||
return "", ErrNoAddressFound
|
return "", ErrNoAddressFound
|
||||||
}
|
}
|
||||||
return s, nil
|
|
||||||
|
for _, addr := range addrs {
|
||||||
|
if addr.Type == api.NodeInternalIP {
|
||||||
|
return addr.Address, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return addrs[0].Address, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementation of Instances.CurrentNodeName
|
// Implementation of Instances.CurrentNodeName
|
||||||
|
@ -418,39 +450,11 @@ func (i *Instances) AddSSHKeyToAllInstances(user string, keyData []byte) error {
|
||||||
func (i *Instances) NodeAddresses(name string) ([]api.NodeAddress, error) {
|
func (i *Instances) NodeAddresses(name string) ([]api.NodeAddress, error) {
|
||||||
glog.V(4).Infof("NodeAddresses(%v) called", name)
|
glog.V(4).Infof("NodeAddresses(%v) called", name)
|
||||||
|
|
||||||
srv, err := getServerByName(i.compute, name)
|
addrs, err := getAddressesByName(i.compute, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
addrs := []api.NodeAddress{}
|
|
||||||
|
|
||||||
for _, addr := range findAddrs(srv.Addresses["private"]) {
|
|
||||||
addrs = append(addrs, api.NodeAddress{
|
|
||||||
Type: api.NodeInternalIP,
|
|
||||||
Address: addr,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, addr := range findAddrs(srv.Addresses["public"]) {
|
|
||||||
addrs = append(addrs, api.NodeAddress{
|
|
||||||
Type: api.NodeExternalIP,
|
|
||||||
Address: addr,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// AccessIPs are usually duplicates of "public" addresses.
|
|
||||||
api.AddToNodeAddresses(&addrs,
|
|
||||||
api.NodeAddress{
|
|
||||||
Type: api.NodeExternalIP,
|
|
||||||
Address: srv.AccessIPv6,
|
|
||||||
},
|
|
||||||
api.NodeAddress{
|
|
||||||
Type: api.NodeExternalIP,
|
|
||||||
Address: srv.AccessIPv4,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
glog.V(4).Infof("NodeAddresses(%v) => %v", name, addrs)
|
glog.V(4).Infof("NodeAddresses(%v) => %v", name, addrs)
|
||||||
return addrs, nil
|
return addrs, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue