Skip to content

Commit

Permalink
Configure primary nic if only set in cfg file (#408)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaitanyaKulkarni28 authored Aug 1, 2024
1 parent 3aa08e9 commit ca3272f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions google_guest_agent/network/manager/netplan_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type netplanEthernet struct {
type netplanDHCPOverrides struct {
// When true, the domain name received from the DHCP server will be used as DNS
// search domain over this link.
UseDomains bool `yaml:"use-domains,omitempty"`
UseDomains *bool `yaml:"use-domains,omitempty"`
}

// netplanMatch contains the keys uses to match an interface.
Expand Down Expand Up @@ -207,6 +207,9 @@ func (n netplan) writeNetworkdDropin(interfaces, ipv6Interfaces []string) error
}

for i, iface := range interfaces {
if !shouldManageInterface(i == 0) {
continue
}
logger.Debugf("writing systemd-networkd drop-in config for %s", iface)

var dhcp = "ipv4"
Expand Down Expand Up @@ -274,6 +277,12 @@ func (nd networkdNetplanDropin) write(n netplan, iface string) error {
return nil
}

// shouldUseDomains returns true if interface index is 0.
func shouldUseDomains(idx int) *bool {
res := idx == 0
return &res
}

// writeNetplanEthernetDropin selects the ethernet configuration, transforms it
// into a netplan dropin format and writes it down to the netplan's drop-in directory.
func (n netplan) writeNetplanEthernetDropin(mtuMap map[string]int, interfaces, ipv6Interfaces []string) error {
Expand All @@ -295,7 +304,7 @@ func (n netplan) writeNetplanEthernetDropin(mtuMap map[string]int, interfaces, i
Match: netplanMatch{Name: iface},
DHCPv4: &trueVal,
DHCP4Overrides: &netplanDHCPOverrides{
UseDomains: (i == 0),
UseDomains: shouldUseDomains(i),
},
}

Expand All @@ -306,7 +315,7 @@ func (n netplan) writeNetplanEthernetDropin(mtuMap map[string]int, interfaces, i
if slices.Contains(ipv6Interfaces, iface) {
ne.DHCPv6 = &trueVal
ne.DHCP6Overrides = &netplanDHCPOverrides{
UseDomains: (i == 0),
UseDomains: shouldUseDomains(i),
}
}

Expand Down

0 comments on commit ca3272f

Please sign in to comment.