mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
Improve the error message for the service cidr check
This commit is contained in:
parent
b19de7f9b6
commit
889648d6e5
@ -36,6 +36,8 @@ import (
|
|||||||
// validateClusterIPFlags is expected to be called after Complete()
|
// validateClusterIPFlags is expected to be called after Complete()
|
||||||
func validateClusterIPFlags(options *ServerRunOptions) []error {
|
func validateClusterIPFlags(options *ServerRunOptions) []error {
|
||||||
var errs []error
|
var errs []error
|
||||||
|
// maxCIDRbits is used to define the maximum CIDR size for the cluster ip(s)
|
||||||
|
const maxCIDRbits = 20
|
||||||
|
|
||||||
// validate that primary has been processed by user provided values or it has been defaulted
|
// validate that primary has been processed by user provided values or it has been defaulted
|
||||||
if options.PrimaryServiceClusterIPRange.IP == nil {
|
if options.PrimaryServiceClusterIPRange.IP == nil {
|
||||||
@ -50,8 +52,8 @@ func validateClusterIPFlags(options *ServerRunOptions) []error {
|
|||||||
// Complete() expected to have set Primary* and Secondary*
|
// Complete() expected to have set Primary* and Secondary*
|
||||||
// primary CIDR validation
|
// primary CIDR validation
|
||||||
var ones, bits = options.PrimaryServiceClusterIPRange.Mask.Size()
|
var ones, bits = options.PrimaryServiceClusterIPRange.Mask.Size()
|
||||||
if bits-ones > 20 {
|
if bits-ones > maxCIDRbits {
|
||||||
errs = append(errs, errors.New("specified --service-cluster-ip-range is too large"))
|
errs = append(errs, fmt.Errorf("specified --service-cluster-ip-range is too large. Network CIDR should not be bigger than /%d", bits-maxCIDRbits))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Secondary IP validation
|
// Secondary IP validation
|
||||||
@ -79,8 +81,8 @@ func validateClusterIPFlags(options *ServerRunOptions) []error {
|
|||||||
// bigger cidr (specially those offered by IPv6) will add no value
|
// bigger cidr (specially those offered by IPv6) will add no value
|
||||||
// significantly increase snapshotting time.
|
// significantly increase snapshotting time.
|
||||||
var ones, bits = options.SecondaryServiceClusterIPRange.Mask.Size()
|
var ones, bits = options.SecondaryServiceClusterIPRange.Mask.Size()
|
||||||
if bits-ones > 20 {
|
if bits-ones > maxCIDRbits {
|
||||||
errs = append(errs, errors.New("specified --secondary-service-cluster-ip-range is too large"))
|
errs = append(errs, fmt.Errorf("specified --service-cluster-ip-range is too large. Network CIDR should not be bigger than /%d", bits-maxCIDRbits))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +95,18 @@ func TestClusterSerivceIPRange(t *testing.T) {
|
|||||||
options: makeOptionsWithCIDRs("10.0.0.0/16", "3000::/108"),
|
options: makeOptionsWithCIDRs("10.0.0.0/16", "3000::/108"),
|
||||||
enableDualStack: false,
|
enableDualStack: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "service cidr to big",
|
||||||
|
expectErrors: true,
|
||||||
|
options: makeOptionsWithCIDRs("10.0.0.0/8", ""),
|
||||||
|
enableDualStack: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "dual-stack secondary cidr to big",
|
||||||
|
expectErrors: true,
|
||||||
|
options: makeOptionsWithCIDRs("10.0.0.0/16", "3000::/64"),
|
||||||
|
enableDualStack: true,
|
||||||
|
},
|
||||||
/* success cases */
|
/* success cases */
|
||||||
{
|
{
|
||||||
name: "valid primary",
|
name: "valid primary",
|
||||||
|
Loading…
Reference in New Issue
Block a user