Skip to content

Commit f39df7e

Browse files
Allowing multiple CIDR addresses for an openshift cluster to allocate nodes from
This is all the human edited files pretaining to that so far
1 parent a294495 commit f39df7e

26 files changed

+466
-242
lines changed

pkg/cmd/cli/describe/printer.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,9 +1002,16 @@ func printNetNamespaceList(list *sdnapi.NetNamespaceList, w io.Writer, opts kpri
10021002
}
10031003

10041004
func printClusterNetwork(n *sdnapi.ClusterNetwork, w io.Writer, opts kprinters.PrintOptions) error {
1005+
var cidrList []string
10051006
name := formatResourceName(opts.Kind, n.Name, opts.WithKind)
1006-
_, err := fmt.Fprintf(w, "%s\t%s\t%d\t%s\t%s\n", name, n.Network, n.HostSubnetLength, n.ServiceNetwork, n.PluginName)
1007-
return err
1007+
for _, cidr := range n.ClusterNetworks {
1008+
cidrList = append(cidrList, cidr.CIDR)
1009+
_, err := fmt.Fprintf(w, "%s\t%s\t%d\t%s\t%s\n", name, cidr.CIDR, n.HostSubnetLength, n.ServiceNetwork, n.PluginName)
1010+
if err != nil {
1011+
return err
1012+
}
1013+
}
1014+
return nil
10081015
}
10091016

