From 71426fbde62c8312f6ee53d01a5952ceab76a9b1 Mon Sep 17 00:00:00 2001 From: Ilya Alekseyev Date: Thu, 19 Dec 2024 16:00:56 +0000 Subject: [PATCH] Fix comments --- pkg/providers/nutanix/template.go | 35 ++------------------ pkg/providers/nutanix/template_test.go | 45 -------------------------- 2 files changed, 3 insertions(+), 77 deletions(-) diff --git a/pkg/providers/nutanix/template.go b/pkg/providers/nutanix/template.go index ccf718be14e5..240b8472f952 100644 --- a/pkg/providers/nutanix/template.go +++ b/pkg/providers/nutanix/template.go @@ -4,7 +4,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "log" "net" "strings" @@ -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) { @@ -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 @@ -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 } diff --git a/pkg/providers/nutanix/template_test.go b/pkg/providers/nutanix/template_test.go index d0111be0c274..06b9265e701e 100644 --- a/pkg/providers/nutanix/template_test.go +++ b/pkg/providers/nutanix/template_test.go @@ -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 }, },