Extend validator for host in machineNetwork
This PR extends the validator checking whether the host belongs to the
machineNetwork so that instead of a single entry, the host is compared
against all the networks specified as Machine Networks.
Contributes-to:
@@ -312,14 +312,24 @@ func GetClusterNetworks(hosts []*models.Host, log logrus.FieldLogger) []string {
}
func IsHostInPrimaryMachineNetCidr(log logrus.FieldLogger, cluster *common.Cluster, host *models.Host) bool {
+ // The host should belong to all the networks specified as Machine Networks.
+
+ // TODO(mko) This rule should be revised as soon as OCP supports multiple machineNetwork
+ // entries using the same IP stack.
+
if !IsMachineCidrAvailable(cluster) {
return false
}
- _, machineIpnet, err := net.ParseCIDR(string(cluster.MachineNetworks[0].Cidr))
+
+ ret := true
+ for _, machineNet := range cluster.MachineNetworks {
+ _, machineIpnet, err := net.ParseCIDR(string(machineNet.Cidr))
if err != nil {
return false
}
- return belongsToNetwork(log, host, machineIpnet)
+ ret = ret && belongsToNetwork(log, host, machineIpnet)
+ }
+ return ret
}
type IPSet map[strfmt.IPv4]struct{}
