Skip to content
This repository was archived by the owner on May 6, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions pkg/cloudprovider/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ type CloudInstance struct {
}

type NetworkInterface struct {
IPv4 string `json:"ip,omitempty"`
IPv6 []string `json:"ipv6,omitempty"`
Mac string `json:"mac,omitempty"`
MTU int `json:"mtu,omitempty"`
Network string `json:"network,omitempty"`
IPv4 string `json:"ip,omitempty"`
IPv6 []string `json:"ipv6,omitempty"`
Mac string `json:"mac,omitempty"`
MTU int `json:"mtu,omitempty"`
Network string `json:"network,omitempty"`
IPAliases []string `json:"ipAliases,omitempty"`
Comment thread
gauravkghildiyal marked this conversation as resolved.
}

// CloudProvider represents the type of cloud provider.
Expand Down
18 changes: 12 additions & 6 deletions pkg/cloudprovider/gce/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ const (
GCEAttrPrefix = "gce.dra.net"

AttrGCEBlock = GCEAttrPrefix + "/" + "block"
AttrGCESubblock = GCEAttrPrefix + "/" + "subblock"
AttrGCESubBlock = GCEAttrPrefix + "/" + "subBlock"
AttrGCEHost = GCEAttrPrefix + "/" + "host"
AttrGCENetworkName = GCEAttrPrefix + "/" + "networkName"
AttrGCENetworkProjectNumber = GCEAttrPrefix + "/" + "networkProjectNumber"
AttrGCEIPAliases = GCEAttrPrefix + "/" + "ipAliases"
)

var (
Expand Down Expand Up @@ -131,9 +132,9 @@ func GetGCEAttributes(mac string, instance *cloudprovider.CloudInstance) map[res
topologyParts := strings.SplitN(strings.TrimPrefix(instance.Topology, "/"), "/", 3)
// topology may not be always available
if len(topologyParts) == 3 {
attributes["gce.dra.net/block"] = resourceapi.DeviceAttribute{StringValue: &topologyParts[0]}
attributes["gce.dra.net/subblock"] = resourceapi.DeviceAttribute{StringValue: &topologyParts[1]}
attributes["gce.dra.net/host"] = resourceapi.DeviceAttribute{StringValue: &topologyParts[2]}
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)
}
Expand All @@ -150,6 +151,11 @@ func GetGCEAttributes(mac string, instance *cloudprovider.CloudInstance) map[res
}
}
if interfaceForMacFound {
if len(interfaceForMac.IPAliases) > 0 {
ipAliases := strings.Join(interfaceForMac.IPAliases, ",")
attributes[AttrGCEIPAliases] = resourceapi.DeviceAttribute{StringValue: &ipAliases}
}

var projectNumber int64
var name string
// Use custom parsing because the network path is
Expand All @@ -159,8 +165,8 @@ func GetGCEAttributes(mac string, instance *cloudprovider.CloudInstance) map[res
klog.Warningf("Error parsing network %q : %v", interfaceForMac.Network, err)
return nil
}
attributes["gce.dra.net/networkName"] = resourceapi.DeviceAttribute{StringValue: &name}
attributes["gce.dra.net/networkProjectNumber"] = resourceapi.DeviceAttribute{IntValue: &projectNumber}
attributes[AttrGCENetworkName] = resourceapi.DeviceAttribute{StringValue: &name}
attributes[AttrGCENetworkProjectNumber] = resourceapi.DeviceAttribute{IntValue: &projectNumber}
} else {
klog.V(4).Infof("No cloud metadata found for device with mac %q; it is possible this device has no associated cloud provider metadata", mac)
}
Expand Down
40 changes: 30 additions & 10 deletions pkg/inventory/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

"github.com/google/dranet/pkg/cloudprovider"
"github.com/google/dranet/pkg/cloudprovider/gce"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
resourceapi "k8s.io/api/resource/v1"
Expand Down Expand Up @@ -70,9 +71,9 @@ func TestGetProviderAttributes(t *testing.T) {
Topology: "/block/subblock/host",
},
want: map[resourceapi.QualifiedName]resourceapi.DeviceAttribute{
"gce.dra.net/block": {StringValue: ptr.To("block")},
"gce.dra.net/subblock": {StringValue: ptr.To("subblock")},
"gce.dra.net/host": {StringValue: ptr.To("host")},
gce.AttrGCEBlock: {StringValue: ptr.To("block")},
gce.AttrGCESubBlock: {StringValue: ptr.To("subblock")},
gce.AttrGCEHost: {StringValue: ptr.To("host")},
},
},
{
Expand All @@ -87,11 +88,11 @@ func TestGetProviderAttributes(t *testing.T) {
Topology: "/block/subblock/host",
},
want: map[resourceapi.QualifiedName]resourceapi.DeviceAttribute{
"gce.dra.net/networkName": {StringValue: ptr.To("test-network")},
"gce.dra.net/networkProjectNumber": {IntValue: ptr.To(int64(12345))},
"gce.dra.net/block": {StringValue: ptr.To("block")},
"gce.dra.net/subblock": {StringValue: ptr.To("subblock")},
"gce.dra.net/host": {StringValue: ptr.To("host")},
gce.AttrGCENetworkName: {StringValue: ptr.To("test-network")},
gce.AttrGCENetworkProjectNumber: {IntValue: ptr.To(int64(12345))},
gce.AttrGCEBlock: {StringValue: ptr.To("block")},
gce.AttrGCESubBlock: {StringValue: ptr.To("subblock")},
gce.AttrGCEHost: {StringValue: ptr.To("host")},
},
},
{
Expand All @@ -117,8 +118,8 @@ func TestGetProviderAttributes(t *testing.T) {
Topology: "/block/subblock",
},
want: map[resourceapi.QualifiedName]resourceapi.DeviceAttribute{
"gce.dra.net/networkName": {StringValue: ptr.To("test-network")},
"gce.dra.net/networkProjectNumber": {IntValue: ptr.To(int64(12345))},
gce.AttrGCENetworkName: {StringValue: ptr.To("test-network")},
gce.AttrGCENetworkProjectNumber: {IntValue: ptr.To(int64(12345))},
},
},
{
Expand All @@ -132,6 +133,25 @@ func TestGetProviderAttributes(t *testing.T) {
},
want: nil,
},
{
name: "GCE provider, MAC found, with IP aliases",
mac: "00:11:22:33:44:55",
instance: &cloudprovider.CloudInstance{
Provider: cloudprovider.CloudProviderGCE,
Interfaces: []cloudprovider.NetworkInterface{
{
Mac: "00:11:22:33:44:55",
Network: "projects/12345/networks/test-network",
IPAliases: []string{"10.0.0.1/24", "10.0.0.2/24"},
},
},
},
want: map[resourceapi.QualifiedName]resourceapi.DeviceAttribute{
gce.AttrGCENetworkName: {StringValue: ptr.To("test-network")},
gce.AttrGCENetworkProjectNumber: {IntValue: ptr.To(int64(12345))},
gce.AttrGCEIPAliases: {StringValue: ptr.To("10.0.0.1/24,10.0.0.2/24")},
},
},
}

for _, tt := range tests {
Expand Down
Loading