@@ -24,6 +24,7 @@ import (
2424 "errors"
2525 "fmt"
2626 "regexp"
27+ "strings"
2728
2829 "github.com/apache/cloudstack-go/v2/cloudstack"
2930 corev1 "k8s.io/api/core/v1"
@@ -53,7 +54,7 @@ func (cs *CSCloud) NodeAddresses(ctx context.Context, name types.NodeName) ([]co
5354// NodeAddressesByProviderID returns the addresses of the specified instance.
5455func (cs * CSCloud ) NodeAddressesByProviderID (ctx context.Context , providerID string ) ([]corev1.NodeAddress , error ) {
5556 instance , count , err := cs .client .VirtualMachine .GetVirtualMachineByID (
56- providerID ,
57+ cs . getInstanceIDFromProviderID ( providerID ) ,
5758 cloudstack .WithProject (cs .projectID ),
5859 )
5960 if err != nil {
@@ -125,7 +126,7 @@ func (cs *CSCloud) InstanceType(ctx context.Context, name types.NodeName) (strin
125126// InstanceTypeByProviderID returns the type of the specified instance.
126127func (cs * CSCloud ) InstanceTypeByProviderID (ctx context.Context , providerID string ) (string , error ) {
127128 instance , count , err := cs .client .VirtualMachine .GetVirtualMachineByID (
128- providerID ,
129+ cs . getInstanceIDFromProviderID ( providerID ) ,
129130 cloudstack .WithProject (cs .projectID ),
130131 )
131132 if err != nil {
@@ -151,7 +152,7 @@ func (cs *CSCloud) CurrentNodeName(ctx context.Context, hostname string) (types.
151152// InstanceExistsByProviderID returns if the instance still exists.
152153func (cs * CSCloud ) InstanceExistsByProviderID (ctx context.Context , providerID string ) (bool , error ) {
153154 _ , count , err := cs .client .VirtualMachine .GetVirtualMachineByID (
154- providerID ,
155+ cs . getInstanceIDFromProviderID ( providerID ) ,
155156 cloudstack .WithProject (cs .projectID ),
156157 )
157158 if err != nil {
@@ -185,6 +186,11 @@ func (cs *CSCloud) InstanceShutdown(ctx context.Context, node *corev1.Node) (boo
185186
186187func (cs * CSCloud ) InstanceMetadata (ctx context.Context , node * corev1.Node ) (* cloudprovider.InstanceMetadata , error ) {
187188
189+ instanceID , err := cs .InstanceID (ctx , types .NodeName (node .Name ))
190+ if err != nil {
191+ return nil , err
192+ }
193+
188194 instanceType , err := cs .InstanceType (ctx , types .NodeName (node .Name ))
189195 if err != nil {
190196 return nil , err
@@ -201,10 +207,22 @@ func (cs *CSCloud) InstanceMetadata(ctx context.Context, node *corev1.Node) (*cl
201207 }
202208
203209 return & cloudprovider.InstanceMetadata {
204- ProviderID : cs .ProviderName ( ),
210+ ProviderID : cs .getProviderIDFromInstanceID ( instanceID ),
205211 InstanceType : instanceType ,
206212 NodeAddresses : addresses ,
207213 Zone : cs .zone ,
208214 Region : zone .Region ,
209215 }, nil
210216}
217+
218+ func (cs * CSCloud ) getProviderIDFromInstanceID (instanceID string ) string {
219+ return fmt .Sprintf ("%s://%s" , cs .ProviderName (), instanceID )
220+ }
221+
222+ func (cs * CSCloud ) getInstanceIDFromProviderID (providerID string ) string {
223+ parts := strings .Split (providerID , "://" )
224+ if len (parts ) == 1 {
225+ return providerID
226+ }
227+ return parts [1 ]
228+ }
0 commit comments