mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
Add a clusters interface and GCE implementation.
This commit is contained in:
parent
8c358f0cae
commit
aabf1c3573
@ -101,6 +101,10 @@ func newAWSCloud(config io.Reader, authFunc AuthFunc) (*AWSCloud, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (aws *AWSCloud) Clusters() (cloudprovider.Clusters, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// TCPLoadBalancer returns an implementation of TCPLoadBalancer for Amazon Web Services.
|
||||
func (aws *AWSCloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
|
||||
return nil, false
|
||||
|
@ -30,6 +30,16 @@ type Interface interface {
|
||||
Instances() (Instances, bool)
|
||||
// Zones returns a zones interface. Also returns true if the interface is supported, false otherwise.
|
||||
Zones() (Zones, bool)
|
||||
// Clusters returns a clusters interface. Also returns true if the interface is supported, false otherwise.
|
||||
Clusters() (Clusters, bool)
|
||||
}
|
||||
|
||||
// Clusters is an abstract, pluggable interface for clusters of containers.
|
||||
type Clusters interface {
|
||||
// List lists the names of the available clusters.
|
||||
ListClusters() ([]string, error)
|
||||
// Master gets back the address (either DNS name or IP address) of the master node for the cluster.
|
||||
Master(clusterName string) (string, error)
|
||||
}
|
||||
|
||||
// TCPLoadBalancer is an abstract, pluggable interface for TCP load balancers.
|
||||
|
@ -45,8 +45,11 @@ func (f *FakeCloud) ClearCalls() {
|
||||
f.Calls = []string{}
|
||||
}
|
||||
|
||||
func (f *FakeCloud) Clusters() (cloudprovider.Clusters, bool) {
|
||||
return f, true
|
||||
}
|
||||
|
||||
// TCPLoadBalancer returns a fake implementation of TCPLoadBalancer.
|
||||
//
|
||||
// Actually it just returns f itself.
|
||||
func (f *FakeCloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
|
||||
return f, true
|
||||
|
@ -30,6 +30,7 @@ import (
|
||||
|
||||
"code.google.com/p/goauth2/compute/serviceaccount"
|
||||
compute "code.google.com/p/google-api-go-client/compute/v1"
|
||||
container "code.google.com/p/google-api-go-client/container/v1beta1"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/resources"
|
||||
@ -39,10 +40,11 @@ import (
|
||||
|
||||
// GCECloud is an implementation of Interface, TCPLoadBalancer and Instances for Google Compute Engine.
|
||||
type GCECloud struct {
|
||||
service *compute.Service
|
||||
projectID string
|
||||
zone string
|
||||
instanceID string
|
||||
service *compute.Service
|
||||
containerService *container.Service
|
||||
projectID string
|
||||
zone string
|
||||
instanceID string
|
||||
}
|
||||
|
||||
func init() {
|
||||
@ -115,14 +117,23 @@ func newGCECloud() (*GCECloud, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
containerSvc, err := container.New(client)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &GCECloud{
|
||||
service: svc,
|
||||
projectID: projectID,
|
||||
zone: zone,
|
||||
instanceID: instanceID,
|
||||
service: svc,
|
||||
containerService: containerSvc,
|
||||
projectID: projectID,
|
||||
zone: zone,
|
||||
instanceID: instanceID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (gce *GCECloud) Clusters() (cloudprovider.Clusters, bool) {
|
||||
return gce, true
|
||||
}
|
||||
|
||||
// TCPLoadBalancer returns an implementation of TCPLoadBalancer for Google Compute Engine.
|
||||
func (gce *GCECloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
|
||||
return gce, true
|
||||
@ -385,3 +396,19 @@ func (gce *GCECloud) convertDiskToAttachedDisk(disk *compute.Disk, readWrite str
|
||||
Type: "PERSISTENT",
|
||||
}
|
||||
}
|
||||
|
||||
func (gce *GCECloud) ListClusters() ([]string, error) {
|
||||
list, err := gce.containerService.Projects.Clusters.List(gce.projectID).Do()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := []string{}
|
||||
for _, cluster := range list.Clusters {
|
||||
result = append(result, cluster.Name)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (gce *GCECloud) Master(clusterName string) (string, error) {
|
||||
return "k8s-" + clusterName + "-master.internal", nil
|
||||
}
|
||||
|
@ -208,6 +208,10 @@ func (i *Instances) GetNodeResources(name string) (*api.NodeResources, error) {
|
||||
return rsrc, nil
|
||||
}
|
||||
|
||||
func (aws *OpenStack) Clusters() (cloudprovider.Clusters, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (os *OpenStack) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
@ -95,6 +95,10 @@ func newOVirtCloud(config io.Reader) (*OVirtCloud, error) {
|
||||
return &OVirtCloud{VmsRequest: request}, nil
|
||||
}
|
||||
|
||||
func (aws *OVirtCloud) Clusters() (cloudprovider.Clusters, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// TCPLoadBalancer returns an implementation of TCPLoadBalancer for oVirt cloud
|
||||
func (v *OVirtCloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
|
||||
return nil, false
|
||||
|
@ -80,6 +80,10 @@ func newVagrantCloud() (*VagrantCloud, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (aws *VagrantCloud) Clusters() (cloudprovider.Clusters, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// TCPLoadBalancer returns an implementation of TCPLoadBalancer for Vagrant cloud.
|
||||
func (v *VagrantCloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
|
||||
return nil, false
|
||||
|
Loading…
Reference in New Issue
Block a user