mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +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
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (aws *AWSCloud) Clusters() (cloudprovider.Clusters, bool) {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
// TCPLoadBalancer returns an implementation of TCPLoadBalancer for Amazon Web Services.
|
// TCPLoadBalancer returns an implementation of TCPLoadBalancer for Amazon Web Services.
|
||||||
func (aws *AWSCloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
|
func (aws *AWSCloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
|
||||||
return nil, false
|
return nil, false
|
||||||
|
@ -30,6 +30,16 @@ type Interface interface {
|
|||||||
Instances() (Instances, bool)
|
Instances() (Instances, bool)
|
||||||
// Zones returns a zones interface. Also returns true if the interface is supported, false otherwise.
|
// Zones returns a zones interface. Also returns true if the interface is supported, false otherwise.
|
||||||
Zones() (Zones, bool)
|
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.
|
// TCPLoadBalancer is an abstract, pluggable interface for TCP load balancers.
|
||||||
|
@ -45,8 +45,11 @@ func (f *FakeCloud) ClearCalls() {
|
|||||||
f.Calls = []string{}
|
f.Calls = []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *FakeCloud) Clusters() (cloudprovider.Clusters, bool) {
|
||||||
|
return f, true
|
||||||
|
}
|
||||||
|
|
||||||
// TCPLoadBalancer returns a fake implementation of TCPLoadBalancer.
|
// TCPLoadBalancer returns a fake implementation of TCPLoadBalancer.
|
||||||
//
|
|
||||||
// Actually it just returns f itself.
|
// Actually it just returns f itself.
|
||||||
func (f *FakeCloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
|
func (f *FakeCloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
|
||||||
return f, true
|
return f, true
|
||||||
|
@ -30,6 +30,7 @@ import (
|
|||||||
|
|
||||||
"code.google.com/p/goauth2/compute/serviceaccount"
|
"code.google.com/p/goauth2/compute/serviceaccount"
|
||||||
compute "code.google.com/p/google-api-go-client/compute/v1"
|
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/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/resources"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/resources"
|
||||||
@ -39,10 +40,11 @@ import (
|
|||||||
|
|
||||||
// GCECloud is an implementation of Interface, TCPLoadBalancer and Instances for Google Compute Engine.
|
// GCECloud is an implementation of Interface, TCPLoadBalancer and Instances for Google Compute Engine.
|
||||||
type GCECloud struct {
|
type GCECloud struct {
|
||||||
service *compute.Service
|
service *compute.Service
|
||||||
projectID string
|
containerService *container.Service
|
||||||
zone string
|
projectID string
|
||||||
instanceID string
|
zone string
|
||||||
|
instanceID string
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -115,14 +117,23 @@ func newGCECloud() (*GCECloud, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
containerSvc, err := container.New(client)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return &GCECloud{
|
return &GCECloud{
|
||||||
service: svc,
|
service: svc,
|
||||||
projectID: projectID,
|
containerService: containerSvc,
|
||||||
zone: zone,
|
projectID: projectID,
|
||||||
instanceID: instanceID,
|
zone: zone,
|
||||||
|
instanceID: instanceID,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gce *GCECloud) Clusters() (cloudprovider.Clusters, bool) {
|
||||||
|
return gce, true
|
||||||
|
}
|
||||||
|
|
||||||
// TCPLoadBalancer returns an implementation of TCPLoadBalancer for Google Compute Engine.
|
// TCPLoadBalancer returns an implementation of TCPLoadBalancer for Google Compute Engine.
|
||||||
func (gce *GCECloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
|
func (gce *GCECloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
|
||||||
return gce, true
|
return gce, true
|
||||||
@ -385,3 +396,19 @@ func (gce *GCECloud) convertDiskToAttachedDisk(disk *compute.Disk, readWrite str
|
|||||||
Type: "PERSISTENT",
|
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
|
return rsrc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (aws *OpenStack) Clusters() (cloudprovider.Clusters, bool) {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
func (os *OpenStack) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
|
func (os *OpenStack) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,10 @@ func newOVirtCloud(config io.Reader) (*OVirtCloud, error) {
|
|||||||
return &OVirtCloud{VmsRequest: request}, nil
|
return &OVirtCloud{VmsRequest: request}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (aws *OVirtCloud) Clusters() (cloudprovider.Clusters, bool) {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
// TCPLoadBalancer returns an implementation of TCPLoadBalancer for oVirt cloud
|
// TCPLoadBalancer returns an implementation of TCPLoadBalancer for oVirt cloud
|
||||||
func (v *OVirtCloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
|
func (v *OVirtCloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
|
||||||
return nil, false
|
return nil, false
|
||||||
|
@ -80,6 +80,10 @@ func newVagrantCloud() (*VagrantCloud, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (aws *VagrantCloud) Clusters() (cloudprovider.Clusters, bool) {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
// TCPLoadBalancer returns an implementation of TCPLoadBalancer for Vagrant cloud.
|
// TCPLoadBalancer returns an implementation of TCPLoadBalancer for Vagrant cloud.
|
||||||
func (v *VagrantCloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
|
func (v *VagrantCloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
|
||||||
return nil, false
|
return nil, false
|
||||||
|
Loading…
Reference in New Issue
Block a user