From 8c8535ad3a09b51d860555cebb7c1113d46b3a14 Mon Sep 17 00:00:00 2001 From: Chaitanya Kulkarni Date: Tue, 8 Oct 2024 17:28:08 -0700 Subject: [PATCH] Skip SetupInterfaces if configs are already applied (#444) --- google_guest_agent/network/manager/manager.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/google_guest_agent/network/manager/manager.go b/google_guest_agent/network/manager/manager.go index de23c59b..114ead04 100644 --- a/google_guest_agent/network/manager/manager.go +++ b/google_guest_agent/network/manager/manager.go @@ -21,6 +21,7 @@ import ( "fmt" "net" "os" + "reflect" "time" "github.com/GoogleCloudPlatform/guest-agent/google_guest_agent/cfg" @@ -128,6 +129,10 @@ var ( // osinfoGet points to the function to use for getting osInfo. // Primarily used for testing. osinfoGet = osinfo.Get + + // seenMetadata keeps a copy of MDS descriptor that was already seen and applied + // in terms of VLAN/Ethernet NIC configuration by the manager. + seenMetadata *metadata.Descriptor ) // detectNetworkManager detects the network manager managing the primary network interface. @@ -168,6 +173,16 @@ func reformatVlanNics(mds *metadata.Descriptor, nics *Interfaces, ethernetInterf // interface if enabled in the configuration using the native network manager service detected // to be managing the primary network interface. func SetupInterfaces(ctx context.Context, config *cfg.Sections, mds *metadata.Descriptor) error { + if seenMetadata != nil { + diff := reflect.DeepEqual(mds.Instance.NetworkInterfaces, seenMetadata.Instance.NetworkInterfaces) && + reflect.DeepEqual(mds.Instance.VlanNetworkInterfaces, seenMetadata.Instance.VlanNetworkInterfaces) + + if diff { + logger.Debugf("MDS returned Ethernet NICs [%+v] and VLAN NICs [%+v] are already seen and applied, skipping", seenMetadata.Instance.NetworkInterfaces, seenMetadata.Instance.VlanNetworkInterfaces) + return nil + } + } + // User may have disabled network interface setup entirely. if !config.NetworkInterfaces.Setup { logger.Infof("Network interface setup disabled, skipping...") @@ -235,6 +250,7 @@ func SetupInterfaces(ctx context.Context, config *cfg.Sections, mds *metadata.De logInterfaceState(ctx) }() + seenMetadata = mds return nil }