diff --git a/pkg/volume/cinder/attacher_test.go b/pkg/volume/cinder/attacher_test.go index 00e85ede2c6..e08817e5995 100644 --- a/pkg/volume/cinder/attacher_test.go +++ b/pkg/volume/cinder/attacher_test.go @@ -734,6 +734,10 @@ func (instances *instances) InstanceShutdownByProviderID(ctx context.Context, pr return false, errors.New("unimplemented") } +func (instances *instances) InstanceMetadataByProviderID(ctx context.Context, providerID string) (*cloudprovider.InstanceMetadata, error) { + return nil, errors.New("unimplemented") +} + func (instances *instances) List(filter string) ([]types.NodeName, error) { return []types.NodeName{}, errors.New("Not implemented") } diff --git a/staging/src/k8s.io/cloud-provider/cloud.go b/staging/src/k8s.io/cloud-provider/cloud.go index de64419e298..35b59e74daa 100644 --- a/staging/src/k8s.io/cloud-provider/cloud.go +++ b/staging/src/k8s.io/cloud-provider/cloud.go @@ -163,6 +163,7 @@ type Instances interface { // ProviderID is a unique identifier of the node. This will not be called // from the node whose nodeaddresses are being queried. i.e. local metadata // services cannot be used in this method to obtain nodeaddresses + // Deprecated: Remove once all calls are migrated to InstanceMetadataByProviderID NodeAddressesByProviderID(ctx context.Context, providerID string) ([]v1.NodeAddress, error) // InstanceID returns the cloud provider ID of the node with the specified NodeName. // Note that if the instance does not exist, we must return ("", cloudprovider.InstanceNotFound) @@ -171,6 +172,7 @@ type Instances interface { // InstanceType returns the type of the specified instance. InstanceType(ctx context.Context, name types.NodeName) (string, error) // InstanceTypeByProviderID returns the type of the specified instance. + // Deprecated: Remove once all calls are migrated to InstanceMetadataByProviderID InstanceTypeByProviderID(ctx context.Context, providerID string) (string, error) // AddSSHKeyToAllInstances adds an SSH public key as a legal identity for all instances // expected format for the key is standard ssh-keygen format: @@ -181,9 +183,12 @@ type Instances interface { // InstanceExistsByProviderID returns true if the instance for the given provider exists. // If false is returned with no error, the instance will be immediately deleted by the cloud controller manager. // This method should still return true for instances that exist but are stopped/sleeping. + // Deprecated: Remove once all calls are migrated to InstanceMetadataByProviderID 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. @@ -250,3 +255,13 @@ type Zones interface { type PVLabeler interface { GetLabelsForVolume(ctx context.Context, pv *v1.PersistentVolume) (map[string]string, error) } + +// InstanceMetadata contains metadata about the specific instance. +type InstanceMetadata struct { + // ProviderID is provider's id that instance belongs to. + ProviderID string + // Type is instance's type. + Type string + // NodeAddress contains information for the instance's address. + NodeAddresses []v1.NodeAddress +} diff --git a/staging/src/k8s.io/cloud-provider/fake/fake.go b/staging/src/k8s.io/cloud-provider/fake/fake.go index b473ceca6b3..858980558c1 100644 --- a/staging/src/k8s.io/cloud-provider/fake/fake.go +++ b/staging/src/k8s.io/cloud-provider/fake/fake.go @@ -292,6 +292,18 @@ func (f *Cloud) InstanceShutdownByProviderID(ctx context.Context, providerID str return f.NodeShutdown, f.ErrShutdownByProviderID } +// InstanceMetadataByProviderID returns metadata of the specified instance. +func (f *Cloud) InstanceMetadataByProviderID(ctx context.Context, providerID string) (*cloudprovider.InstanceMetadata, error) { + f.addCall("instance-metadata-by-provider-id") + f.addressesMux.Lock() + defer f.addressesMux.Unlock() + return &cloudprovider.InstanceMetadata{ + ProviderID: providerID, + Type: f.InstanceTypes[types.NodeName(providerID)], + NodeAddresses: f.Addresses, + }, f.Err +} + // List is a test-spy implementation of Instances.List. // It adds an entry "list" into the internal method call record. func (f *Cloud) List(filter string) ([]types.NodeName, error) { 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 8e198fdb9c3..40ea45eb134 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go +++ b/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go @@ -1646,6 +1646,11 @@ func (c *Cloud) InstanceShutdownByProviderID(ctx context.Context, providerID str return false, nil } +// InstanceMetadataByProviderID returns metadata of the specified instance. +func (c *Cloud) InstanceMetadataByProviderID(ctx context.Context, providerID string) (*cloudprovider.InstanceMetadata, error) { + return nil, fmt.Errorf("unimplemented") +} + // InstanceID returns the cloud provider ID of the node with the specified nodeName. func (c *Cloud) InstanceID(ctx context.Context, nodeName types.NodeName) (string, error) { // In the future it is possible to also return an endpoint as: diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_instances.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_instances.go index 86c30d44f5a..8f1b123e3b5 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_instances.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_instances.go @@ -230,6 +230,11 @@ func (az *Cloud) InstanceShutdownByProviderID(ctx context.Context, providerID st return strings.ToLower(powerStatus) == vmPowerStateStopped || strings.ToLower(powerStatus) == vmPowerStateDeallocated, nil } +// InstanceMetadataByProviderID returns metadata of the specified instance. +func (az *Cloud) InstanceMetadataByProviderID(ctx context.Context, providerID string) (*cloudprovider.InstanceMetadata, error) { + return nil, fmt.Errorf("unimplemented") +} + func (az *Cloud) isCurrentInstance(name types.NodeName, metadataVMName string) (bool, error) { nodeName := mapNodeNameToVMName(name) diff --git a/staging/src/k8s.io/legacy-cloud-providers/gce/gce_instances.go b/staging/src/k8s.io/legacy-cloud-providers/gce/gce_instances.go index 71aa4c59e94..ec475ae87dc 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/gce/gce_instances.go +++ b/staging/src/k8s.io/legacy-cloud-providers/gce/gce_instances.go @@ -161,6 +161,11 @@ func (g *Cloud) InstanceShutdownByProviderID(ctx context.Context, providerID str return false, cloudprovider.NotImplemented } +// InstanceMetadataByProviderID returns metadata of the specified instance. +func (g *Cloud) InstanceMetadataByProviderID(ctx context.Context, providerID string) (*cloudprovider.InstanceMetadata, error) { + return nil, fmt.Errorf("unimplemented") +} + // InstanceTypeByProviderID returns the cloudprovider instance type of the node // with the specified unique providerID This method will not be called from the // node that is requesting this ID. i.e. metadata service and other local 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 3d817985da5..c354e9f1657 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 @@ -152,6 +152,11 @@ func (i *Instances) InstanceShutdownByProviderID(ctx context.Context, providerID return false, nil } +// InstanceMetadataByProviderID returns metadata of the specified instance. +func (i *Instances) InstanceMetadataByProviderID(ctx context.Context, providerID string) (*cloudprovider.InstanceMetadata, error) { + return nil, fmt.Errorf("unimplemented") +} + // InstanceID returns the kubelet's cloud provider ID. func (os *OpenStack) InstanceID() (string, error) { if len(os.localInstanceID) == 0 { 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 9caf1d813c3..04331ee50d2 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/vsphere/vsphere.go +++ b/staging/src/k8s.io/legacy-cloud-providers/vsphere/vsphere.go @@ -770,6 +770,11 @@ func (vs *VSphere) InstanceShutdownByProviderID(ctx context.Context, providerID return !isActive, nil } +// InstanceMetadataByProviderID returns metadata of the specified instance. +func (vs *VSphere) InstanceMetadataByProviderID(ctx context.Context, providerID string) (*cloudprovider.InstanceMetadata, error) { + return nil, fmt.Errorf("unimplemented") +} + // InstanceID returns the cloud provider ID of the node with the specified Name. func (vs *VSphere) InstanceID(ctx context.Context, nodeName k8stypes.NodeName) (string, error) {