Skip to content

Commit

Permalink
Merge pull request kubernetes#71547 from andrewsykim/check-provider-i…
Browse files Browse the repository at this point in the history
…mplements-interface

compile check to ensure cloud providers implement cloud interfaces
  • Loading branch information
k8s-ci-robot authored Dec 1, 2018
2 parents 9b160ab + 4b0f2ab commit e056703
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 9 deletions.
10 changes: 7 additions & 3 deletions pkg/cloudprovider/providers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,6 @@ const DefaultVolumeType = "gp2"
// Used to call recognizeWellKnownRegions just once
var once sync.Once

// AWS implements PVLabeler.
var _ cloudprovider.PVLabeler = (*Cloud)(nil)

// Services is an abstraction over AWS, to allow mocking/other implementations
type Services interface {
Compute(region string) (EC2, error)
Expand Down Expand Up @@ -480,6 +477,13 @@ type InstanceGroupInfo interface {
CurrentSize() (int, error)
}

var _ cloudprovider.Interface = (*Cloud)(nil)
var _ cloudprovider.Instances = (*Cloud)(nil)
var _ cloudprovider.LoadBalancer = (*Cloud)(nil)
var _ cloudprovider.Routes = (*Cloud)(nil)
var _ cloudprovider.Zones = (*Cloud)(nil)
var _ cloudprovider.PVLabeler = (*Cloud)(nil)

// Cloud is an implementation of Interface, LoadBalancer and Instances for Amazon Web Services.
type Cloud struct {
ec2 EC2
Expand Down
10 changes: 7 additions & 3 deletions pkg/cloudprovider/providers/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ var (
defaultExcludeMasterFromStandardLB = true
)

// Azure implements PVLabeler.
var _ cloudprovider.PVLabeler = (*Cloud)(nil)

// Config holds the configuration parsed from the --cloud-config flag
// All fields are required unless otherwise specified
type Config struct {
Expand Down Expand Up @@ -143,6 +140,13 @@ type Config struct {
MaximumLoadBalancerRuleCount int `json:"maximumLoadBalancerRuleCount" yaml:"maximumLoadBalancerRuleCount"`
}

var _ cloudprovider.Interface = (*Cloud)(nil)
var _ cloudprovider.Instances = (*Cloud)(nil)
var _ cloudprovider.LoadBalancer = (*Cloud)(nil)
var _ cloudprovider.Routes = (*Cloud)(nil)
var _ cloudprovider.Zones = (*Cloud)(nil)
var _ cloudprovider.PVLabeler = (*Cloud)(nil)

// Cloud holds the config and clients
type Cloud struct {
Config
Expand Down
5 changes: 5 additions & 0 deletions pkg/cloudprovider/providers/cloudstack/cloudstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ func newCSCloud(cfg *CSConfig) (*CSCloud, error) {
return cs, nil
}

var _ cloudprovider.Interface = (*CSCloud)(nil)
var _ cloudprovider.Instances = (*CSCloud)(nil)
var _ cloudprovider.LoadBalancer = (*CSCloud)(nil)
var _ cloudprovider.Zones = (*CSCloud)(nil)

// Initialize passes a Kubernetes clientBuilder interface to the cloud provider
func (cs *CSCloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, stop <-chan struct{}) {
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/cloudprovider/providers/cloudstack/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import (
"k8s.io/klog"
)

var _ cloudprovider.Instances = (*metadata)(nil)
var _ cloudprovider.Zones = (*metadata)(nil)

type metadata struct {
dhcpServer string
zone string
Expand Down
8 changes: 8 additions & 0 deletions pkg/cloudprovider/providers/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ type FakeUpdateBalancerCall struct {
Hosts []*v1.Node
}

var _ cloudprovider.Interface = (*FakeCloud)(nil)
var _ cloudprovider.Instances = (*FakeCloud)(nil)
var _ cloudprovider.LoadBalancer = (*FakeCloud)(nil)
var _ cloudprovider.Routes = (*FakeCloud)(nil)
var _ cloudprovider.Zones = (*FakeCloud)(nil)
var _ cloudprovider.PVLabeler = (*FakeCloud)(nil)
var _ cloudprovider.Clusters = (*FakeCloud)(nil)

// FakeCloud is a test-double implementation of Interface, LoadBalancer, Instances, and Routes. It is useful for testing.
type FakeCloud struct {
Exists bool
Expand Down
11 changes: 8 additions & 3 deletions pkg/cloudprovider/providers/gce/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ type gceObject interface {
MarshalJSON() ([]byte, error)
}

var _ cloudprovider.Interface = (*Cloud)(nil)
var _ cloudprovider.Instances = (*Cloud)(nil)
var _ cloudprovider.LoadBalancer = (*Cloud)(nil)
var _ cloudprovider.Routes = (*Cloud)(nil)
var _ cloudprovider.Zones = (*Cloud)(nil)
var _ cloudprovider.PVLabeler = (*Cloud)(nil)
var _ cloudprovider.Clusters = (*Cloud)(nil)

// Cloud is an implementation of Interface, LoadBalancer and Instances for Google Compute Engine.
type Cloud struct {
// ClusterID contains functionality for getting (and initializing) the ingress-uid. Call Cloud.Initialize()
Expand Down Expand Up @@ -765,9 +773,6 @@ func isProjectNumber(idOrNumber string) bool {
return err == nil
}

// Cloud implements cloudprovider.Interface.
var _ cloudprovider.Interface = (*Cloud)(nil)

func gceNetworkURL(apiEndpoint, project, network string) string {
if apiEndpoint == "" {
apiEndpoint = gceComputeAPIEndpoint
Expand Down
3 changes: 3 additions & 0 deletions pkg/cloudprovider/providers/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ type MetadataOpts struct {
RequestTimeout MyDuration `gcfg:"request-timeout"`
}

var _ cloudprovider.Interface = (*OpenStack)(nil)
var _ cloudprovider.Zones = (*OpenStack)(nil)

// OpenStack is an implementation of cloud provider Interface for OpenStack.
type OpenStack struct {
provider *gophercloud.ProviderClient
Expand Down
2 changes: 2 additions & 0 deletions pkg/cloudprovider/providers/openstack/openstack_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
cloudprovider "k8s.io/cloud-provider"
)

var _ cloudprovider.Instances = (*Instances)(nil)

// Instances encapsulates an implementation of Instances for OpenStack.
type Instances struct {
compute *gophercloud.ServiceClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ const (
ServiceAnnotationLoadBalancerInternal = "service.beta.kubernetes.io/openstack-internal-load-balancer"
)

var _ cloudprovider.LoadBalancer = (*LbaasV2)(nil)

// LbaasV2 is a LoadBalancer implementation for Neutron LBaaS v2 API
type LbaasV2 struct {
LoadBalancer
Expand Down
2 changes: 2 additions & 0 deletions pkg/cloudprovider/providers/openstack/openstack_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (

var errNoRouterID = errors.New("router-id not set in cloud provider config")

var _ cloudprovider.Routes = (*Routes)(nil)

// Routes implements the cloudprovider.Routes for OpenStack clouds
type Routes struct {
compute *gophercloud.ServiceClient
Expand Down
3 changes: 3 additions & 0 deletions pkg/cloudprovider/providers/ovirt/ovirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ type Instance struct {
// InstanceMap provides the map of Ovirt instances.
type InstanceMap map[string]Instance

var _ cloudprovider.Interface = (*Cloud)(nil)
var _ cloudprovider.Instances = (*Cloud)(nil)

// Cloud is an implementation of the cloud provider interface for Ovirt.
type Cloud struct {
VmsRequest *url.URL
Expand Down
4 changes: 4 additions & 0 deletions pkg/cloudprovider/providers/photon/photon.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ const (
// overrideIP = true in cloud config file. Default value is false.
var overrideIP bool = false

var _ cloudprovider.Interface = (*PCCloud)(nil)
var _ cloudprovider.Instances = (*PCCloud)(nil)
var _ cloudprovider.Zones = (*PCCloud)(nil)

// Photon is an implementation of the cloud provider interface for Photon Controller.
type PCCloud struct {
cfg *PCConfig
Expand Down
4 changes: 4 additions & 0 deletions pkg/cloudprovider/providers/vsphere/vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ var (
ErrPasswordMissing = errors.New(MissingPasswordErrMsg)
)

var _ cloudprovider.Interface = (*VSphere)(nil)
var _ cloudprovider.Instances = (*VSphere)(nil)
var _ cloudprovider.Zones = (*VSphere)(nil)

// VSphere is an implementation of cloud provider Interface for VSphere.
type VSphere struct {
cfg *VSphereConfig
Expand Down

0 comments on commit e056703

Please sign in to comment.