Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
adiantum committed Dec 19, 2024
1 parent 43fc362 commit 71426fb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 77 deletions.
35 changes: 3 additions & 32 deletions pkg/providers/nutanix/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"log"
"net"
"strings"

Expand Down Expand Up @@ -602,12 +601,7 @@ func compareIP(ip1, ip2 net.IP) (int, error) {
}

func addCIDRToIgnoredNodeIPsList(cidr string, result []string) []string {
ip, ipNet, err := net.ParseCIDR(cidr)
if err != nil {
// log error and continue
log.Printf("error parsing CIDR %s: %v", cidr, err)
return result
}
ip, ipNet, _ := net.ParseCIDR(cidr)

// Add all ip addresses in the range to the list
for ip := ip.Mask(ipNet.Mask); ipNet.Contains(ip); incrementIP(ip) {
Expand All @@ -622,28 +616,12 @@ func addCIDRToIgnoredNodeIPsList(cidr string, result []string) []string {
func addIPRangeToIgnoredNodeIPsList(ipRangeStr string, result []string) []string {
// Parse the range
ipRange := strings.Split(ipRangeStr, "-")
if len(ipRange) != 2 {
// log error and return
log.Printf("error parsing range %s: expected 2 values, got %d", ipRangeStr, len(ipRange))
return result
}

// Parse the start and end of the range
start := net.ParseIP(strings.TrimSpace(ipRange[0]))
end := net.ParseIP(strings.TrimSpace(ipRange[1]))
if start == nil || end == nil {
// log error and return
log.Printf("error parsing range %s: invalid IP address", ipRangeStr)
return result
}

cmp, err := compareIP(start, end)
if err != nil {
// log error and return
log.Printf("error comparing IP addresses %s and %s: %v", start.String(), end.String(), err)
return result
}

cmp, _ := compareIP(start, end)
if cmp >= 0 {
// swap start and end if start is greater than end
start, end = end, start
Expand All @@ -660,14 +638,7 @@ func addIPRangeToIgnoredNodeIPsList(ipRangeStr string, result []string) []string
}

func addIPAddressToIgnoredNodeIPsList(ipAddrStr string, result []string) []string {
ip := net.ParseIP(ipAddrStr)
if ip == nil {
// log error and return
log.Printf("error parsing IP address %s", ipAddrStr)
return result
}

result = append(result, ip.String())
result = append(result, ipAddrStr)
return result
}

Expand Down
45 changes: 0 additions & 45 deletions pkg/providers/nutanix/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,51 +865,6 @@ func TestTemplateBuilderCcmExcludeNodeIPs(t *testing.T) {
}
clusterSpec.NutanixDatacenter.Spec.CcmExcludeNodeIPs = excludeNodeIPs

return clusterSpec
},
},
{
Input: "testdata/eksa-cluster-ccm-exclude-node-ips.yaml",
Output: "testdata/expected_cluster_ccm_exclude_node_ips.yaml",
ChangeFn: func(clusterSpec *cluster.Spec) *cluster.Spec {
excludeNodeIPs := []string{
"127.100.200.101",
"10.10.10.10-10.10.10.13",
"10.123.0.0/29",
"10.10.10.20-10.10.10.30-10.10.20.30",
}
clusterSpec.NutanixDatacenter.Spec.CcmExcludeNodeIPs = excludeNodeIPs

return clusterSpec
},
},
{
Input: "testdata/eksa-cluster-ccm-exclude-node-ips.yaml",
Output: "testdata/expected_cluster_ccm_exclude_node_ips.yaml",
ChangeFn: func(clusterSpec *cluster.Spec) *cluster.Spec {
excludeNodeIPs := []string{
"127.100.200.101",
"10.10.10.10-10.10.10.13",
"10.123.0.0/29",
"244.244.1",
}
clusterSpec.NutanixDatacenter.Spec.CcmExcludeNodeIPs = excludeNodeIPs

return clusterSpec
},
},
{
Input: "testdata/eksa-cluster-ccm-exclude-node-ips.yaml",
Output: "testdata/expected_cluster_ccm_exclude_node_ips.yaml",
ChangeFn: func(clusterSpec *cluster.Spec) *cluster.Spec {
excludeNodeIPs := []string{
"127.100.200.101",
"10.10.10.10-10.10.10.13",
"10.123.0.0/29",
"10.21.0.5/55",
}
clusterSpec.NutanixDatacenter.Spec.CcmExcludeNodeIPs = excludeNodeIPs

return clusterSpec
},
},
Expand Down

0 comments on commit 71426fb

Please sign in to comment.