@@ -36,8 +36,8 @@ import (
36
36
// validateClusterIPFlags is expected to be called after Complete()
37
37
func validateClusterIPFlags (options * ServerRunOptions ) []error {
38
38
var errs []error
39
- // maxCIDRbits is used to define the maximum CIDR size for the cluster ip(s)
40
- const maxCIDRbits = 20
39
+ // maxCIDRBits is used to define the maximum CIDR size for the cluster ip(s)
40
+ const maxCIDRBits = 20
41
41
42
42
// validate that primary has been processed by user provided values or it has been defaulted
43
43
if options .PrimaryServiceClusterIPRange .IP == nil {
@@ -51,9 +51,8 @@ func validateClusterIPFlags(options *ServerRunOptions) []error {
51
51
52
52
// Complete() expected to have set Primary* and Secondary*
53
53
// primary CIDR validation
54
- var ones , bits = options .PrimaryServiceClusterIPRange .Mask .Size ()
55
- if bits - ones > maxCIDRbits {
56
- errs = append (errs , fmt .Errorf ("specified --service-cluster-ip-range is too large. Network CIDR should not be bigger than /%d" , bits - maxCIDRbits ))
54
+ if err := validateMaxCIDRRange (options .PrimaryServiceClusterIPRange , maxCIDRBits , "--service-cluster-ip-range" ); err != nil {
55
+ errs = append (errs , err )
57
56
}
58
57
59
58
// Secondary IP validation
@@ -77,18 +76,26 @@ func validateClusterIPFlags(options *ServerRunOptions) []error {
77
76
errs = append (errs , errors .New ("--service-cluster-ip-range and --secondary-service-cluster-ip-range must be of different IP family" ))
78
77
}
79
78
80
- // Should be smallish sized cidr, this thing is kept in etcd
81
- // bigger cidr (specially those offered by IPv6) will add no value
82
- // significantly increase snapshotting time.
83
- var ones , bits = options .SecondaryServiceClusterIPRange .Mask .Size ()
84
- if bits - ones > maxCIDRbits {
85
- errs = append (errs , fmt .Errorf ("specified --service-cluster-ip-range is too large. Network CIDR should not be bigger than /%d" , bits - maxCIDRbits ))
79
+ if err := validateMaxCIDRRange (options .SecondaryServiceClusterIPRange , maxCIDRBits , "--secondary-service-cluster-ip-range" ); err != nil {
80
+ errs = append (errs , err )
86
81
}
87
82
}
88
83
89
84
return errs
90
85
}
91
86
87
+ func validateMaxCIDRRange (cidr net.IPNet , maxCIDRBits int , cidrFlag string ) error {
88
+ // Should be smallish sized cidr, this thing is kept in etcd
89
+ // bigger cidr (specially those offered by IPv6) will add no value
90
+ // significantly increase snapshotting time.
91
+ var ones , bits = cidr .Mask .Size ()
92
+ if bits - ones > maxCIDRBits {
93
+ return fmt .Errorf ("specified %s is too large; for %d-bit addresses, the mask must be >= %d" , cidrFlag , bits , bits - maxCIDRBits )
94
+ }
95
+
96
+ return nil
97
+ }
98
+
92
99
func validateServiceNodePort (options * ServerRunOptions ) []error {
93
100
var errs []error
94
101
0 commit comments