Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
eaudetcobello committed Sep 30, 2024
1 parent fd5e39d commit 1a87bcb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/k8s/pkg/k8sd/app/hooks_bootstrap_test.go

This file was deleted.

7 changes: 3 additions & 4 deletions src/k8s/pkg/k8sd/types/cluster_config_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func validateCIDRs(cidrString string) error {
return nil
}

// validateCIDROverlapAndSize checks for overlap and size constraints between pod and service CIDRs.
// validateCIDROverlap checks for overlap and size constraints between pod and service CIDRs.
// It parses the provided podCIDR and serviceCIDR strings, checks for IPv4 and IPv6 overlaps.
func validateCIDROverlap(podCIDR string, serviceCIDR string) error {
// Parse the CIDRs
Expand Down Expand Up @@ -58,7 +58,7 @@ func validateCIDROverlap(podCIDR string, serviceCIDR string) error {
return nil
}

// Check CIDR size ensures that the service IPv6 CIDR is not larger than /108.
// validateIPv6CIDRSize ensures that the service IPv6 CIDR is not larger than /108.
// Ref: https://documentation.ubuntu.com/canonical-kubernetes/latest/snap/howto/networking/dualstack/#cidr-size-limitations
func validateIPv6CIDRSize(serviceCIDR string) error {
_, svcIPv6CIDR, err := utils.SplitCIDRStrings(serviceCIDR)
Expand All @@ -75,8 +75,7 @@ func validateIPv6CIDRSize(serviceCIDR string) error {
return fmt.Errorf("invalid CIDR: %w", err)
}

prefixLength, _ := ipv6Net.Mask.Size()
if prefixLength < 108 {
if prefixLength, _ := ipv6Net.Mask.Size(); prefixLength < 108 {
return fmt.Errorf("service CIDR %q cannot be larger than /108", serviceCIDR)
}

Expand Down
8 changes: 6 additions & 2 deletions src/k8s/pkg/utils/cidr.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,12 @@ func CIDRsOverlap(cidr1, cidr2 string) (bool, error) {
_, ipNet1, err1 := net.ParseCIDR(cidr1)
_, ipNet2, err2 := net.ParseCIDR(cidr2)

if err1 != nil || err2 != nil {
return false, fmt.Errorf("invalid CIDR blocks, %v, %v", err1, err2)
if err1 != nil {
return false, fmt.Errorf("couldn't parse CIDR block %q: %w", cidr1, err1)
}

if err2 != nil {
return false, fmt.Errorf("couldn't parse CIDR block %q: %w", cidr2, err2)
}

if ipNet1.Contains(ipNet2.IP) || ipNet2.Contains(ipNet1.IP) {
Expand Down

0 comments on commit 1a87bcb

Please sign in to comment.