Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f67dfb7

Browse files
committedJul 7, 2017
changes to validation to validate the hostsubnet for a specific cidr
1 parent bb7d9b7 commit f67dfb7

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed
 

‎pkg/sdn/apis/network/validation/validation.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ func ValidateClusterNetwork(clusterNet *sdnapi.ClusterNetwork) field.ErrorList {
2828
if len(clusterNet.ClusterNetworks) == 0 {
2929
allErrs = append(allErrs, field.Invalid(field.NewPath("clusterNetworks"), clusterNet.ClusterNetworks, "empty"))
3030
}
31-
for _, cidr := range clusterNet.ClusterNetworks {
32-
clusterIPNet, err := netutils.ParseCIDRMask(cidr.CIDR)
31+
for _, cn := range clusterNet.ClusterNetworks {
32+
clusterIPNet, err := netutils.ParseCIDRMask(cn.CIDR)
3333
if err != nil {
34-
allErrs = append(allErrs, field.Invalid(field.NewPath("network"), cidr.CIDR, err.Error()))
34+
allErrs = append(allErrs, field.Invalid(field.NewPath("network"), cn.CIDR, err.Error()))
3535
} else {
3636
maskLen, addrLen := clusterIPNet.Mask.Size()
37-
if clusterNet.HostSubnetLength > uint32(addrLen-maskLen) {
38-
allErrs = append(allErrs, field.Invalid(field.NewPath("hostSubnetLength"), clusterNet.HostSubnetLength, "subnet length is too large for clusterNetwork"))
39-
} else if clusterNet.HostSubnetLength < 2 {
40-
allErrs = append(allErrs, field.Invalid(field.NewPath("hostSubnetLength"), clusterNet.HostSubnetLength, "subnet length must be at least 2"))
37+
if cn.HostSubnetLength > uint32(addrLen-maskLen) {
38+
allErrs = append(allErrs, field.Invalid(field.NewPath("hostSubnetLength"), cn.HostSubnetLength, "subnet length is too large for clusterNetwork"))
39+
} else if cn.HostSubnetLength < 2 {
40+
allErrs = append(allErrs, field.Invalid(field.NewPath("hostSubnetLength"), cn.HostSubnetLength, "subnet length must be at least 2"))
4141
}
4242
}
4343

@@ -61,14 +61,14 @@ func ValidateClusterNetwork(clusterNet *sdnapi.ClusterNetwork) field.ErrorList {
6161
}
6262
}
6363
} else {
64-
allErrs = append(allErrs, field.Invalid(field.NewPath("ClusterDef"), clusterNet.ClusterNetworks, "cannot change the default ClusterNetwork record via API"))
64+
allErrs = append(allErrs, field.Invalid(field.NewPath("ClusterNetworks"), clusterNet.ClusterNetworks, "cannot change the default ClusterNetwork record via API"))
6565
}
6666
// if clusterNet.Network != defaultClusterNetwork.Network {
6767
// allErrs = append(allErrs, field.Invalid(field.NewPath("network"), clusterNet.Network, "cannot change the default ClusterNetwork record via API."))
6868
// }
69-
if clusterNet.HostSubnetLength != defaultClusterNetwork.HostSubnetLength {
70-
allErrs = append(allErrs, field.Invalid(field.NewPath("hostSubnetLength"), clusterNet.HostSubnetLength, "cannot change the default ClusterNetwork record via API."))
71-
}
69+
// if clusterNet.HostSubnetLength != defaultClusterNetwork.HostSubnetLength {
70+
// allErrs = append(allErrs, field.Invalid(field.NewPath("hostSubnetLength"), clusterNet.HostSubnetLength, "cannot change the default ClusterNetwork record via API."))
71+
// }
7272
if clusterNet.ServiceNetwork != defaultClusterNetwork.ServiceNetwork {
7373
allErrs = append(allErrs, field.Invalid(field.NewPath("serviceNetwork"), clusterNet.ServiceNetwork, "cannot change the default ClusterNetwork record via API."))
7474
}

0 commit comments

Comments
 (0)
Please sign in to comment.