Skip to content

Commit 2696919

Browse files
Merge pull request #16649 from smarterclayton/clusternetwork
Automatic merge from submit-queue (batch tested with PRs 16644, 16649, 16656, 16651, 16663). Switch from defaulting to converting clusterNetworkCIDR Fixes break. On disk, deprecated fields override the first value in the clusterNetworks array if specified. When writing out, the deprecated fields are set to the first value of the network CIDR. Fixes #16627 This fixes oc cluster up. @csrwng @JacobTanenbaum
2 parents 7fb934d + a5f3a43 commit 2696919

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

pkg/cmd/server/api/serialization_test.go

+15-7
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,22 @@ func fuzzInternalObject(t *testing.T, forVersion schema.GroupVersion, item runti
112112
obj.NetworkConfig.ServiceNetworkCIDR = "10.0.0.0/24"
113113
}
114114
}
115-
if len(obj.NetworkConfig.ClusterNetworks) == 0 {
116-
clusterNetwork := []configapi.ClusterNetworkEntry{
117-
{
118-
CIDR: "10.128.0.0/14",
119-
HostSubnetLength: 9,
120-
},
115+
if c.RandBool() {
116+
if len(obj.NetworkConfig.ClusterNetworks) == 0 {
117+
clusterNetwork := []configapi.ClusterNetworkEntry{
118+
{
119+
CIDR: "10.128.0.0/14",
120+
HostSubnetLength: 9,
121+
},
122+
}
123+
obj.NetworkConfig.ClusterNetworks = clusterNetwork
121124
}
122-
obj.NetworkConfig.ClusterNetworks = clusterNetwork
125+
obj.NetworkConfig.DeprecatedClusterNetworkCIDR = obj.NetworkConfig.ClusterNetworks[0].CIDR
126+
obj.NetworkConfig.DeprecatedHostSubnetLength = obj.NetworkConfig.ClusterNetworks[0].HostSubnetLength
127+
} else {
128+
obj.NetworkConfig.ClusterNetworks = nil
129+
obj.NetworkConfig.DeprecatedClusterNetworkCIDR = ""
130+
obj.NetworkConfig.DeprecatedHostSubnetLength = 0
123131
}
124132

125133
// TODO stop duplicating the conversion in the test.

pkg/cmd/server/api/v1/conversions.go

+29-6
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,6 @@ func SetDefaults_MasterConfig(obj *MasterConfig) {
9090
obj.NetworkConfig.ServiceNetworkCIDR = "10.0.0.0/24"
9191
}
9292
}
93-
if len(obj.NetworkConfig.ClusterNetworks) == 0 {
94-
obj.NetworkConfig.ClusterNetworks = []ClusterNetworkEntry{{CIDR: obj.NetworkConfig.DeprecatedClusterNetworkCIDR, HostSubnetLength: obj.NetworkConfig.DeprecatedHostSubnetLength}}
95-
96-
obj.NetworkConfig.DeprecatedClusterNetworkCIDR = ""
97-
obj.NetworkConfig.DeprecatedHostSubnetLength = 0
98-
}
9993

10094
// TODO Detect cloud provider when not using built-in kubernetes
10195
kubeConfig := obj.KubernetesMasterConfig
@@ -371,6 +365,35 @@ func addConversionFuncs(scheme *runtime.Scheme) error {
371365
out.DynamicProvisioningEnabled = &enabled
372366
return nil
373367
},
368+
func(in *MasterNetworkConfig, out *internal.MasterNetworkConfig, s conversion.Scope) error {
369+
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
370+
return err
371+
}
372+
if len(in.DeprecatedClusterNetworkCIDR) > 0 || in.DeprecatedHostSubnetLength > 0 {
373+
if len(out.ClusterNetworks) > 0 {
374+
out.ClusterNetworks[0].CIDR = in.DeprecatedClusterNetworkCIDR
375+
out.ClusterNetworks[0].HostSubnetLength = in.DeprecatedHostSubnetLength
376+
} else {
377+
out.ClusterNetworks = []internal.ClusterNetworkEntry{
378+
{
379+
CIDR: in.DeprecatedClusterNetworkCIDR,
380+
HostSubnetLength: in.DeprecatedHostSubnetLength,
381+
},
382+
}
383+
}
384+
}
385+
return nil
386+
},
387+
func(in *internal.MasterNetworkConfig, out *MasterNetworkConfig, s conversion.Scope) error {
388+
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
389+
return err
390+
}
391+
if len(in.ClusterNetworks) > 0 {
392+
out.DeprecatedHostSubnetLength = in.ClusterNetworks[0].HostSubnetLength
393+
out.DeprecatedClusterNetworkCIDR = in.ClusterNetworks[0].CIDR
394+
}
395+
return nil
396+
},
374397

375398
metav1.Convert_resource_Quantity_To_resource_Quantity,
376399
metav1.Convert_bool_To_Pointer_bool,

pkg/cmd/server/api/validation/master.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -849,10 +849,10 @@ func ValidateIngressIPNetworkCIDR(config *api.MasterConfig, fldPath *field.Path)
849849
func ValidateDeprecatedClusterNetworkConfig(config *api.MasterConfig, fldPath *field.Path) ValidationResults {
850850
validationResults := ValidationResults{}
851851

852-
if len(config.NetworkConfig.ClusterNetworks) > 0 && config.NetworkConfig.DeprecatedHostSubnetLength != 0 {
852+
if len(config.NetworkConfig.ClusterNetworks) > 0 && config.NetworkConfig.DeprecatedHostSubnetLength != config.NetworkConfig.ClusterNetworks[0].HostSubnetLength {
853853
validationResults.AddErrors(field.Invalid(fldPath.Child("hostSubnetLength"), config.NetworkConfig.DeprecatedHostSubnetLength, "cannot set hostSubnetLength and clusterNetworks, please use clusterNetworks"))
854854
}
855-
if len(config.NetworkConfig.ClusterNetworks) > 0 && config.NetworkConfig.DeprecatedClusterNetworkCIDR != "" {
855+
if len(config.NetworkConfig.ClusterNetworks) > 0 && config.NetworkConfig.DeprecatedClusterNetworkCIDR != config.NetworkConfig.ClusterNetworks[0].CIDR {
856856
validationResults.AddErrors(field.Invalid(fldPath.Child("clusterNetworkCIDR"), config.NetworkConfig.DeprecatedClusterNetworkCIDR, "cannot set clusterNetworkCIDR and clusterNetworks, please use clusterNetworks"))
857857
}
858858
return validationResults

0 commit comments

Comments
 (0)