-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: split WithNetworkConfig into sub-options
Allow setting individual options for the network interface while generating config instead of providing whole config. This solves the problem of merging options from different sources to build the config. There should be no changes with this PR. This is prep work for control plane VIP. Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
- Loading branch information
Showing
11 changed files
with
163 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
pkg/machinery/config/types/v1alpha1/v1alpha1_network_options.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"github.com/AlekSi/pointer" | ||
|
||
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/machine" | ||
) | ||
|
||
// NetworkConfigOption generates NetworkConfig. | ||
type NetworkConfigOption func(machine.Type, *NetworkConfig) error | ||
|
||
// WithNetworkConfig sets whole network config structure, overwrites any previous options. | ||
func WithNetworkConfig(c *NetworkConfig) NetworkConfigOption { | ||
return func(_ machine.Type, cfg *NetworkConfig) error { | ||
*cfg = *c | ||
|
||
return nil | ||
} | ||
} | ||
|
||
// WithNetworkNameservers sets global nameservers list. | ||
func WithNetworkNameservers(nameservers ...string) NetworkConfigOption { | ||
return func(_ machine.Type, cfg *NetworkConfig) error { | ||
cfg.NameServers = append(cfg.NameServers, nameservers...) | ||
|
||
return nil | ||
} | ||
} | ||
|
||
// WithNetworkInterfaceIgnore marks interface as ignored. | ||
func WithNetworkInterfaceIgnore(iface string) NetworkConfigOption { | ||
return func(_ machine.Type, cfg *NetworkConfig) error { | ||
cfg.GetDevice(iface).DeviceIgnore = true | ||
|
||
return nil | ||
} | ||
} | ||
|
||
// WithNetworkInterfaceDHCP enables DHCP for the interface. | ||
func WithNetworkInterfaceDHCP(iface string, enable bool) NetworkConfigOption { | ||
return func(_ machine.Type, cfg *NetworkConfig) error { | ||
cfg.GetDevice(iface).DeviceDHCP = true | ||
|
||
return nil | ||
} | ||
} | ||
|
||
// WithNetworkInterfaceDHCPv4 enables DHCPv4 for the interface. | ||
func WithNetworkInterfaceDHCPv4(iface string, enable bool) NetworkConfigOption { | ||
return func(_ machine.Type, cfg *NetworkConfig) error { | ||
dev := cfg.GetDevice(iface) | ||
|
||
if dev.DeviceDHCPOptions == nil { | ||
dev.DeviceDHCPOptions = &DHCPOptions{} | ||
} | ||
|
||
dev.DeviceDHCPOptions.DHCPIPv4 = pointer.ToBool(enable) | ||
|
||
return nil | ||
} | ||
} | ||
|
||
// WithNetworkInterfaceDHCPv6 enables DHCPv6 for the interface. | ||
func WithNetworkInterfaceDHCPv6(iface string, enable bool) NetworkConfigOption { | ||
return func(_ machine.Type, cfg *NetworkConfig) error { | ||
dev := cfg.GetDevice(iface) | ||
|
||
if dev.DeviceDHCPOptions == nil { | ||
dev.DeviceDHCPOptions = &DHCPOptions{} | ||
} | ||
|
||
dev.DeviceDHCPOptions.DHCPIPv6 = pointer.ToBool(enable) | ||
|
||
return nil | ||
} | ||
} | ||
|
||
// WithNetworkInterfaceCIDR configures interface for static addressing. | ||
func WithNetworkInterfaceCIDR(iface, cidr string) NetworkConfigOption { | ||
return func(_ machine.Type, cfg *NetworkConfig) error { | ||
cfg.GetDevice(iface).DeviceCIDR = cidr | ||
|
||
return nil | ||
} | ||
} | ||
|
||
// WithNetworkInterfaceMTU configures interface MTU. | ||
func WithNetworkInterfaceMTU(iface string, mtu int) NetworkConfigOption { | ||
return func(_ machine.Type, cfg *NetworkConfig) error { | ||
cfg.GetDevice(iface).DeviceMTU = mtu | ||
|
||
return nil | ||
} | ||
} | ||
|
||
// WithNetworkInterfaceWireguard configures interface for Wireguard. | ||
func WithNetworkInterfaceWireguard(iface string, wireguardConfig *DeviceWireguardConfig) NetworkConfigOption { | ||
return func(_ machine.Type, cfg *NetworkConfig) error { | ||
cfg.GetDevice(iface).DeviceWireguardConfig = wireguardConfig | ||
|
||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters