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