Skip to content

Conversation

juanluisvaladas
Copy link
Contributor

@juanluisvaladas juanluisvaladas commented Sep 5, 2025

Description

Allow to configure CPLB using interface mac address instead of interface name.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

  • Manual test
  • Auto test added

Checklist

  • My code follows the style guidelines of this project
  • My commit messages are signed-off
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

@juanluisvaladas juanluisvaladas requested review from a team as code owners September 5, 2025 11:11
@juanluisvaladas juanluisvaladas added this to the 1.34 milestone Sep 5, 2025
@juanluisvaladas juanluisvaladas force-pushed the cplb-mac-nic branch 5 times, most recently from fec3171 to 4be3b5f Compare September 5, 2025 15:38
}
case VRRPInterfaceTypeMAC:
if len(k.VRRPInstances[i].InterfaceMACAddresses) == 0 {
errs = append(errs, errors.New("InterfaceMACAddresses must be defined when InterfaceType is mac"))
Copy link
Contributor Author

@juanluisvaladas juanluisvaladas Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: The PR is large already, so I want to deal with this in a separate PR, but the validation could be better, we should use k8s.io/apimachinery/pkg/util/validation/field like we do in workerprofile.go

Also we could do better error checking in the test for this function, again, we should improve it like we do in workerprofile.go...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to use those errors right away. We'll never get around to refactor this once this lands. We can just omit the proper field path propagation for now, and use something like this?

Suggested change
errs = append(errs, errors.New("InterfaceMACAddresses must be defined when InterfaceType is mac"))
path := field.NewPath("interfaceMACAddresses")
err := field.Required(path, `must be defined when interfaceType is "mac"`)
errs = append(errs, err)

Also, it's a good practice to use the JSON field names in the error messages, as this is what users will be facing.

@ncopa
Copy link
Collaborator

ncopa commented Oct 1, 2025

What is the reasoning to support multiple MAC addresses?

If we could get away with a single, we could maybe let the interface be either an interface name or a MAC address.

  interface: 00:00:5E:00:53:00 

@juanluisvaladas
Copy link
Contributor Author

What is the reasoning to support multiple MAC addresses?

It was requested by k0rdent people so that they could have the same configuration for all the control plane nodes. If they have 3 control plane nodes with MAC addresses X, Y and Z, they'll define X, Y and Z in the configuration file and only the correct value will be used. Apparently providing different configuration per control plane node is major change for them.

If we could get away with a single, we could maybe let the interface be either an interface name or a MAC address.

That was actually the initial implementation.

@twz123
Copy link
Member

twz123 commented Oct 2, 2025

Apparently providing different configuration per control plane node is major change for them.

I don't think this is a good argument for allowing multiple interfaces. Can we come up with some reasoning that makes sense for k0s itself to support MAC lists for a single node?

Copy link
Member

@twz123 twz123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about removing the type field?

| `virtualIPs` | List of virtual IP address used by the VRRP instance. Each virtual IP must be a CIDR as defined in RFC 4632 and RFC 4291.A list of the CIDRs handled by the VRRP instance. |
| `interfaceType` | The type of the interface. If not specified, k0s will use `interface`. Valid values are `interface` and `mac`. If `interfaceType` is `mac`, k0s will use the field `interfaceMACAddresses`, otherwise it will use the field `interface`. Default: `interface`. |
| `interface` | The NIC used by the virtual router. If not specified, k0s will use the interface that owns the default route. |
| `interfaceMACAddresses` | A list of MAC addresses for the interface. MAC addresses are evaluated in order and the first match will be chosen. If none of the MAC addresses match, an error is returned and k0s will not start. This field is only used when `interfaceType` is set to `mac`. |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have two separate fields for this, we don't need the type field IMO in this case. We can make it either interface or interfaceMACAddresses. I reckon this will save some code/docs.

}
case VRRPInterfaceTypeMAC:
if len(k.VRRPInstances[i].InterfaceMACAddresses) == 0 {
errs = append(errs, errors.New("InterfaceMACAddresses must be defined when InterfaceType is mac"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to use those errors right away. We'll never get around to refactor this once this lands. We can just omit the proper field path propagation for now, and use something like this?

Suggested change
errs = append(errs, errors.New("InterfaceMACAddresses must be defined when InterfaceType is mac"))
path := field.NewPath("interfaceMACAddresses")
err := field.Required(path, `must be defined when interfaceType is "mac"`)
errs = append(errs, err)

Also, it's a good practice to use the JSON field names in the error messages, as this is what users will be facing.

k.VRRPInstances[i].Interface = iface
}
case VRRPInterfaceTypeMAC:
if len(k.VRRPInstances[i].InterfaceMACAddresses) == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to distinguish nil from an empty slice. Would be different errors (required vs. invalid).

Signed-off-by: Juan-Luis de Sousa-Valadas Castaño <jvaladas@mirantis.com>
@juanluisvaladas juanluisvaladas marked this pull request as draft October 2, 2025 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants