Skip to content

Commit

Permalink
Skip SetupInterfaces if configs are already applied (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaitanyaKulkarni28 authored Oct 9, 2024
1 parent 2a9cb58 commit 8c8535a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions google_guest_agent/network/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"net"
"os"
"reflect"
"time"

"github.com/GoogleCloudPlatform/guest-agent/google_guest_agent/cfg"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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...")
Expand Down Expand Up @@ -235,6 +250,7 @@ func SetupInterfaces(ctx context.Context, config *cfg.Sections, mds *metadata.De
logInterfaceState(ctx)
}()

seenMetadata = mds
return nil
}

Expand Down

0 comments on commit 8c8535a

Please sign in to comment.