You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by vi...@apache.org on 2025/11/25 17:02:46 UTC
(cloudstack-kubernetes-provider) branch fix-provider-id created (now d2ddd959)
This is an automated email from the ASF dual-hosted git repository.
vishesh pushed a change to branch fix-provider-id
in repository https://gitbox.apache.org/repos/asf/cloudstack-kubernetes-provider.git
at d2ddd959 Fix usage of provider ID
This branch includes the following new commits:
new d2ddd959 Fix usage of provider ID
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(cloudstack-kubernetes-provider) 01/01: Fix usage of provider ID
Posted by vi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vishesh pushed a commit to branch fix-provider-id
in repository https://gitbox.apache.org/repos/asf/cloudstack-kubernetes-provider.git
commit d2ddd95922fd1d511ecb04e55c37a783200d26dc
Author: vishesh92 <vi...@gmail.com>
AuthorDate: Tue Nov 25 18:02:36 2025 +0100
Fix usage of provider ID
---
cloudstack.go | 2 +-
cloudstack_instances.go | 26 ++++++++++++++++++++++----
2 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/cloudstack.go b/cloudstack.go
index 8d78a861..a384cbd9 100644
--- a/cloudstack.go
+++ b/cloudstack.go
@@ -200,7 +200,7 @@ func (cs *CSCloud) GetZoneByProviderID(ctx context.Context, providerID string) (
zone := cloudprovider.Zone{}
instance, count, err := cs.client.VirtualMachine.GetVirtualMachineByID(
- providerID,
+ cs.getInstanceIDFromProviderID(providerID),
cloudstack.WithProject(cs.projectID),
)
if err != nil {
diff --git a/cloudstack_instances.go b/cloudstack_instances.go
index 91d65751..48f1e7c6 100644
--- a/cloudstack_instances.go
+++ b/cloudstack_instances.go
@@ -24,6 +24,7 @@ import (
"errors"
"fmt"
"regexp"
+ "strings"
"github.com/apache/cloudstack-go/v2/cloudstack"
corev1 "k8s.io/api/core/v1"
@@ -53,7 +54,7 @@ func (cs *CSCloud) NodeAddresses(ctx context.Context, name types.NodeName) ([]co
// NodeAddressesByProviderID returns the addresses of the specified instance.
func (cs *CSCloud) NodeAddressesByProviderID(ctx context.Context, providerID string) ([]corev1.NodeAddress, error) {
instance, count, err := cs.client.VirtualMachine.GetVirtualMachineByID(
- providerID,
+ cs.getInstanceIDFromProviderID(providerID),
cloudstack.WithProject(cs.projectID),
)
if err != nil {
@@ -125,7 +126,7 @@ func (cs *CSCloud) InstanceType(ctx context.Context, name types.NodeName) (strin
// InstanceTypeByProviderID returns the type of the specified instance.
func (cs *CSCloud) InstanceTypeByProviderID(ctx context.Context, providerID string) (string, error) {
instance, count, err := cs.client.VirtualMachine.GetVirtualMachineByID(
- providerID,
+ cs.getInstanceIDFromProviderID(providerID),
cloudstack.WithProject(cs.projectID),
)
if err != nil {
@@ -151,7 +152,7 @@ func (cs *CSCloud) CurrentNodeName(ctx context.Context, hostname string) (types.
// InstanceExistsByProviderID returns if the instance still exists.
func (cs *CSCloud) InstanceExistsByProviderID(ctx context.Context, providerID string) (bool, error) {
_, count, err := cs.client.VirtualMachine.GetVirtualMachineByID(
- providerID,
+ cs.getInstanceIDFromProviderID(providerID),
cloudstack.WithProject(cs.projectID),
)
if err != nil {
@@ -185,6 +186,11 @@ func (cs *CSCloud) InstanceShutdown(ctx context.Context, node *corev1.Node) (boo
func (cs *CSCloud) InstanceMetadata(ctx context.Context, node *corev1.Node) (*cloudprovider.InstanceMetadata, error) {
+ instanceID, err := cs.InstanceID(ctx, types.NodeName(node.Name))
+ if err != nil {
+ return nil, err
+ }
+
instanceType, err := cs.InstanceType(ctx, types.NodeName(node.Name))
if err != nil {
return nil, err
@@ -201,10 +207,22 @@ func (cs *CSCloud) InstanceMetadata(ctx context.Context, node *corev1.Node) (*cl
}
return &cloudprovider.InstanceMetadata{
- ProviderID: cs.ProviderName(),
+ ProviderID: cs.getProviderIDFromInstanceID(instanceID),
InstanceType: instanceType,
NodeAddresses: addresses,
Zone: cs.zone,
Region: zone.Region,
}, nil
}
+
+func (cs *CSCloud) getProviderIDFromInstanceID(instanceID string) string {
+ return fmt.Sprintf("%s://%s", cs.ProviderName(), instanceID)
+}
+
+func (cs *CSCloud) getInstanceIDFromProviderID(providerID string) string {
+ parts := strings.Split(providerID, "://")
+ if len(parts) == 1 {
+ return providerID
+ }
+ return parts[1]
+}