mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Fixes golint errors in pkg/cloudprovider
This commit is contained in:
		@@ -20,7 +20,7 @@ import (
 | 
			
		||||
	"net"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// CloudInterface is an abstract, pluggable interface for cloud providers
 | 
			
		||||
// Interface is an abstract, pluggable interface for cloud providers
 | 
			
		||||
type Interface interface {
 | 
			
		||||
	// TCPLoadBalancer returns a balancer interface. Also returns true if the interface is supported, false otherwise.
 | 
			
		||||
	TCPLoadBalancer() (TCPLoadBalancer, bool)
 | 
			
		||||
@@ -28,16 +28,23 @@ type Interface interface {
 | 
			
		||||
	Instances() (Instances, bool)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TCPLoadBalancer is an abstract, pluggable interface for TCP load balancers.
 | 
			
		||||
type TCPLoadBalancer interface {
 | 
			
		||||
	// TCPLoadBalancerExists returns whether the specified load balancer exists.
 | 
			
		||||
	// TODO: Break this up into different interfaces (LB, etc) when we have more than one type of service
 | 
			
		||||
	TCPLoadBalancerExists(name, region string) (bool, error)
 | 
			
		||||
	// CreateTCPLoadBalancer creates a new tcp load balancer.
 | 
			
		||||
	CreateTCPLoadBalancer(name, region string, port int, hosts []string) error
 | 
			
		||||
	// UpdateTCPLoadBalancer updates hosts under the specified load balancer.
 | 
			
		||||
	UpdateTCPLoadBalancer(name, region string, hosts []string) error
 | 
			
		||||
	// DeleteTCPLoadBalancer deletes a specified load balancer.
 | 
			
		||||
	DeleteTCPLoadBalancer(name, region string) error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Instances is an abstract, pluggable interface for sets of instances.
 | 
			
		||||
type Instances interface {
 | 
			
		||||
	// IPAddress returns an IP address of the specified instance.
 | 
			
		||||
	IPAddress(name string) (net.IP, error)
 | 
			
		||||
	// Lists instances that match 'filter' which is a regular expression which must match the entire instance name (fqdn)
 | 
			
		||||
	// List lists instances that match 'filter' which is a regular expression which must match the entire instance name (fqdn)
 | 
			
		||||
	List(filter string) ([]string, error)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,7 @@ import (
 | 
			
		||||
	"regexp"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// FakeCloud is a test-double implementation of Interface, TCPLoadBalancer and Instances. It is useful for testing.
 | 
			
		||||
type FakeCloud struct {
 | 
			
		||||
	Exists   bool
 | 
			
		||||
	Err      error
 | 
			
		||||
@@ -33,42 +34,60 @@ func (f *FakeCloud) addCall(desc string) {
 | 
			
		||||
	f.Calls = append(f.Calls, desc)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ClearCalls clears internal record of method calls to this FakeCloud.
 | 
			
		||||
func (f *FakeCloud) ClearCalls() {
 | 
			
		||||
	f.Calls = []string{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TCPLoadBalancer returns a fake implementation of TCPLoadBalancer.
 | 
			
		||||
//
 | 
			
		||||
// Actually it just returns f itself.
 | 
			
		||||
func (f *FakeCloud) TCPLoadBalancer() (TCPLoadBalancer, bool) {
 | 
			
		||||
	return f, true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Instances returns a fake implementation of Instances.
 | 
			
		||||
//
 | 
			
		||||
// Actually it just returns f itself.
 | 
			
		||||
func (f *FakeCloud) Instances() (Instances, bool) {
 | 
			
		||||
	return f, true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TCPLoadBalancerExists is a stub implementation of TCPLoadBalancer.TCPLoadBalancerExists.
 | 
			
		||||
func (f *FakeCloud) TCPLoadBalancerExists(name, region string) (bool, error) {
 | 
			
		||||
	return f.Exists, f.Err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CreateTCPLoadBalancer is a test-spy implementation of TCPLoadBalancer.CreateTCPLoadBalancer.
 | 
			
		||||
// It adds an entry "create" into the internal method call record.
 | 
			
		||||
func (f *FakeCloud) CreateTCPLoadBalancer(name, region string, port int, hosts []string) error {
 | 
			
		||||
	f.addCall("create")
 | 
			
		||||
	return f.Err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UpdateTCPLoadBalancer is a test-spy implementation of TCPLoadBalancer.UpdateTCPLoadBalancer.
 | 
			
		||||
// It adds an entry "update" into the internal method call record.
 | 
			
		||||
func (f *FakeCloud) UpdateTCPLoadBalancer(name, region string, hosts []string) error {
 | 
			
		||||
	f.addCall("update")
 | 
			
		||||
	return f.Err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DeleteTCPLoadBalancer is a test-spy implementation of TCPLoadBalancer.DeleteTCPLoadBalancer.
 | 
			
		||||
// It adds an entry "delete" into the internal method call record.
 | 
			
		||||
func (f *FakeCloud) DeleteTCPLoadBalancer(name, region string) error {
 | 
			
		||||
	f.addCall("delete")
 | 
			
		||||
	return f.Err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IPAddress is a test-spy implementation of Instances.IPAddress.
 | 
			
		||||
// It adds an entry "ip-address" into the internal method call record.
 | 
			
		||||
func (f *FakeCloud) IPAddress(instance string) (net.IP, error) {
 | 
			
		||||
	f.addCall("ip-address")
 | 
			
		||||
	return f.IP, f.Err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// List is a test-spy implementation of Instances.List.
 | 
			
		||||
// It adds an entry "list" into the internal method call record.
 | 
			
		||||
func (f *FakeCloud) List(filter string) ([]string, error) {
 | 
			
		||||
	f.addCall("list")
 | 
			
		||||
	result := []string{}
 | 
			
		||||
 
 | 
			
		||||
@@ -30,6 +30,7 @@ import (
 | 
			
		||||
	compute "code.google.com/p/google-api-go-client/compute/v1"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// GCECloud is an implementation of Interface, TCPLoadBalancer and Instances for Google Compute Engine.
 | 
			
		||||
type GCECloud struct {
 | 
			
		||||
	service    *compute.Service
 | 
			
		||||
	projectID  string
 | 
			
		||||
@@ -61,6 +62,7 @@ func getProjectAndZone() (string, string, error) {
 | 
			
		||||
	return parts[1], parts[3], nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NewGCECloud creates a new instance of GCECloud.
 | 
			
		||||
func NewGCECloud() (*GCECloud, error) {
 | 
			
		||||
	projectID, zone, err := getProjectAndZone()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -81,10 +83,12 @@ func NewGCECloud() (*GCECloud, error) {
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TCPLoadBalancer returns an implementation of TCPLoadBalancer for Google Compute Engine.
 | 
			
		||||
func (gce *GCECloud) TCPLoadBalancer() (TCPLoadBalancer, bool) {
 | 
			
		||||
	return gce, true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Instances returns an implementation of Instances for Google Compute Engine.
 | 
			
		||||
func (gce *GCECloud) Instances() (Instances, bool) {
 | 
			
		||||
	return gce, true
 | 
			
		||||
}
 | 
			
		||||
@@ -128,11 +132,13 @@ func (gce *GCECloud) waitForRegionOp(op *compute.Operation, region string) error
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TCPLoadBalancerExists is an implementation of TCPLoadBalancer.TCPLoadBalancerExists.
 | 
			
		||||
func (gce *GCECloud) TCPLoadBalancerExists(name, region string) (bool, error) {
 | 
			
		||||
	_, err := gce.service.ForwardingRules.Get(gce.projectID, region, name).Do()
 | 
			
		||||
	return false, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CreateTCPLoadBalancer is an implementation of TCPLoadBalancer.CreateTCPLoadBalancer.
 | 
			
		||||
func (gce *GCECloud) CreateTCPLoadBalancer(name, region string, port int, hosts []string) error {
 | 
			
		||||
	pool, err := gce.makeTargetPool(name, region, hosts)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -148,6 +154,7 @@ func (gce *GCECloud) CreateTCPLoadBalancer(name, region string, port int, hosts
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UpdateTCPLoadBalancer is an implementation of TCPLoadBalancer.UpdateTCPLoadBalancer.
 | 
			
		||||
func (gce *GCECloud) UpdateTCPLoadBalancer(name, region string, hosts []string) error {
 | 
			
		||||
	var refs []*compute.InstanceReference
 | 
			
		||||
	for _, host := range hosts {
 | 
			
		||||
@@ -161,6 +168,7 @@ func (gce *GCECloud) UpdateTCPLoadBalancer(name, region string, hosts []string)
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DeleteTCPLoadBalancer is an implementation of TCPLoadBalancer.DeleteTCPLoadBalancer.
 | 
			
		||||
func (gce *GCECloud) DeleteTCPLoadBalancer(name, region string) error {
 | 
			
		||||
	_, err := gce.service.ForwardingRules.Delete(gce.projectID, region, name).Do()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -170,6 +178,7 @@ func (gce *GCECloud) DeleteTCPLoadBalancer(name, region string) error {
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IPAddress is an implementation of Instances.IPAddress.
 | 
			
		||||
func (gce *GCECloud) IPAddress(instance string) (net.IP, error) {
 | 
			
		||||
	res, err := gce.service.Instances.Get(gce.projectID, gce.zone, instance).Do()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -195,6 +204,7 @@ func fqdnSuffix() (string, error) {
 | 
			
		||||
	return strings.TrimSpace(string(fullHostname)[len(string(hostname)):]), nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// List is an implementation of Instances.List.
 | 
			
		||||
func (gce *GCECloud) List(filter string) ([]string, error) {
 | 
			
		||||
	// GCE gives names without their fqdn suffix, so get that here for appending.
 | 
			
		||||
	// This is needed because the kubelet looks for its jobs in /registry/hosts/<fqdn>/pods
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user