From 531be1d28e37caa788430f6a863f2e07e6893d6f Mon Sep 17 00:00:00 2001 From: Andrew Sy Kim Date: Thu, 18 Jun 2020 09:41:42 -0400 Subject: [PATCH 1/2] define instances v2 Signed-off-by: Andrew Sy Kim --- staging/src/k8s.io/cloud-provider/cloud.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/staging/src/k8s.io/cloud-provider/cloud.go b/staging/src/k8s.io/cloud-provider/cloud.go index 059e9761aff..c39cf463d0f 100644 --- a/staging/src/k8s.io/cloud-provider/cloud.go +++ b/staging/src/k8s.io/cloud-provider/cloud.go @@ -49,6 +49,9 @@ type Interface interface { LoadBalancer() (LoadBalancer, bool) // Instances returns an instances interface. Also returns true if the interface is supported, false otherwise. Instances() (Instances, bool) + // InstancesV2 is an implementation for instances only used by cloud node-controller now. + // Also returns true if the interface is supported, false otherwise. + InstancesV2() (InstancesV2, 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. @@ -186,6 +189,17 @@ type Instances interface { InstanceShutdownByProviderID(ctx context.Context, providerID string) (bool, error) } +// InstancesV2 is an abstract, pluggable interface for sets of instances. +// Unlike Instances, it is only used by cloud node-controller now. +type InstancesV2 interface { + // InstanceExistsByProviderID returns true if the instance for the given provider exists. + InstanceExistsByProviderID(ctx context.Context, providerID string) (bool, error) + // InstanceShutdownByProviderID returns true if the instance is shutdown in cloudprovider. + InstanceShutdownByProviderID(ctx context.Context, providerID string) (bool, error) + // InstanceMetadataByProviderID returns the instance's metadata. + InstanceMetadataByProviderID(ctx context.Context, providerID string) (*InstanceMetadata, error) +} + // Route is a representation of an advanced routing rule. type Route struct { // Name is the name of the routing rule in the cloud-provider. From 22e083f132377dd1b4ee400494b974d902ece10a Mon Sep 17 00:00:00 2001 From: gongguan Date: Sat, 20 Jun 2020 17:23:05 +0800 Subject: [PATCH 2/2] implement instancesV2 --- pkg/volume/cinder/attacher_test.go | 4 ++++ staging/src/k8s.io/cloud-provider/fake/fake.go | 11 +++++++++++ staging/src/k8s.io/legacy-cloud-providers/aws/aws.go | 5 +++++ .../src/k8s.io/legacy-cloud-providers/azure/azure.go | 5 +++++ staging/src/k8s.io/legacy-cloud-providers/gce/gce.go | 5 +++++ .../openstack/openstack_instances.go | 5 +++++ .../k8s.io/legacy-cloud-providers/vsphere/vsphere.go | 5 +++++ 7 files changed, 40 insertions(+) diff --git a/pkg/volume/cinder/attacher_test.go b/pkg/volume/cinder/attacher_test.go index 76980d80372..43df940de02 100644 --- a/pkg/volume/cinder/attacher_test.go +++ b/pkg/volume/cinder/attacher_test.go @@ -645,6 +645,10 @@ func (testcase *testcase) Instances() (cloudprovider.Instances, bool) { return &instances{testcase.instanceID}, true } +func (testcase *testcase) InstancesV2() (cloudprovider.InstancesV2, bool) { + return nil, false +} + func (testcase *testcase) DisksAreAttached(instanceID string, volumeIDs []string) (map[string]bool, error) { expected := &testcase.disksAreAttached diff --git a/staging/src/k8s.io/cloud-provider/fake/fake.go b/staging/src/k8s.io/cloud-provider/fake/fake.go index 858980558c1..22d1a915d8d 100644 --- a/staging/src/k8s.io/cloud-provider/fake/fake.go +++ b/staging/src/k8s.io/cloud-provider/fake/fake.go @@ -59,6 +59,7 @@ type Cloud struct { Exists bool Err error + EnableInstancesV2 bool ExistsByProviderID bool ErrByProviderID error NodeShutdown bool @@ -152,6 +153,16 @@ func (f *Cloud) Instances() (cloudprovider.Instances, bool) { return f, true } +// InstancesV2 returns a fake implementation of InstancesV2. +// +// Actually it just returns f itself. +func (f *Cloud) InstancesV2() (cloudprovider.InstancesV2, bool) { + if f.EnableInstancesV2 { + return f, true + } + return nil, false +} + // Zones returns a zones interface. Also returns true if the interface is supported, false otherwise. func (f *Cloud) Zones() (cloudprovider.Zones, bool) { return f, true diff --git a/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go b/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go index 901444df47d..0e8d50c28ae 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go +++ b/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go @@ -1394,6 +1394,11 @@ func (c *Cloud) Instances() (cloudprovider.Instances, bool) { return c, true } +// InstancesV2 returns an implementation of InstancesV2 for Amazon Web Services. +func (c *Cloud) InstancesV2() (cloudprovider.InstancesV2, bool) { + return nil, false +} + // Zones returns an implementation of Zones for Amazon Web Services. func (c *Cloud) Zones() (cloudprovider.Zones, bool) { return c, true diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go index 50034820893..12185bd6123 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go @@ -659,6 +659,11 @@ func (az *Cloud) Instances() (cloudprovider.Instances, bool) { return az, true } +// InstancesV2 returns an instancesV2 interface. Also returns true if the interface is supported, false otherwise. +func (az *Cloud) InstancesV2() (cloudprovider.InstancesV2, bool) { + return nil, false +} + // Zones returns a zones interface. Also returns true if the interface is supported, false otherwise. func (az *Cloud) Zones() (cloudprovider.Zones, bool) { return az, true diff --git a/staging/src/k8s.io/legacy-cloud-providers/gce/gce.go b/staging/src/k8s.io/legacy-cloud-providers/gce/gce.go index e3c26c1ef8c..e9077f93bc7 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/gce/gce.go +++ b/staging/src/k8s.io/legacy-cloud-providers/gce/gce.go @@ -659,6 +659,11 @@ func (g *Cloud) Instances() (cloudprovider.Instances, bool) { return g, true } +// InstancesV2 returns an implementation of InstancesV2 for Google Compute Engine. +func (g *Cloud) InstancesV2() (cloudprovider.InstancesV2, bool) { + return nil, false +} + // Zones returns an implementation of Zones for Google Compute Engine. func (g *Cloud) Zones() (cloudprovider.Zones, bool) { return g, true diff --git a/staging/src/k8s.io/legacy-cloud-providers/openstack/openstack_instances.go b/staging/src/k8s.io/legacy-cloud-providers/openstack/openstack_instances.go index c68f6bdd78e..c1741f06933 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/openstack/openstack_instances.go +++ b/staging/src/k8s.io/legacy-cloud-providers/openstack/openstack_instances.go @@ -62,6 +62,11 @@ func (os *OpenStack) Instances() (cloudprovider.Instances, bool) { }, true } +// InstancesV2 returns an implementation of InstancesV2 for OpenStack. +func (os *OpenStack) InstancesV2() (cloudprovider.InstancesV2, bool) { + return nil, false +} + // CurrentNodeName implements Instances.CurrentNodeName // Note this is *not* necessarily the same as hostname. func (i *Instances) CurrentNodeName(ctx context.Context, hostname string) (types.NodeName, error) { diff --git a/staging/src/k8s.io/legacy-cloud-providers/vsphere/vsphere.go b/staging/src/k8s.io/legacy-cloud-providers/vsphere/vsphere.go index 2ef2a30833c..d7b39151855 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/vsphere/vsphere.go +++ b/staging/src/k8s.io/legacy-cloud-providers/vsphere/vsphere.go @@ -560,6 +560,11 @@ func (vs *VSphere) Instances() (cloudprovider.Instances, bool) { return vs, true } +// InstancesV2 returns an implementation of InstancesV2 for vSphere. +func (vs *VSphere) InstancesV2() (cloudprovider.InstancesV2, bool) { + return nil, false +} + func getLocalIP() ([]v1.NodeAddress, error) { // hashtable with VMware-allocated OUIs for MAC filtering // List of official OUIs: http://standards-oui.ieee.org/oui.txt