-
Notifications
You must be signed in to change notification settings - Fork 450
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
feat: check configuration #1832
Conversation
|
fdec3b2
to
cf4863c
Compare
It's done. |
75b922d
to
88a43d7
Compare
pkg/controller/config.go
Outdated
@@ -249,6 +249,10 @@ func ParseFlags() (*Configuration, error) { | |||
return nil, err | |||
} | |||
|
|||
if err := util.CIDRConflict([]string{config.NodeSwitchCIDR, config.DefaultCIDR, config.ServiceClusterIPRange}); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cidrCheck 和 conflictCheck 要拆开
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
两个功能性函数已经拆开, 并且已经根据之前的函数功能重新简化命名并使用.
pkg/util/net.go
Outdated
if err != nil { | ||
return err | ||
} | ||
if v4 != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要在 cidrconflict 里检查 cidr 是否正确。否则一个子网非法,其他正常子网都会冲突无法创建
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/util/net.go
Outdated
return nil | ||
} | ||
|
||
func ReturnCidr(address string) (*net.IPNet, *net.IPNet, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func ReturnCidr(address string) (*net.IPNet, *net.IPNet, error) { | |
func ReturnCidr(cidrBlock string) (*net.IPNet, *net.IPNet, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/util/net.go
Outdated
return nil, acidr, nil | ||
} | ||
|
||
return nil, nil, fmt.Errorf("ip %v unresolvable", address) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, nil, fmt.Errorf("ip %v unresolvable", address) | |
return nil, nil, fmt.Errorf("cidr %v unresolvable", address) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/util/net.go
Outdated
return nil, nil, fmt.Errorf("ip %v unresolvable", address) | ||
} | ||
|
||
func checkIPV4(ip *net.IPNet) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func checkIPV4(ip *net.IPNet) error { | |
func checkIPV4Cidr(cidr *net.IPNet) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/util/net.go
Outdated
return nil | ||
} | ||
|
||
func checkIPV6(ip *net.IPNet) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func checkIPV6(ip *net.IPNet) error { | |
func checkIPV6Cidr(cidr *net.IPNet) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
c09f492
to
f2252bd
Compare
- name: Setup upterm session | ||
uses: lhotari/action-upterm@v1 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deleted after debug
77a3654
to
f7b6973
Compare
pkg/util/net.go
Outdated
@@ -434,3 +428,77 @@ func GatewayContains(gatewayNodeStr, gateway string) bool { | |||
func JoinHostPort(host string, port int32) string { | |||
return net.JoinHostPort(host, strconv.FormatInt(int64(port), 10)) | |||
} | |||
|
|||
func CheckSupCIDROverlap(a, b string) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CheckSupCIDROverlap -> CIDROverlap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/util/net.go
Outdated
return false | ||
} | ||
|
||
func CheckCIDRSpec(cidr string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CheckCIDRSpec -> CIDRGlobalUnicast
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/util/net.go
Outdated
const ( | ||
IPV4Multicast = "224.0.0.0/4" | ||
IPV4Loopback = "127.0.0.1/8" | ||
IPv4bcast = "255.255.255.255/32" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IPv4Broadcast
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/util/net.go
Outdated
IPV4Multicast = "224.0.0.0/4" | ||
IPV4Loopback = "127.0.0.1/8" | ||
IPv4bcast = "255.255.255.255/32" | ||
IPv4zero = "0.0.0.0/32" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IPv4Zero
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/util/net.go
Outdated
IPv4LinkLocalUnicast = "169.254.0.0/16" | ||
|
||
IPv6unspecified = "::/128" | ||
IPv6loopback = "::1/128" | ||
IPV6Multicast = "ff00::/8" | ||
IPv6linkLocalUnicast = "FE80::/10" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the variables should use camelcase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/util/net.go
Outdated
func CheckCIDRSpec(cidr string) error { | ||
for _, cidrBlock := range strings.Split(cidr, ",") { | ||
if CheckSupCIDROverlap(cidrBlock, IPv4bcast) { | ||
return fmt.Errorf("%s conflict with v4 boardcast cidr %s", cidr, IPv4bcast) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
broadcast
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/util/net.go
Outdated
return fmt.Errorf("%s conflict with v4 localnet cidr %s", cidr, IPv4zero) | ||
} | ||
if CheckSupCIDROverlap(cidrBlock, IPv4LinkLocalUnicast) { | ||
return fmt.Errorf("%s conflict with v4 locallink cidr %s", cidr, IPv4LinkLocalUnicast) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
link local
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/util/net.go
Outdated
return fmt.Errorf("%s conflict with vv6 multicast cidr %s", cidr, IPV6Multicast) | ||
} | ||
if CheckSupCIDROverlap(cidrBlock, IPv6linkLocalUnicast) { | ||
return fmt.Errorf("%s conflict with v6 locallink cidr %s", cidr, IPv6linkLocalUnicast) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
link local
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/util/net.go
Outdated
return nil | ||
} | ||
|
||
func CheckCIDRsAll(cidrs []string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CheckCIDRsAll -> CheckSystemCIDR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/util/net.go
Outdated
if i == (lenth - 1) { | ||
break | ||
} | ||
c := i + 1 | ||
for c < lenth { | ||
if CheckSupCIDROverlap(cidr, cidrs[c]) { | ||
err := fmt.Errorf("cidr %s is conflict with cidr %s", cidr, cidrs[c]) | ||
return err | ||
} | ||
c += 1 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if i == (lenth - 1) { | |
break | |
} | |
c := i + 1 | |
for c < lenth { | |
if CheckSupCIDROverlap(cidr, cidrs[c]) { | |
err := fmt.Errorf("cidr %s is conflict with cidr %s", cidr, cidrs[c]) | |
return err | |
} | |
c += 1 | |
} | |
for j := range cidrs { | |
if j == i { | |
continue | |
} | |
if CheckSupCIDROverlap(cidr, cidrs[c]) { | |
err := fmt.Errorf("cidr %s is conflict with cidr %s", cidr, cidrs[c]) | |
return err | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed and done
pkg/util/net.go
Outdated
IPV4Multicast = "224.0.0.0/4" | ||
IPV4Loopback = "127.0.0.1/8" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
V4 -> v4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/util/net.go
Outdated
|
||
IPv6Unspecified = "::/128" | ||
IPv6Loopback = "::1/128" | ||
IPV6Multicast = "ff00::/8" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
V6 -> v6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/util/net.go
Outdated
return fmt.Errorf("%s conflict with v6 loopback cidr %s", cidr, IPv6Loopback) | ||
} | ||
if CIDROverlap(cidrBlock, IPV6Multicast) { | ||
return fmt.Errorf("%s conflict with vv6 multicast cidr %s", cidr, IPV6Multicast) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vv6 -> v6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/controller/config.go
Outdated
@@ -249,6 +249,10 @@ func ParseFlags() (*Configuration, error) { | |||
return nil, err | |||
} | |||
|
|||
if err := util.CheckSystemCIDR([]string{config.NodeSwitchCIDR, config.DefaultCIDR, config.ServiceClusterIPRange}); err != nil { | |||
return nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
klog.Errorf("check system cidr failed, %v", err)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
What type of this PR
Examples of user facing changes:
Now controller will check network CIDRs before initialization, and illegal CIDR will lead to fatal error.
Which issue(s) this PR fixes:
Fixes #1813