From d4b3a7d4c47bf9b29f12b094ae1f429e9152235d Mon Sep 17 00:00:00 2001 From: Damyan Yordanov Date: Tue, 29 Oct 2024 14:55:50 +0100 Subject: [PATCH 1/3] Implement new configuration strategy for `metal` plugin --- README.md | 6 +++--- config.yaml | 16 +++++++++++++++- internal/api/{config.go => metal_config.go} | 2 +- plugins/metal/plugin.go | 2 +- plugins/metal/plugin_test.go | 12 ++++++------ plugins/metal/suite_test.go | 2 +- 6 files changed, 27 insertions(+), 13 deletions(-) rename internal/api/{config.go => metal_config.go} (94%) diff --git a/README.md b/README.md index 1243785..7ce959a 100644 --- a/README.md +++ b/README.md @@ -72,9 +72,9 @@ As for in-band, a kubernetes namespace shall be passed as a parameter. Further, The Metal plugin acts as a connection link between DHCP and the IronCore metal stack. It creates an `EndPoint` object for each machine with leased IP address. Those endpoints are then consumed by the metal operator, who then creates the corresponding `Machine` objects. ### Configuration -Path to an inventory yaml shall be passed as a string. Currently, there are two different ways to provide an inventory list: either by specifying a MAC address filter or by providing the inventory list explicitly. If both a static list and a filter are specified in the `inventory.yaml`, the static list gets a precedence, so the filter will be ignored. +The metal configuration consists of an inventory list. Currently, there are two different ways to provide an inventory list: either by specifying a MAC address filter or by providing the inventory list explicitly. If both a static list and a filter are specified in the `metal_config.yaml`, the static list gets a precedence, so the filter will be ignored. -Providing an explicit static inventory list in `inventory.yaml` goes as follows: +Providing an explicit static inventory list in `metal_config.yaml` goes as follows: ```yaml hosts: - name: server-01 @@ -84,7 +84,7 @@ hosts: ``` Providing a MAC address prefix filter list creates `Endpoint`s with a predefined prefix name. When the MAC address of an inventory does not match the prefix, the inventory will not be onboarded, so for now no "onboarding by default" occurs. Obviously a full MAC address is a valid prefix filter. -To get inventories with certain MACs onboarded, the following `inventory.yaml` shall be specified: +To get inventories with certain MACs onboarded, the following `metal_config.yaml` shall be specified: ```yaml namePrefix: server- # optional prefix, default: "compute-" filter: diff --git a/config.yaml b/config.yaml index 94abca9..7310c78 100644 --- a/config.yaml +++ b/config.yaml @@ -18,4 +18,18 @@ server6: # implement (i)PXE boot - pxeboot: tftp://[2001:db8::1]/ipxe/x86_64/ipxe http://[2001:db8::1]/ipxe/boot6 # create Endpoint objects in kubernetes - - metal: inventory.yaml \ No newline at end of file + - metal: metal_config.yaml + +--- +# metal_config.yaml +hosts: + - name: server-01 + macAddress: 00:1A:2B:3C:4D:5E + - name: server-02 + macAddress: 00:1A:2B:3C:4D:5F +namePrefix: server- # optional prefix, default: "compute-" +filter: + macPrefix: + - 00:1A:2B:3C:4D:5E + - 00:1A:2B:3C:4D:5F + - 00:AA:BB diff --git a/internal/api/config.go b/internal/api/metal_config.go similarity index 94% rename from internal/api/config.go rename to internal/api/metal_config.go index b05e9e0..78b5a56 100644 --- a/internal/api/config.go +++ b/internal/api/metal_config.go @@ -12,7 +12,7 @@ type Filter struct { MacPrefix []string `yaml:"macPrefix"` } -type Config struct { +type MetalConfig struct { NamePrefix string `yaml:"namePrefix"` Inventories []Inventory `yaml:"hosts"` Filter Filter `yaml:"filter"` diff --git a/plugins/metal/plugin.go b/plugins/metal/plugin.go index cb7cc5a..b2d1eeb 100644 --- a/plugins/metal/plugin.go +++ b/plugins/metal/plugin.go @@ -88,7 +88,7 @@ func loadConfig(args ...string) (*Inventory, error) { return nil, fmt.Errorf("failed to read config file: %v", err) } - var config api.Config + var config api.MetalConfig if err = yaml.Unmarshal(configData, &config); err != nil { return nil, fmt.Errorf("failed to parse config file: %v", err) } diff --git a/plugins/metal/plugin_test.go b/plugins/metal/plugin_test.go index e5fcc51..8bca061 100644 --- a/plugins/metal/plugin_test.go +++ b/plugins/metal/plugin_test.go @@ -120,7 +120,7 @@ var _ = Describe("Endpoint", func() { It("Should return an empty inventory for an empty list", func() { configFile := inventoryConfigFile - data := api.Config{ + data := api.MetalConfig{ Inventories: []api.Inventory{ {}, }, @@ -145,7 +145,7 @@ var _ = Describe("Endpoint", func() { It("Should return a valid inventory list with default name prefix for non-empty MAC address filter", func() { configFile := inventoryConfigFile - data := api.Config{ + data := api.MetalConfig{ Filter: api.Filter{ MacPrefix: []string{ "aa:bb:cc:dd:ee:ff", @@ -171,7 +171,7 @@ var _ = Describe("Endpoint", func() { It("Should return an inventory list with custom name prefix for non-empty MAC address filter and set prefix", func() { configFile := inventoryConfigFile - data := api.Config{ + data := api.MetalConfig{ NamePrefix: "server-", Filter: api.Filter{ MacPrefix: []string{ @@ -198,7 +198,7 @@ var _ = Describe("Endpoint", func() { It("Should return a valid inventory list for a non-empty inventory section, precedence over MAC filter", func() { configFile := inventoryConfigFile - data := api.Config{ + data := api.MetalConfig{ NamePrefix: "server-", Inventories: []api.Inventory{ { @@ -262,7 +262,7 @@ var _ = Describe("Endpoint", func() { relayedRequest, _ := dhcpv6.EncapsulateRelay(req, dhcpv6.MessageTypeRelayForward, net.IPv6loopback, linkLocalIPV6Addr) configFile := inventoryConfigFile - data := api.Config{ + data := api.MetalConfig{ NamePrefix: "foobar-", Inventories: []api.Inventory{}, Filter: api.Filter{ @@ -396,7 +396,7 @@ var _ = Describe("Endpoint", func() { stub, _ := dhcpv4.NewReplyFromRequest(req) configFile := inventoryConfigFile - data := api.Config{ + data := api.MetalConfig{ NamePrefix: "", Inventories: []api.Inventory{}, Filter: api.Filter{ diff --git a/plugins/metal/suite_test.go b/plugins/metal/suite_test.go index 29ba743..6eb57cd 100644 --- a/plugins/metal/suite_test.go +++ b/plugins/metal/suite_test.go @@ -122,7 +122,7 @@ func SetupTest() *corev1.Namespace { DeferCleanup(k8sClient.Delete, ns) configFile := inventoryConfigFile - data := api.Config{ + data := api.MetalConfig{ NamePrefix: "server-", Inventories: []api.Inventory{ { From 6d1d922d9e0b6393c0b724d977bacad36083a50a Mon Sep 17 00:00:00 2001 From: Damyan Yordanov Date: Mon, 4 Nov 2024 15:37:15 +0100 Subject: [PATCH 2/3] Split FeDHCP config and metal plugin config into different files Move all example configuration data to a new folder --- config.yaml => example/config.yaml | 16 +--------------- example/metal_config.yaml | 11 +++++++++++ 2 files changed, 12 insertions(+), 15 deletions(-) rename config.yaml => example/config.yaml (70%) create mode 100644 example/metal_config.yaml diff --git a/config.yaml b/example/config.yaml similarity index 70% rename from config.yaml rename to example/config.yaml index 7310c78..f4a41e6 100644 --- a/config.yaml +++ b/example/config.yaml @@ -18,18 +18,4 @@ server6: # implement (i)PXE boot - pxeboot: tftp://[2001:db8::1]/ipxe/x86_64/ipxe http://[2001:db8::1]/ipxe/boot6 # create Endpoint objects in kubernetes - - metal: metal_config.yaml - ---- -# metal_config.yaml -hosts: - - name: server-01 - macAddress: 00:1A:2B:3C:4D:5E - - name: server-02 - macAddress: 00:1A:2B:3C:4D:5F -namePrefix: server- # optional prefix, default: "compute-" -filter: - macPrefix: - - 00:1A:2B:3C:4D:5E - - 00:1A:2B:3C:4D:5F - - 00:AA:BB + - metal: metal_config.yaml \ No newline at end of file diff --git a/example/metal_config.yaml b/example/metal_config.yaml new file mode 100644 index 0000000..59690f7 --- /dev/null +++ b/example/metal_config.yaml @@ -0,0 +1,11 @@ +hosts: + - name: server-01 + macAddress: 00:1A:2B:3C:4D:5E + - name: server-02 + macAddress: 00:1A:2B:3C:4D:5F +namePrefix: server- # optional prefix, default: "compute-" +filter: + macPrefix: + - 00:1A:2B:3C:4D:5E + - 00:1A:2B:3C:4D:5F + - 00:AA:BB From 39c23c812d555ef3810518a79ea28cf50f2b0748 Mon Sep 17 00:00:00 2001 From: Damyan Yordanov Date: Mon, 4 Nov 2024 15:39:16 +0100 Subject: [PATCH 3/3] Fix `reuse` compliance --- .reuse/dep5 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.reuse/dep5 b/.reuse/dep5 index cfc181f..81c5ca6 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -13,7 +13,7 @@ Files: Dockerfile Makefile config/* - config.yaml + example/* go.mod go.sum hack/*