From 630e3591188e86d2c681e2405115371890f2c5e2 Mon Sep 17 00:00:00 2001 From: Gaurav Ghildiyal Date: Fri, 17 Oct 2025 03:56:57 +0000 Subject: [PATCH] fix: Only parse topology when it actually exists This also helps avoid unnecessary logging that happens each time we need to reconstruct ResourceSlice state and it's cloud provider attributes. --- pkg/cloudprovider/gce/gce.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/cloudprovider/gce/gce.go b/pkg/cloudprovider/gce/gce.go index 451f141c..f58f83a3 100644 --- a/pkg/cloudprovider/gce/gce.go +++ b/pkg/cloudprovider/gce/gce.go @@ -136,14 +136,16 @@ func GetGCEAttributes(mac string, instance *cloudprovider.CloudInstance) map[res attributes := make(map[resourceapi.QualifiedName]resourceapi.DeviceAttribute) attributes[AttrGCEMachineType] = resourceapi.DeviceAttribute{StringValue: &instance.Type} - topologyParts := strings.SplitN(strings.TrimPrefix(instance.Topology, "/"), "/", 3) - // topology may not be always available - if len(topologyParts) == 3 { - attributes[AttrGCEBlock] = resourceapi.DeviceAttribute{StringValue: &topologyParts[0]} - attributes[AttrGCESubBlock] = resourceapi.DeviceAttribute{StringValue: &topologyParts[1]} - attributes[AttrGCEHost] = resourceapi.DeviceAttribute{StringValue: &topologyParts[2]} - } else { - klog.Warningf("Error parsing host topology %q; it may be unsupported for the VM", instance.Topology) + if instance.Topology != "" { + topologyParts := strings.SplitN(strings.TrimPrefix(instance.Topology, "/"), "/", 3) + // topology may not be always available + if len(topologyParts) == 3 { + attributes[AttrGCEBlock] = resourceapi.DeviceAttribute{StringValue: &topologyParts[0]} + attributes[AttrGCESubBlock] = resourceapi.DeviceAttribute{StringValue: &topologyParts[1]} + attributes[AttrGCEHost] = resourceapi.DeviceAttribute{StringValue: &topologyParts[2]} + } else { + klog.Warningf("Error parsing host topology %q; it may be unsupported for the VM", instance.Topology) + } } // Determine properties specific to the device identified by this mac