Skip to content

Commit

Permalink
fix: better testing of NetworkInterfaces so test doesn't fail
Browse files Browse the repository at this point in the history
ref: #105
  • Loading branch information
budimanjojo committed Apr 6, 2023
1 parent 08d9308 commit a32a621
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
9 changes: 5 additions & 4 deletions pkg/config/validate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Node struct {
DisableSearchDomain string `validate:"isBool"`
Nameservers []string `validate:"isIPList"`
ConfigPatches []map[string]interface{} `validate:"isRFC6902List"`
NetworkInterfaces []*NetworkInterface
NetworkInterfaces []*NetworkInterface `validate:"isValidNetworkInterfaces"`
InstallDiskSelector *InstallDiskSelector
KernelModules []*KernelModule
NodeLabels map[string]string
Expand All @@ -60,9 +60,9 @@ type InstallDiskSelector struct {
}

type NetworkInterface struct {
Interface string `validate:"requiredWithout:Nodes.[].NetworkInterfaces.DeviceSelector"`
DeviceSelector *NetworkDeviceSelector `validate:"requiredWithout:Nodes.[].NetworkInterfaces.Interface"`
Addresses []string `validate:"isCIDRList"`
Interface string
DeviceSelector *NetworkDeviceSelector
Addresses []string `validate:"isCIDRList"`
Routes []Route
Bond *Bond
Vlans []*Vlan
Expand Down Expand Up @@ -174,5 +174,6 @@ func (c Config) Messages() map[string]string {
"isInt": "{field} is not a valid integer",
"isUint": "{field} is not a valid unsigned integer",
"isDomainOrIP": "{field} is not a valid domain or IP address",
"isValidNetworkInterfaces": "{field} requires one of `interface` and `deviceSelector` to be set",
}
}
2 changes: 1 addition & 1 deletion pkg/config/validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ nodes:
"Nodes.0.InstallDisk": false,
"Nodes.0.DisableSearchDomain": true,
"Nodes.0.Nameservers": false,
"Nodes.0.NetworkInterfaces.0.Interface": true,
"Nodes.0.NetworkInterfaces": true,
"Nodes.0.NetworkInterfaces.0.Addresses": true,
"Nodes.0.NetworkInterfaces.0.Mtu": true,
"Nodes.0.NetworkInterfaces.0.Routes.0.Gateway": true,
Expand Down
11 changes: 11 additions & 0 deletions pkg/config/validate/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,14 @@ func (c Config) IsDomainOrIP(domainIP string) bool {

return false
}

func (c Config) IsValidNetworkInterfaces(ifaces []*NetworkInterface) bool {
for _, iface := range ifaces {
if iface.Interface == "" && iface.DeviceSelector == nil {
return false
} else if iface.Interface != "" && iface.DeviceSelector != nil {
return false
}
}
return true
}

0 comments on commit a32a621

Please sign in to comment.