Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove requirement of having deprecated clusterNetworkCIDR/hostSubnetLength in master.networkConfig #18669

Merged
merged 3 commits into from
Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pkg/cmd/server/apis/config/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,15 @@ func fuzzInternalObject(t *testing.T, forVersion schema.GroupVersion, item runti
obj.NetworkConfig.DeprecatedClusterNetworkCIDR = obj.NetworkConfig.ClusterNetworks[0].CIDR
obj.NetworkConfig.DeprecatedHostSubnetLength = obj.NetworkConfig.ClusterNetworks[0].HostSubnetLength
} else {
obj.NetworkConfig.ClusterNetworks = nil
obj.NetworkConfig.DeprecatedClusterNetworkCIDR = ""
obj.NetworkConfig.DeprecatedHostSubnetLength = 0
clusterNetwork := []configapi.ClusterNetworkEntry{
{
CIDR: obj.NetworkConfig.DeprecatedClusterNetworkCIDR,
HostSubnetLength: obj.NetworkConfig.DeprecatedHostSubnetLength,
},
}
obj.NetworkConfig.ClusterNetworks = clusterNetwork
}

// TODO stop duplicating the conversion in the test.
Expand Down
28 changes: 7 additions & 21 deletions pkg/cmd/server/apis/config/v1/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,31 +392,17 @@ func addConversionFuncs(scheme *runtime.Scheme) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
return err
}
if len(in.DeprecatedClusterNetworkCIDR) > 0 || in.DeprecatedHostSubnetLength > 0 {
if len(out.ClusterNetworks) > 0 {
out.ClusterNetworks[0].CIDR = in.DeprecatedClusterNetworkCIDR
out.ClusterNetworks[0].HostSubnetLength = in.DeprecatedHostSubnetLength
} else {
out.ClusterNetworks = []internal.ClusterNetworkEntry{
{
CIDR: in.DeprecatedClusterNetworkCIDR,
HostSubnetLength: in.DeprecatedHostSubnetLength,
},
}

if len(out.ClusterNetworks) == 0 {
out.ClusterNetworks = []internal.ClusterNetworkEntry{
{
CIDR: in.DeprecatedClusterNetworkCIDR,
HostSubnetLength: in.DeprecatedHostSubnetLength,
},
}
}
return nil
},
func(in *internal.MasterNetworkConfig, out *MasterNetworkConfig, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
return err
}
if len(in.ClusterNetworks) > 0 {
out.DeprecatedHostSubnetLength = in.ClusterNetworks[0].HostSubnetLength
out.DeprecatedClusterNetworkCIDR = in.ClusterNetworks[0].CIDR
}
return nil
},
func(in *AuditConfig, out *internal.AuditConfig, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
return err
Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/server/apis/config/v1/testdata/master-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ masterClients:
openshiftLoopbackKubeConfig: ""
masterPublicURL: ""
networkConfig:
clusterNetworks: null
clusterNetworks:
- cidr: ""
hostSubnetLength: 0
externalIPNetworkCIDRs: null
ingressIPNetworkCIDR: 172.29.0.0/16
networkPluginName: ""
Expand Down
21 changes: 16 additions & 5 deletions pkg/cmd/server/apis/config/validation/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,11 +724,22 @@ func ValidateIngressIPNetworkCIDR(config *configapi.MasterConfig, fldPath *field
func ValidateDeprecatedClusterNetworkConfig(config *configapi.MasterConfig, fldPath *field.Path) ValidationResults {
validationResults := ValidationResults{}

if len(config.NetworkConfig.ClusterNetworks) > 0 && config.NetworkConfig.DeprecatedHostSubnetLength != config.NetworkConfig.ClusterNetworks[0].HostSubnetLength {
validationResults.AddErrors(field.Invalid(fldPath.Child("hostSubnetLength"), config.NetworkConfig.DeprecatedHostSubnetLength, "cannot set hostSubnetLength and clusterNetworks, please use clusterNetworks"))
}
if len(config.NetworkConfig.ClusterNetworks) > 0 && config.NetworkConfig.DeprecatedClusterNetworkCIDR != config.NetworkConfig.ClusterNetworks[0].CIDR {
validationResults.AddErrors(field.Invalid(fldPath.Child("clusterNetworkCIDR"), config.NetworkConfig.DeprecatedClusterNetworkCIDR, "cannot set clusterNetworkCIDR and clusterNetworks, please use clusterNetworks"))
if len(config.NetworkConfig.ClusterNetworks) > 1 {
if config.NetworkConfig.DeprecatedHostSubnetLength != 0 {
validationResults.AddErrors(field.Invalid(fldPath.Child("hostSubnetLength"), config.NetworkConfig.DeprecatedHostSubnetLength, "cannot set hostSubnetLength and clusterNetworks, please use clusterNetworks"))
}
if len(config.NetworkConfig.DeprecatedClusterNetworkCIDR) != 0 {
validationResults.AddErrors(field.Invalid(fldPath.Child("clusterNetworkCIDR"), config.NetworkConfig.DeprecatedClusterNetworkCIDR, "cannot set clusterNetworkCIDR and clusterNetworks, please use clusterNetworks"))
}

} else if len(config.NetworkConfig.ClusterNetworks) == 1 {
if config.NetworkConfig.DeprecatedHostSubnetLength != config.NetworkConfig.ClusterNetworks[0].HostSubnetLength && config.NetworkConfig.DeprecatedHostSubnetLength != 0 {
validationResults.AddErrors(field.Invalid(fldPath.Child("hostSubnetLength"), config.NetworkConfig.DeprecatedHostSubnetLength, "cannot set hostSubnetLength and clusterNetworks, please use clusterNetworks"))
}
if config.NetworkConfig.DeprecatedClusterNetworkCIDR != config.NetworkConfig.ClusterNetworks[0].CIDR && len(config.NetworkConfig.DeprecatedClusterNetworkCIDR) != 0 {
validationResults.AddErrors(field.Invalid(fldPath.Child("clusterNetworkCIDR"), config.NetworkConfig.DeprecatedClusterNetworkCIDR, "cannot set clusterNetworkCIDR and clusterNetworks, please use clusterNetworks"))
}
}

return validationResults
}