Skip to content

Commit

Permalink
network/netplan: do generate instead of apply (#445)
Browse files Browse the repository at this point in the history
We don't want to rely on netplan's apply operation as it will do more
than we expect to the interfaces we are managing. Instead we use
generate operation and we manage the reload from our side.
  • Loading branch information
dorileo authored Oct 9, 2024
1 parent 8c8535a commit db64a08
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions google_guest_agent/network/manager/netplan_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,16 @@ func (n *netplan) SetupEthernetInterface(ctx context.Context, config *cfg.Sectio
func (n *netplan) reloadConfigs(ctx context.Context) error {
logger.Infof("Reloading netplan configs...")

// Avoid restarting netplan.
if err := run.Quiet(ctx, "netplan", "generate"); err != nil {
return fmt.Errorf("error generating netplan based config: %w", err)
}

// Avoid restarting systemd-networkd.
if err := run.Quiet(ctx, "networkctl", "reload"); err != nil {
return fmt.Errorf("error reloading systemd-networkd network configs: %v", err)
}

// Avoid restarting netplan.
if err := run.Quiet(ctx, "netplan", "apply"); err != nil {
return fmt.Errorf("error applying netplan changes: %w", err)
}

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion google_guest_agent/network/manager/netplan_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func TestSetupVlanInterface(t *testing.T) {
t.Errorf("SetupVlanInterface(ctx, nil, %+v) failed unexpectedly with error: %v", nics, err)
}

wantCmds := []string{"netplan apply", "networkctl reload"}
wantCmds := []string{"netplan generate", "networkctl reload"}
gotCmds := runner.executedCommands
sort.Strings(gotCmds)

Expand Down

0 comments on commit db64a08

Please sign in to comment.