10101017
func printClusterNetworkList(list *sdnapi.ClusterNetworkList, w io.Writer, opts kprinters.PrintOptions) error {

pkg/cmd/server/api/types.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -611,10 +611,11 @@ type UserAgentDenyRule struct {
611611

612612
// MasterNetworkConfig to be passed to the compiled in network plugin
613613
type MasterNetworkConfig struct {
614-
NetworkPluginName string
615-
ClusterNetworkCIDR string
616-
HostSubnetLength uint32
617-
ServiceNetworkCIDR string
614+
NetworkPluginName string
615+
DeprecatedClusterNetworkCIDR string
616+
ClusterNetworks []ClusterNetworkEntry
617+
HostSubnetLength uint32
618+
ServiceNetworkCIDR string
618619
// ExternalIPNetworkCIDRs controls what values are acceptable for the service external IP field. If empty, no externalIP
619620
// may be set. It may contain a list of CIDRs which are checked for access. If a CIDR is prefixed with !, IPs in that
620621
// CIDR will be rejected. Rejections will be applied first, then the IP checked against one of the allowed CIDRs. You
@@ -627,6 +628,10 @@ type MasterNetworkConfig struct {
627628
IngressIPNetworkCIDR string
628629
}
629630

631+
type ClusterNetworkEntry struct {
632+
CIDR string
633+
}
634+
630635
type ImageConfig struct {
631636
// Format describes how to determine image names for system components
632637
Format string

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ func addDefaultingFuncs(scheme *runtime.Scheme) error {
7878
}
7979
setDefault_ClientConnectionOverrides(obj.MasterClients.ExternalKubernetesClientConnectionOverrides)
8080

81+
if len(obj.NetworkConfig.ClusterNetworks) == 0 {
82+
obj.NetworkConfig.ClusterNetworks = []ClusterNetworkEntry{{CIDR: obj.NetworkConfig.DeprecatedClusterNetworkCIDR}}
83+
}
8184
// Populate the new NetworkConfig.ServiceNetworkCIDR field from the KubernetesMasterConfig.ServicesSubnet field if needed
8285
if len(obj.NetworkConfig.ServiceNetworkCIDR) == 0 {
8386
if obj.KubernetesMasterConfig != nil && len(obj.KubernetesMasterConfig.ServicesSubnet) > 0 {
@@ -95,8 +98,10 @@ func addDefaultingFuncs(scheme *runtime.Scheme) error {
9598

9699
if noCloudProvider && len(obj.NetworkConfig.IngressIPNetworkCIDR) == 0 {
97100
cidr := internal.DefaultIngressIPNetworkCIDR
98-
if !(internal.CIDRsOverlap(cidr, obj.NetworkConfig.ClusterNetworkCIDR) || internal.CIDRsOverlap(cidr, obj.NetworkConfig.ServiceNetworkCIDR)) {
99-
obj.NetworkConfig.IngressIPNetworkCIDR = cidr
101+
for _, entry := range obj.NetworkConfig.ClusterNetworks {
102+
if !(internal.CIDRsOverlap(cidr, entry.CIDR) || internal.CIDRsOverlap(cidr, obj.NetworkConfig.ServiceNetworkCIDR)) {
103+
obj.NetworkConfig.IngressIPNetworkCIDR = cidr
104+
}
100105
}
101106
}
102107

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,10 @@ type RoutingConfig struct {
495495
type MasterNetworkConfig struct {
496496
// NetworkPluginName is the name of the network plugin to use
497497
NetworkPluginName string `json:"networkPluginName"`
498-
// ClusterNetworkCIDR is the CIDR string to specify the global overlay network's L3 space
499-
ClusterNetworkCIDR string `json:"clusterNetworkCIDR"`
498+
// Deprecated and maintained for backwards compatibility, use ClusterNetworks instead
499+
DeprecatedClusterNetworkCIDR string `json:"clusterNetworkCIDR,omitempty`
500+
// ClusterNetworks is a list of cluster networks that defines the global overlay network's L3 space
501+
ClusterNetworks []ClusterNetworkEntry `json:"clusterNetworks"`
500502
// HostSubnetLength is the number of bits to allocate to each host's subnet e.g. 8 would mean a /24 network on the host
501503
HostSubnetLength uint32 `json:"hostSubnetLength"`
502504
// ServiceNetwork is the CIDR string to specify the service networks
@@ -513,6 +515,11 @@ type MasterNetworkConfig struct {
513515
IngressIPNetworkCIDR string `json:"ingressIPNetworkCIDR"`
514516
}
515517

518+
// ClusterNetworkEntry defines an L3 space for the global overlay network
519+
type ClusterNetworkEntry struct {
520+
CIDR string `json:"cidr"`
521+
}
522+
516523
// ImageConfig holds the necessary configuration options for building image names for system components
517524
type ImageConfig struct {
518525
// Format is the format of the name to be built for the system component

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ masterClients:
216216
masterPublicURL: ""
217217
networkConfig:
218218
clusterNetworkCIDR: ""
219+
clusterNetworkConfig: null
219220
externalIPNetworkCIDRs: null
220221
hostSubnetLength: 0
221222
ingressIPNetworkCIDR: ""

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,10 @@ func ValidateIngressIPNetworkCIDR(config *api.MasterConfig, fldPath *field.Path)
766766
noCloudProvider := kubeConfig != nil && (len(kubeConfig.ControllerArguments["cloud-provider"]) == 0 || kubeConfig.ControllerArguments["cloud-provider"][0] == "")
767767

768768
if noCloudProvider {
769-
if api.CIDRsOverlap(cidr, config.NetworkConfig.ClusterNetworkCIDR) {
770-
addError("conflicts with cluster network CIDR")
769+
for _, entry := range config.NetworkConfig.ClusterNetworks {
770+
if api.CIDRsOverlap(cidr, entry.CIDR) {
771+
addError("conflicts with cluster network CIDR")
772+
}
771773
}
772774
if api.CIDRsOverlap(cidr, config.NetworkConfig.ServiceNetworkCIDR) {
773775
addError("conflicts with service network CIDR")

pkg/cmd/server/origin/master_config.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,12 @@ func newAdmissionChain(pluginNames []string, admissionConfigFilename string, plu
823823

824824
case serviceadmit.RestrictedEndpointsPluginName:
825825
// we need to set some customer parameters, so create by hand
826-
restrictedNetworks, err := serviceadmit.ParseSimpleCIDRRules([]string{options.NetworkConfig.ClusterNetworkCIDR, options.NetworkConfig.ServiceNetworkCIDR})
826+
var restricted []string
827+
restricted = append(restricted, options.NetworkConfig.ServiceNetworkCIDR)
828+
for _, cidr := range options.NetworkConfig.ClusterNetworks {
829+
restricted = append(restricted, cidr.CIDR)
830+
}
831+
restrictedNetworks, err := serviceadmit.ParseSimpleCIDRRules(restricted)
827832
if err != nil {
828833
// should have been caught with validation
829834
return nil, err

pkg/cmd/server/start/master_args.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/url"
77
"path"
88
"strconv"
9+
"strings"
910

1011
"github.com/spf13/pflag"
1112

@@ -188,6 +189,15 @@ func (args MasterArgs) BuildSerializeableMasterConfig() (*configapi.MasterConfig
188189

189190
dnsServingInfo := servingInfoForAddr(&dnsBindAddr)
190191

192+
var clusterNetworkConfig []configapi.ClusterNetworkEntry
193+
194+
for _, cidr := range strings.Split(args.NetworkArgs.ClusterNetworkCIDR, ",") {
195+
clusterNetworkEntry := configapi.ClusterNetworkEntry{
196+
CIDR: cidr,
197+
}
198+
clusterNetworkConfig = append(clusterNetworkConfig, clusterNetworkEntry)
199+
}
200+
191201
config := &configapi.MasterConfig{
192202
ServingInfo: configapi.HTTPServingInfo{
193203
ServingInfo: listenServingInfo,
@@ -263,10 +273,10 @@ func (args MasterArgs) BuildSerializeableMasterConfig() (*configapi.MasterConfig
263273
},
264274

265275
NetworkConfig: configapi.MasterNetworkConfig{
266-
NetworkPluginName: args.NetworkArgs.NetworkPluginName,
267-
ClusterNetworkCIDR: args.NetworkArgs.ClusterNetworkCIDR,
268-
HostSubnetLength: args.NetworkArgs.HostSubnetLength,
269-
ServiceNetworkCIDR: args.NetworkArgs.ServiceNetworkCIDR,
276+
NetworkPluginName: args.NetworkArgs.NetworkPluginName,
277+
ClusterNetworks: clusterNetworkConfig,
278+
HostSubnetLength: args.NetworkArgs.HostSubnetLength,
279+
ServiceNetworkCIDR: args.NetworkArgs.ServiceNetworkCIDR,
270280
},
271281

272282
VolumeConfig: configapi.MasterVolumeConfig{

pkg/sdn/apis/network/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@ type ClusterNetwork struct {
1616
metav1.ObjectMeta
1717

1818
Network string
19+
ClusterNetworks []ClusterNetworkEntry
1920
HostSubnetLength uint32
2021
ServiceNetwork string
2122
PluginName string
2223
}
2324

25+
type ClusterNetworkEntry struct {
26+
CIDR string
27+
}
28+
2429
type ClusterNetworkList struct {
2530
metav1.TypeMeta
2631
metav1.ListMeta

pkg/sdn/apis/network/v1/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ type ClusterNetwork struct {
2020

2121
// Network is a CIDR string specifying the global overlay network's L3 space
2222
Network string `json:"network" protobuf:"bytes,2,opt,name=network"`
23+
// PLACEHOLDER
24+
ClusterNetworks []ClusterNetworkEntry `json:"clusterNetworks" protobuf:"bytes,6,rep,name=clusterNetworks"`
2325
// HostSubnetLength is the number of bits of network to allocate to each node. eg, 8 would mean that each node would have a /24 slice of the overlay network for its pods
2426
HostSubnetLength uint32 `json:"hostsubnetlength" protobuf:"varint,3,opt,name=hostsubnetlength"`
2527
// ServiceNetwork is the CIDR range that Service IP addresses are allocated from
@@ -28,6 +30,11 @@ type ClusterNetwork struct {
2830
PluginName string `json:"pluginName,omitempty" protobuf:"bytes,5,opt,name=pluginName"`
2931
}
3032

33+
// PLACEHOLDER
34+
type ClusterNetworkEntry struct {
35+
CIDR string `json:"CIDR" protobuf:"bytes,1,opt,name=CIDR"`
36+
}
37+
3138
// ClusterNetworkList is a collection of ClusterNetworks
3239
type ClusterNetworkList struct {
3340
metav1.TypeMeta `json:",inline"`

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

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,52 @@ func SetDefaultClusterNetwork(cn sdnapi.ClusterNetwork) {
2020
defaultClusterNetwork = &cn
2121
}
2222

23+
2324
// ValidateClusterNetwork tests if required fields in the ClusterNetwork are set, and ensures that the "default" ClusterNetwork can only be set to the correct values
2425
func ValidateClusterNetwork(clusterNet *sdnapi.ClusterNetwork) field.ErrorList {
2526
allErrs := validation.ValidateObjectMeta(&clusterNet.ObjectMeta, false, path.ValidatePathSegmentName, field.NewPath("metadata"))
2627

27-
clusterIPNet, err := netutils.ParseCIDRMask(clusterNet.Network)
28-
if err != nil {
29-
allErrs = append(allErrs, field.Invalid(field.NewPath("network"), clusterNet.Network, err.Error()))
30-
} else {
31-
maskLen, addrLen := clusterIPNet.Mask.Size()
32-
if clusterNet.HostSubnetLength > uint32(addrLen-maskLen) {
33-
allErrs = append(allErrs, field.Invalid(field.NewPath("hostSubnetLength"), clusterNet.HostSubnetLength, "subnet length is too large for clusterNetwork"))
34-
} else if clusterNet.HostSubnetLength < 2 {
35-
allErrs = append(allErrs, field.Invalid(field.NewPath("hostSubnetLength"), clusterNet.HostSubnetLength, "subnet length must be at least 2"))
36-
}
37-
}
38-
39-
serviceIPNet, err := netutils.ParseCIDRMask(clusterNet.ServiceNetwork)
40-
if err != nil {
41-
allErrs = append(allErrs, field.Invalid(field.NewPath("serviceNetwork"), clusterNet.ServiceNetwork, err.Error()))
28+
if len(clusterNet.ClusterNetworks) == 0 {
29+
allErrs = append(allErrs, field.Invalid(field.NewPath("clusterNetworks"), clusterNet.ClusterNetworks, "empty"))
4230
}
31+
for _, cidr := range clusterNet.ClusterNetworks {
32+
clusterIPNet, err := netutils.ParseCIDRMask(cidr.CIDR)
33+
if err != nil {
34+
allErrs = append(allErrs, field.Invalid(field.NewPath("network"), cidr.CIDR, err.Error()))
35+
} else {
36+
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"))
41+
}
42+
}
4343

44-
if (clusterIPNet != nil) && (serviceIPNet != nil) && clusterIPNet.Contains(serviceIPNet.IP) {
45-
allErrs = append(allErrs, field.Invalid(field.NewPath("serviceNetwork"), clusterNet.ServiceNetwork, "service network overlaps with cluster network"))
46-
}
47-
if (serviceIPNet != nil) && (clusterIPNet != nil) && serviceIPNet.Contains(clusterIPNet.IP) {
48-
allErrs = append(allErrs, field.Invalid(field.NewPath("network"), clusterNet.Network, "cluster network overlaps with service network"))
44+
serviceIPNet, err := netutils.ParseCIDRMask(clusterNet.ServiceNetwork)
45+
if err != nil {
46+
allErrs = append(allErrs, field.Invalid(field.NewPath("serviceNetwork"), clusterNet.ServiceNetwork, err.Error()))
47+
}
48+
if (clusterIPNet != nil) && (serviceIPNet != nil) && clusterIPNet.Contains(serviceIPNet.IP) {
49+
allErrs = append(allErrs, field.Invalid(field.NewPath("serviceNetwork"), clusterNet.ServiceNetwork, "service network overlaps with cluster network"))
50+
}
51+
if (serviceIPNet != nil) && (clusterIPNet != nil) && serviceIPNet.Contains(clusterIPNet.IP) {
52+
allErrs = append(allErrs, field.Invalid(field.NewPath("network"), clusterNet.Network, "cluster network overlaps with service network"))
53+
}
4954
}
5055

5156
if clusterNet.Name == sdnapi.ClusterNetworkDefault && defaultClusterNetwork != nil {
52-
if clusterNet.Network != defaultClusterNetwork.Network {
53-
allErrs = append(allErrs, field.Invalid(field.NewPath("network"), clusterNet.Network, "cannot change the default ClusterNetwork record via API."))
57+
if len(clusterNet.ClusterNetworks) == len(defaultClusterNetwork.ClusterNetworks){
58+
for index := range defaultClusterNetwork.ClusterNetworks {
59+
if clusterNet.ClusterNetworks[index] != defaultClusterNetwork.ClusterNetworks[index] {
60+
allErrs = append(allErrs, field.Invalid(field.NewPath("ClusterNetworks"), clusterNet.ClusterNetworks, "cannot change the default ClusterNetwork record via API"))
61+
}
62+
}
63+
} else {
64+
allErrs = append(allErrs, field.Invalid(field.NewPath("ClusterDef"), clusterNet.ClusterNetworks, "cannot change the default ClusterNetwork record via API"))
5465
}
66+
// if clusterNet.Network != defaultClusterNetwork.Network {
67+
// allErrs = append(allErrs, field.Invalid(field.NewPath("network"), clusterNet.Network, "cannot change the default ClusterNetwork record via API."))
68+
// }
5569
if clusterNet.HostSubnetLength != defaultClusterNetwork.HostSubnetLength {
5670
allErrs = append(allErrs, field.Invalid(field.NewPath("hostSubnetLength"), clusterNet.HostSubnetLength, "cannot change the default ClusterNetwork record via API."))
5771
}

0 commit comments

Comments
 (0)