Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new configuration strategy for metal plugin #207

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
16 changes: 15 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- metal: metal_config.yaml

---
damyan marked this conversation as resolved.
Show resolved Hide resolved
# 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
2 changes: 1 addition & 1 deletion internal/api/config.go → internal/api/metal_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion plugins/metal/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 6 additions & 6 deletions plugins/metal/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{},
},
Expand All @@ -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",
Expand All @@ -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{
Expand All @@ -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{
{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion plugins/metal/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down
Loading