Skip to content

Commit 30dbfbe

Browse files
authored
Merge pull request kubernetes#92367 from gongguan/instancev2
define and implement cloud InstanceV2
2 parents 7fb3f3e + 22e083f commit 30dbfbe

File tree

8 files changed

+54
-0
lines changed

8 files changed

+54
-0
lines changed

pkg/volume/cinder/attacher_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,10 @@ func (testcase *testcase) Instances() (cloudprovider.Instances, bool) {
645645
return &instances{testcase.instanceID}, true
646646
}
647647

648+
func (testcase *testcase) InstancesV2() (cloudprovider.InstancesV2, bool) {
649+
return nil, false
650+
}
651+
648652
func (testcase *testcase) DisksAreAttached(instanceID string, volumeIDs []string) (map[string]bool, error) {
649653
expected := &testcase.disksAreAttached
650654

staging/src/k8s.io/cloud-provider/cloud.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ type Interface interface {
4949
LoadBalancer() (LoadBalancer, bool)
5050
// Instances returns an instances interface. Also returns true if the interface is supported, false otherwise.
5151
Instances() (Instances, bool)
52+
// InstancesV2 is an implementation for instances only used by cloud node-controller now.
53+
// Also returns true if the interface is supported, false otherwise.
54+
InstancesV2() (InstancesV2, bool)
5255
// Zones returns a zones interface. Also returns true if the interface is supported, false otherwise.
5356
Zones() (Zones, bool)
5457
// Clusters returns a clusters interface. Also returns true if the interface is supported, false otherwise.
@@ -186,6 +189,17 @@ type Instances interface {
186189
InstanceShutdownByProviderID(ctx context.Context, providerID string) (bool, error)
187190
}
188191

192+
// InstancesV2 is an abstract, pluggable interface for sets of instances.
193+
// Unlike Instances, it is only used by cloud node-controller now.
194+
type InstancesV2 interface {
195+
// InstanceExistsByProviderID returns true if the instance for the given provider exists.
196+
InstanceExistsByProviderID(ctx context.Context, providerID string) (bool, error)
197+
// InstanceShutdownByProviderID returns true if the instance is shutdown in cloudprovider.
198+
InstanceShutdownByProviderID(ctx context.Context, providerID string) (bool, error)
199+
// InstanceMetadataByProviderID returns the instance's metadata.
200+
InstanceMetadataByProviderID(ctx context.Context, providerID string) (*InstanceMetadata, error)
201+
}
202+
189203
// Route is a representation of an advanced routing rule.
190204
type Route struct {
191205
// Name is the name of the routing rule in the cloud-provider.

staging/src/k8s.io/cloud-provider/fake/fake.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type Cloud struct {
5959
Exists bool
6060
Err error
6161

62+
EnableInstancesV2 bool
6263
ExistsByProviderID bool
6364
ErrByProviderID error
6465
NodeShutdown bool
@@ -152,6 +153,16 @@ func (f *Cloud) Instances() (cloudprovider.Instances, bool) {
152153
return f, true
153154
}
154155

156+
// InstancesV2 returns a fake implementation of InstancesV2.
157+
//
158+
// Actually it just returns f itself.
159+
func (f *Cloud) InstancesV2() (cloudprovider.InstancesV2, bool) {
160+
if f.EnableInstancesV2 {
161+
return f, true
162+
}
163+
return nil, false
164+
}
165+
155166
// Zones returns a zones interface. Also returns true if the interface is supported, false otherwise.
156167
func (f *Cloud) Zones() (cloudprovider.Zones, bool) {
157168
return f, true

staging/src/k8s.io/legacy-cloud-providers/aws/aws.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,11 @@ func (c *Cloud) Instances() (cloudprovider.Instances, bool) {
13941394
return c, true
13951395
}
13961396

1397+
// InstancesV2 returns an implementation of InstancesV2 for Amazon Web Services.
1398+
func (c *Cloud) InstancesV2() (cloudprovider.InstancesV2, bool) {
1399+
return nil, false
1400+
}
1401+
13971402
// Zones returns an implementation of Zones for Amazon Web Services.
13981403
func (c *Cloud) Zones() (cloudprovider.Zones, bool) {
13991404
return c, true

staging/src/k8s.io/legacy-cloud-providers/azure/azure.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,11 @@ func (az *Cloud) Instances() (cloudprovider.Instances, bool) {
664664
return az, true
665665
}
666666

667+
// InstancesV2 returns an instancesV2 interface. Also returns true if the interface is supported, false otherwise.
668+
func (az *Cloud) InstancesV2() (cloudprovider.InstancesV2, bool) {
669+
return nil, false
670+
}
671+
667672
// Zones returns a zones interface. Also returns true if the interface is supported, false otherwise.
668673
func (az *Cloud) Zones() (cloudprovider.Zones, bool) {
669674
return az, true

staging/src/k8s.io/legacy-cloud-providers/gce/gce.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,11 @@ func (g *Cloud) Instances() (cloudprovider.Instances, bool) {
659659
return g, true
660660
}
661661

662+
// InstancesV2 returns an implementation of InstancesV2 for Google Compute Engine.
663+
func (g *Cloud) InstancesV2() (cloudprovider.InstancesV2, bool) {
664+
return nil, false
665+
}
666+
662667
// Zones returns an implementation of Zones for Google Compute Engine.
663668
func (g *Cloud) Zones() (cloudprovider.Zones, bool) {
664669
return g, true

staging/src/k8s.io/legacy-cloud-providers/openstack/openstack_instances.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ func (os *OpenStack) Instances() (cloudprovider.Instances, bool) {
6262
}, true
6363
}
6464

65+
// InstancesV2 returns an implementation of InstancesV2 for OpenStack.
66+
func (os *OpenStack) InstancesV2() (cloudprovider.InstancesV2, bool) {
67+
return nil, false
68+
}
69+
6570
// CurrentNodeName implements Instances.CurrentNodeName
6671
// Note this is *not* necessarily the same as hostname.
6772
func (i *Instances) CurrentNodeName(ctx context.Context, hostname string) (types.NodeName, error) {

staging/src/k8s.io/legacy-cloud-providers/vsphere/vsphere.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,11 @@ func (vs *VSphere) Instances() (cloudprovider.Instances, bool) {
560560
return vs, true
561561
}
562562

563+
// InstancesV2 returns an implementation of InstancesV2 for vSphere.
564+
func (vs *VSphere) InstancesV2() (cloudprovider.InstancesV2, bool) {
565+
return nil, false
566+
}
567+
563568
func getLocalIP() ([]v1.NodeAddress, error) {
564569
// hashtable with VMware-allocated OUIs for MAC filtering
565570
// List of official OUIs: http://standards-oui.ieee.org/oui.txt

0 commit comments

Comments
 (0)