Merge pull request #92367 from gongguan/instancev2

define and implement cloud InstanceV2
This commit is contained in:
Kubernetes Prow Robot 2020-06-26 00:07:45 -07:00 committed by GitHub
commit 30dbfbec84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 54 additions and 0 deletions

View File

@ -645,6 +645,10 @@ func (testcase *testcase) Instances() (cloudprovider.Instances, bool) {
return &instances{testcase.instanceID}, true 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) { func (testcase *testcase) DisksAreAttached(instanceID string, volumeIDs []string) (map[string]bool, error) {
expected := &testcase.disksAreAttached expected := &testcase.disksAreAttached

View File

@ -49,6 +49,9 @@ type Interface interface {
LoadBalancer() (LoadBalancer, bool) LoadBalancer() (LoadBalancer, bool)
// Instances returns an instances interface. Also returns true if the interface is supported, false otherwise. // Instances returns an instances interface. Also returns true if the interface is supported, false otherwise.
Instances() (Instances, bool) 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 returns a zones interface. Also returns true if the interface is supported, false otherwise.
Zones() (Zones, bool) Zones() (Zones, bool)
// Clusters returns a clusters interface. Also returns true if the interface is supported, false otherwise. // 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) 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. // Route is a representation of an advanced routing rule.
type Route struct { type Route struct {
// Name is the name of the routing rule in the cloud-provider. // Name is the name of the routing rule in the cloud-provider.

View File

@ -59,6 +59,7 @@ type Cloud struct {
Exists bool Exists bool
Err error Err error
EnableInstancesV2 bool
ExistsByProviderID bool ExistsByProviderID bool
ErrByProviderID error ErrByProviderID error
NodeShutdown bool NodeShutdown bool
@ -152,6 +153,16 @@ func (f *Cloud) Instances() (cloudprovider.Instances, bool) {
return f, true 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. // Zones returns a zones interface. Also returns true if the interface is supported, false otherwise.
func (f *Cloud) Zones() (cloudprovider.Zones, bool) { func (f *Cloud) Zones() (cloudprovider.Zones, bool) {
return f, true return f, true

View File

@ -1394,6 +1394,11 @@ func (c *Cloud) Instances() (cloudprovider.Instances, bool) {
return c, true 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. // Zones returns an implementation of Zones for Amazon Web Services.
func (c *Cloud) Zones() (cloudprovider.Zones, bool) { func (c *Cloud) Zones() (cloudprovider.Zones, bool) {
return c, true return c, true

View File

@ -664,6 +664,11 @@ func (az *Cloud) Instances() (cloudprovider.Instances, bool) {
return az, true 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. // Zones returns a zones interface. Also returns true if the interface is supported, false otherwise.
func (az *Cloud) Zones() (cloudprovider.Zones, bool) { func (az *Cloud) Zones() (cloudprovider.Zones, bool) {
return az, true return az, true

View File

@ -659,6 +659,11 @@ func (g *Cloud) Instances() (cloudprovider.Instances, bool) {
return g, true 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. // Zones returns an implementation of Zones for Google Compute Engine.
func (g *Cloud) Zones() (cloudprovider.Zones, bool) { func (g *Cloud) Zones() (cloudprovider.Zones, bool) {
return g, true return g, true

View File

@ -62,6 +62,11 @@ func (os *OpenStack) Instances() (cloudprovider.Instances, bool) {
}, true }, true
} }
// InstancesV2 returns an implementation of InstancesV2 for OpenStack.
func (os *OpenStack) InstancesV2() (cloudprovider.InstancesV2, bool) {
return nil, false
}
// CurrentNodeName implements Instances.CurrentNodeName // CurrentNodeName implements Instances.CurrentNodeName
// Note this is *not* necessarily the same as hostname. // Note this is *not* necessarily the same as hostname.
func (i *Instances) CurrentNodeName(ctx context.Context, hostname string) (types.NodeName, error) { func (i *Instances) CurrentNodeName(ctx context.Context, hostname string) (types.NodeName, error) {

View File

@ -560,6 +560,11 @@ func (vs *VSphere) Instances() (cloudprovider.Instances, bool) {
return vs, true 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) { func getLocalIP() ([]v1.NodeAddress, error) {
// hashtable with VMware-allocated OUIs for MAC filtering // hashtable with VMware-allocated OUIs for MAC filtering
// List of official OUIs: http://standards-oui.ieee.org/oui.txt // List of official OUIs: http://standards-oui.ieee.org/oui.txt