Skip to content

Commit

Permalink
Correct networking validation for DHCP and Distributed
Browse files Browse the repository at this point in the history
  • Loading branch information
dtantsur committed Nov 17, 2023
1 parent fcdb3d4 commit d3ab3c6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions api/v1alpha1/ironic_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ func validateIPinPrefix(ip string, prefix netip.Prefix) error {
}

func ValidateDHCP(ironic *IronicSpec, dhcp *DHCP) error {
if ironic.Networking.IPAddress == "" {
return errors.New("networking.ipAddress is required when DHCP is used")
hasNetworking := ironic.Networking.IPAddress != "" || ironic.Networking.Interface != "" || len(ironic.Networking.MACAddresses) > 0
if !hasNetworking {
return errors.New("networking: at least one of ipAddress, interface or macAddresses is required when DHCP is used")
}
if dhcp.NetworkCIDR == "" {
return errors.New("networking.dhcp.networkCIRD is required when DHCP is used")
Expand Down Expand Up @@ -191,6 +192,10 @@ func validateIronic(ironic *IronicSpec, old *IronicSpec) error {
return err
}

if ironic.Distributed && ironic.Networking.IPAddress != "" {
return errors.New("networking.ipAddress makes no sense with distributed architecture")
}

if dhcp := ironic.Networking.DHCP; dhcp != nil {
if err := ValidateDHCP(ironic, dhcp); err != nil {
return err
Expand Down

0 comments on commit d3ab3c6

Please sign in to comment.