From 30bef74373528c5aa4ff5e863123206934170846 Mon Sep 17 00:00:00 2001 From: Hans Rakers Date: Thu, 4 Jul 2024 10:56:58 +0200 Subject: [PATCH] chore: Add/adjust some logging --- pkg/cloud/metadata.go | 8 ++++---- pkg/cloud/node.go | 15 +++++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pkg/cloud/metadata.go b/pkg/cloud/metadata.go index 8848527..17a0c80 100644 --- a/pkg/cloud/metadata.go +++ b/pkg/cloud/metadata.go @@ -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 } @@ -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 } @@ -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 } @@ -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 "" } diff --git a/pkg/cloud/node.go b/pkg/cloud/node.go index 29c11bf..86e56f6 100644 --- a/pkg/cloud/node.go +++ b/pkg/cloud/node.go @@ -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) }