Skip to content
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

Merged
merged 1 commit into from
Aug 31, 2022
Merged

feat: check configuration #1832

merged 1 commit into from
Aug 31, 2022

Conversation

lut777
Copy link
Contributor

@lut777 lut777 commented Aug 21, 2022

What type of this PR

Examples of user facing changes:

  • Features

Now controller will check network CIDRs before initialization, and illegal CIDR will lead to fatal error.

Which issue(s) this PR fixes:

Fixes #1813

@oilbeater
Copy link
Collaborator

util/validator.go has similar logical and should reuse it.

@lut777 lut777 force-pushed the master branch 2 times, most recently from fdec3b2 to cf4863c Compare August 23, 2022 04:04
@lut777
Copy link
Contributor Author

lut777 commented Aug 23, 2022

util/validator.go has similar logical and should reuse it.

It's done.

@lut777 lut777 force-pushed the master branch 2 times, most recently from 75b922d to 88a43d7 Compare August 23, 2022 12:16
@@ -249,6 +249,10 @@ func ParseFlags() (*Configuration, error) {
return nil, err
}

if err := util.CIDRConflict([]string{config.NodeSwitchCIDR, config.DefaultCIDR, config.ServiceClusterIPRange}); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cidrCheck 和 conflictCheck 要拆开

Copy link
Contributor Author

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要在 cidrconflict 里检查 cidr 是否正确。否则一个子网非法,其他正常子网都会冲突无法创建

Copy link
Contributor Author

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func ReturnCidr(address string) (*net.IPNet, *net.IPNet, error) {
func ReturnCidr(cidrBlock string) (*net.IPNet, *net.IPNet, error) {

Copy link
Contributor Author

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, nil, fmt.Errorf("ip %v unresolvable", address)
return nil, nil, fmt.Errorf("cidr %v unresolvable", address)

Copy link
Contributor Author

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func checkIPV4(ip *net.IPNet) error {
func checkIPV4Cidr(cidr *net.IPNet) error {

Copy link
Contributor Author

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func checkIPV6(ip *net.IPNet) error {
func checkIPV6Cidr(cidr *net.IPNet) error {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@lut777 lut777 force-pushed the master branch 4 times, most recently from c09f492 to f2252bd Compare August 30, 2022 06:56
Comment on lines 618 to 620
- name: Setup upterm session
uses: lhotari/action-upterm@v1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted after debug

@lut777 lut777 force-pushed the master branch 5 times, most recently from 77a3654 to f7b6973 Compare August 30, 2022 10:46
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckSupCIDROverlap -> CIDROverlap

Copy link
Contributor Author

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckCIDRSpec -> CIDRGlobalUnicast

Copy link
Contributor Author

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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IPv4Broadcast

Copy link
Contributor Author

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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IPv4Zero

Copy link
Contributor Author

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
Comment on lines 23 to 28
IPv4LinkLocalUnicast = "169.254.0.0/16"

IPv6unspecified = "::/128"
IPv6loopback = "::1/128"
IPV6Multicast = "ff00::/8"
IPv6linkLocalUnicast = "FE80::/10"
Copy link
Collaborator

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

Copy link
Contributor Author

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

broadcast

Copy link
Contributor Author

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

link local

Copy link
Contributor Author

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

link local

Copy link
Contributor Author

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckCIDRsAll -> CheckSystemCIDR

Copy link
Contributor Author

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
Comment on lines 491 to 498
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
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
}
}

Copy link
Contributor Author

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
Comment on lines 19 to 20
IPV4Multicast = "224.0.0.0/4"
IPV4Loopback = "127.0.0.1/8"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

V4 -> v4

Copy link
Contributor Author

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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

V6 -> v6

Copy link
Contributor Author

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vv6 -> v6

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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
Copy link
Collaborator

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@lut777 lut777 merged commit dedd5aa into kubeovn:master Aug 31, 2022
lut777 added a commit that referenced this pull request Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kube-ovn-controller should exit if default/join subnets use linklocal or muticast cidr
3 participants