mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-16 06:32:32 +00:00
Add a minion registry that is backed by a cloud provider.
This commit is contained in:
@@ -38,4 +38,6 @@ type TCPLoadBalancer interface {
|
||||
|
||||
type Instances interface {
|
||||
IPAddress(name string) (net.IP, error)
|
||||
// Lists instances that match 'filter' which is a regular expression which must match the entire instance name
|
||||
List(filter string) ([]string, error)
|
||||
}
|
||||
|
@@ -18,13 +18,15 @@ package cloudprovider
|
||||
|
||||
import (
|
||||
"net"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
type FakeCloud struct {
|
||||
Exists bool
|
||||
Err error
|
||||
Calls []string
|
||||
IP net.IP
|
||||
Exists bool
|
||||
Err error
|
||||
Calls []string
|
||||
IP net.IP
|
||||
Machines []string
|
||||
}
|
||||
|
||||
func (f *FakeCloud) addCall(desc string) {
|
||||
@@ -66,3 +68,14 @@ func (f *FakeCloud) IPAddress(instance string) (net.IP, error) {
|
||||
f.addCall("ip-address")
|
||||
return f.IP, f.Err
|
||||
}
|
||||
|
||||
func (f *FakeCloud) List(filter string) ([]string, error) {
|
||||
f.addCall("list")
|
||||
result := []string{}
|
||||
for _, machine := range f.Machines {
|
||||
if match, _ := regexp.MatchString(filter, machine); match {
|
||||
result = append(result, machine)
|
||||
}
|
||||
}
|
||||
return result, f.Err
|
||||
}
|
||||
|
@@ -30,9 +30,10 @@ import (
|
||||
)
|
||||
|
||||
type GCECloud struct {
|
||||
service *compute.Service
|
||||
projectID string
|
||||
zone string
|
||||
service *compute.Service
|
||||
projectID string
|
||||
zone string
|
||||
instanceRE string
|
||||
}
|
||||
|
||||
func getProjectAndZone() (string, string, error) {
|
||||
@@ -179,3 +180,19 @@ func (gce *GCECloud) IPAddress(instance string) (net.IP, error) {
|
||||
}
|
||||
return ip, nil
|
||||
}
|
||||
|
||||
func (gce *GCECloud) List(filter string) ([]string, error) {
|
||||
listCall := gce.service.Instances.List(gce.projectID, gce.zone)
|
||||
if len(filter) > 0 {
|
||||
listCall = listCall.Filter("name eq " + filter)
|
||||
}
|
||||
res, err := listCall.Do()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var instances []string
|
||||
for _, instance := range res.Items {
|
||||
instances = append(instances, instance.Name)
|
||||
}
|
||||
return instances, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user