Skip to content

Commit

Permalink
chore: Add/adjust some logging
Browse files Browse the repository at this point in the history
  • Loading branch information
hrak committed Jul 4, 2024
1 parent 4ea00b2 commit 30bef74
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pkg/cloud/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (c *client) metadataInstanceID(ctx context.Context) string {

// Try a NODE_ID environment variable
if envNodeID := os.Getenv("NODE_ID"); envNodeID != "" {
logger.V(4).Info("Found CloudStack VM ID from envvar NODE_ID", "nodeID", envNodeID)
logger.Info("Found CloudStack VM ID from envvar NODE_ID", "nodeID", envNodeID)

return envNodeID
}
Expand All @@ -38,7 +38,7 @@ func (c *client) metadataInstanceID(ctx context.Context) string {
if err != nil {
logger.Error(err, "Cannot read cloud-init instance data")
} else if ciData.V1.InstanceID != "" {
logger.V(4).Info("Found CloudStack VM ID from cloud-init", "nodeID", ciData.V1.InstanceID)
logger.Info("Found CloudStack VM ID from cloud-init", "nodeID", ciData.V1.InstanceID)

return ciData.V1.InstanceID
}
Expand All @@ -57,7 +57,7 @@ func (c *client) metadataInstanceID(ctx context.Context) string {
if err != nil {
logger.Error(err, "Cannot read ignition metadata")
} else if instanceID != "" {
logger.V(4).Info("Found CloudStack VM ID from ignition", "nodeID", instanceID)
logger.Info("Found CloudStack VM ID from ignition", "nodeID", instanceID)

return instanceID
}
Expand All @@ -68,7 +68,7 @@ func (c *client) metadataInstanceID(ctx context.Context) string {
logger.Error(err, "Cannot read file "+ignitionMetadataFilePath)
}

logger.V(4).Info("CloudStack VM ID not found in meta-data")
logger.Info("CloudStack VM ID not found in meta-data")

return ""
}
Expand Down
15 changes: 11 additions & 4 deletions pkg/cloud/node.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package cloud

import "context"
import (
"context"
"k8s.io/klog/v2"
)

func (c *client) GetNodeInfo(ctx context.Context, vmName string) (*VM, error) {
// First, try to read the instance ID from meta-data (cloud-init)
logger := klog.FromContext(ctx)

// First, try to read the instance ID from meta-data.
if id := c.metadataInstanceID(ctx); id != "" {
// Instance ID found using metadata
logger.V(4).Info("Looking up node info using VM ID found in metadata", "nodeID", id)

// Use CloudStack API to get VM info
return c.GetVMByID(ctx, id)
}

// VM ID was not found using metadata.
// Use VM name instead
// VM ID was not found using metadata, fall back to using VM name instead.
logger.V(4).Info("Looking up node info using VM name", "nodeName", vmName)

return c.getVMByName(ctx, vmName)
}

0 comments on commit 30bef74

Please sign in to comment.