mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-15 22:20:51 +00:00
Add IP look up if the Cloud Provider is not null
Add Instance info to the Cloud Provider interface
This commit is contained in:
@@ -16,10 +16,16 @@ limitations under the License.
|
||||
|
||||
package cloudprovider
|
||||
|
||||
import (
|
||||
"net"
|
||||
)
|
||||
|
||||
// CloudInterface is an abstract, pluggable interface for cloud providers
|
||||
type Interface interface {
|
||||
// TCPLoadBalancer returns a balancer interface, or nil if none is supported. Returns an error if one occurs.
|
||||
TCPLoadBalancer() (TCPLoadBalancer, error)
|
||||
// Instances returns an instances interface, or nil if none is supported. Returns an error if one occurs.
|
||||
Instances() (Instances, error)
|
||||
}
|
||||
|
||||
type TCPLoadBalancer interface {
|
||||
@@ -29,3 +35,7 @@ type TCPLoadBalancer interface {
|
||||
UpdateTCPLoadBalancer(name, region string, hosts []string) error
|
||||
DeleteTCPLoadBalancer(name, region string) error
|
||||
}
|
||||
|
||||
type Instances interface {
|
||||
IPAddress(name string) (net.IP, error)
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ package cloudprovider
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -82,6 +83,10 @@ func (gce *GCECloud) TCPLoadBalancer() (TCPLoadBalancer, error) {
|
||||
return gce, nil
|
||||
}
|
||||
|
||||
func (gce *GCECloud) Instances() (Instances, error) {
|
||||
return gce, nil
|
||||
}
|
||||
|
||||
func makeHostLink(projectID, zone, host string) string {
|
||||
ix := strings.Index(host, ".")
|
||||
if ix != -1 {
|
||||
@@ -162,3 +167,15 @@ func (gce *GCECloud) DeleteTCPLoadBalancer(name, region string) error {
|
||||
_, err = gce.service.TargetPools.Delete(gce.projectID, region, name).Do()
|
||||
return err
|
||||
}
|
||||
|
||||
func (gce *GCECloud) IPAddress(instance string) (net.IP, error) {
|
||||
res, err := gce.service.Instances.Get(gce.projectID, gce.zone, instance).Do()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ip := net.ParseIP(res.NetworkInterfaces[0].AccessConfigs[0].NatIP)
|
||||
if ip == nil {
|
||||
return nil, fmt.Errorf("Invalid network IP: %s", res.NetworkInterfaces[0].AccessConfigs[0].NatIP)
|
||||
}
|
||||
return ip, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user