Skip to content

Commit ce6738a

Browse files
committed
refactor: renames func and error messages
1 parent b519340 commit ce6738a

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

pkg/webhook/cluster/nutanix_validator.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package cluster
55

66
import (
77
"context"
8+
"errors"
89
"fmt"
910
"net"
1011
"net/http"
@@ -72,7 +73,7 @@ func (a *nutanixValidator) validate(
7273
if clusterConfig.Nutanix != nil &&
7374
clusterConfig.Addons != nil {
7475
// Check if Prism Central IP is in MetalLB Load Balancer IP range.
75-
if err := checkIfPrismCentralIPInLoadBalancerIPRange(
76+
if err := validatePrismCentralIPNotInLoadBalancerIPRange(
7677
clusterConfig.Nutanix.PrismCentralEndpoint,
7778
clusterConfig.Addons.ServiceLoadBalancer,
7879
); err != nil {
@@ -83,9 +84,9 @@ func (a *nutanixValidator) validate(
8384
return admission.Allowed("")
8485
}
8586

86-
// checkIfPrismCentralIPInLoadBalancerIPRange checks if the Prism Central IP is in the MetalLB Load Balancer IP range.
87-
// Errors out if Prism Central IP is in the Load Balancer IP range.
88-
func checkIfPrismCentralIPInLoadBalancerIPRange(
87+
// validatePrismCentralIPNotInLoadBalancerIPRange checks if the Prism Central IP is not
88+
// in the MetalLB Load Balancer IP range and error out if it is.
89+
func validatePrismCentralIPNotInLoadBalancerIPRange(
8990
pcEndpoint v1alpha1.NutanixPrismCentralEndpointSpec,
9091
serviceLoadBalancerConfiguration *v1alpha1.ServiceLoadBalancer,
9192
) error {
@@ -110,16 +111,21 @@ func checkIfPrismCentralIPInLoadBalancerIPRange(
110111
isIPInRange, err := helpers.IsIPInRange(pool.Start, pool.End, pcIP.String())
111112
if err != nil {
112113
return fmt.Errorf(
113-
"error while checking if Prism Central IP %q is part of MetalLB address range %q-%q: %w",
114+
"failed to check if Prism Central IP %q is part of MetalLB address range %q-%q: %w",
114115
pcIP,
115116
pool.Start,
116117
pool.End,
117118
err,
118119
)
119120
}
120121
if isIPInRange {
121-
return fmt.Errorf("prism central IP %q must not be part of MetalLB address range %q-%q",
122-
pcIP, pool.Start, pool.End)
122+
errMsg := fmt.Sprintf(
123+
"Prism Central IP %q must not be part of MetalLB address range %q-%q",
124+
pcIP,
125+
pool.Start,
126+
pool.End,
127+
)
128+
return errors.New(errMsg)
123129
}
124130
}
125131

pkg/webhook/cluster/nutanix_validator_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
1313
)
1414

15-
func TestCheckIfPrismCentralIPInLoadBalancerIPRange(t *testing.T) {
15+
func TestValidatePrismCentralIPNotInLoadBalancerIPRange(t *testing.T) {
1616
tests := []struct {
1717
name string
1818
pcEndpoint v1alpha1.NutanixPrismCentralEndpointSpec
@@ -48,7 +48,7 @@ func TestCheckIfPrismCentralIPInLoadBalancerIPRange(t *testing.T) {
4848
},
4949
},
5050
expectedErr: fmt.Errorf(
51-
"prism central IP %q must not be part of MetalLB address range %q-%q",
51+
"Prism Central IP %q must not be part of MetalLB address range %q-%q",
5252
"192.168.1.15",
5353
"192.168.1.10",
5454
"192.168.1.20",
@@ -99,7 +99,7 @@ func TestCheckIfPrismCentralIPInLoadBalancerIPRange(t *testing.T) {
9999

100100
for _, tt := range tests {
101101
t.Run(tt.name, func(t *testing.T) {
102-
err := checkIfPrismCentralIPInLoadBalancerIPRange(
102+
err := validatePrismCentralIPNotInLoadBalancerIPRange(
103103
tt.pcEndpoint,
104104
tt.serviceLoadBalancerConfiguration,
105105
)

0 commit comments

Comments
 (0)