From 08fdf7a768a9a4ca324e4b063b3666f15c41c067 Mon Sep 17 00:00:00 2001 From: Archana Holla Date: Wed, 6 Sep 2023 10:02:04 -0700 Subject: [PATCH] Update VM resource graph query to use unique fields during iteration. Signed-off-by: Archana Holla --- .../plugins/azure/azure_crd_helpers.go | 6 ++++-- .../plugins/azure/azure_resourcegraph_vmTable.go | 16 ++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pkg/cloudprovider/plugins/azure/azure_crd_helpers.go b/pkg/cloudprovider/plugins/azure/azure_crd_helpers.go index 8395e64b..c5b67bea 100644 --- a/pkg/cloudprovider/plugins/azure/azure_crd_helpers.go +++ b/pkg/cloudprovider/plugins/azure/azure_crd_helpers.go @@ -78,13 +78,15 @@ func computeInstanceToInternalVirtualMachineObject(instance *virtualMachineTable } var nsgIds []string - if nwInf.NsgID != nil { + if nwInf.NsgID != nil && *nwInf.NsgID != "" { nsgIds = append(nsgIds, *nwInf.NsgID) } var asgIDs []string for _, asgID := range nwInf.ApplicationSecurityGroupIDs { - asgIDs = append(asgIDs, *asgID) + if asgID != nil && *asgID != "" { + asgIDs = append(asgIDs, *asgID) + } } networkInterface := runtimev1alpha1.NetworkInterface{ diff --git a/pkg/cloudprovider/plugins/azure/azure_resourcegraph_vmTable.go b/pkg/cloudprovider/plugins/azure/azure_resourcegraph_vmTable.go index 9233ac67..35438392 100644 --- a/pkg/cloudprovider/plugins/azure/azure_resourcegraph_vmTable.go +++ b/pkg/cloudprovider/plugins/azure/azure_resourcegraph_vmTable.go @@ -95,19 +95,19 @@ const ( " {{ end }}" + " | extend publicIpId = tolower(tostring(ipconfig.properties.publicIPAddress.id))" + " | extend nicPrivateIp = ipconfig.properties.privateIPAddress" + - " | extend applicationSecurityGroup = ipconfig.properties.applicationSecurityGroups" + + " | extend applicationSecurityGroups = ipconfig.properties.applicationSecurityGroups" + " | join kind = leftouter (" + " Resources" + " | where type =~ 'microsoft.network/publicipaddresses'" + " | project publicIpId = tolower(id), nicPublicIp = properties.ipAddress" + " ) on publicIpId" + - " | mvexpand applicationSecurityGroup" + - " | extend appId = tolower(applicationSecurityGroup.id)" + - " | summarize nicTags = any(tags), macAddress = any(macAddress), vnetId = any(vnetId), nsgId = any(nsgId), " + - "applicationSecurityGroupIds = make_list(appId), nicPublicIps = make_list(nicPublicIp), " + - "nicPrivateIps = make_list(nicPrivateIp) by id, name" + - " | project nicId = tolower(id), nicName = name, nicPublicIps, nicPrivateIps, vnetId, macAddress, " + - "nicTags, nsgId = tolower(nsgId), applicationSecurityGroupIds" + + " | mvexpand applicationSecurityGroup = applicationSecurityGroups" + + " | extend appSecurityGroupId = tolower(applicationSecurityGroup.id)" + + " | summarize applicationSecurityGroupIds = make_set(appSecurityGroupId), " + + "nicTags = any(tags), macAddress = any(macAddress), vnetId = any(vnetId), nsgId = any(nsgId), " + + "nicPublicIps = make_set(nicPublicIp), nicPrivateIps = make_set(nicPrivateIp) by id, name" + + " | project nicId = tolower(id), nicName = name, nsgId = tolower(nsgId), nicPublicIps, nicPrivateIps, vnetId, macAddress, " + + "nicTags, applicationSecurityGroupIds" + ") on nicId" + "| extend networkInterfaceDetails = pack(\"id\", nicId, \"name\", nicName, \"macAddress\", macAddress, \"privateIps\"," + "nicPrivateIps, \"publicIps\", nicPublicIps, \"tags\", nicTags, \"vnetId\", vnetId, \"nsgId\", nsgId, " +