@@ -5,6 +5,7 @@ package cluster
5
5
6
6
import (
7
7
"context"
8
+ "errors"
8
9
"fmt"
9
10
"net"
10
11
"net/http"
@@ -72,7 +73,7 @@ func (a *nutanixValidator) validate(
72
73
if clusterConfig .Nutanix != nil &&
73
74
clusterConfig .Addons != nil {
74
75
// Check if Prism Central IP is in MetalLB Load Balancer IP range.
75
- if err := checkIfPrismCentralIPInLoadBalancerIPRange (
76
+ if err := validatePrismCentralIPNotInLoadBalancerIPRange (
76
77
clusterConfig .Nutanix .PrismCentralEndpoint ,
77
78
clusterConfig .Addons .ServiceLoadBalancer ,
78
79
); err != nil {
@@ -83,9 +84,9 @@ func (a *nutanixValidator) validate(
83
84
return admission .Allowed ("" )
84
85
}
85
86
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 (
89
90
pcEndpoint v1alpha1.NutanixPrismCentralEndpointSpec ,
90
91
serviceLoadBalancerConfiguration * v1alpha1.ServiceLoadBalancer ,
91
92
) error {
@@ -110,16 +111,21 @@ func checkIfPrismCentralIPInLoadBalancerIPRange(
110
111
isIPInRange , err := helpers .IsIPInRange (pool .Start , pool .End , pcIP .String ())
111
112
if err != nil {
112
113
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" ,
114
115
pcIP ,
115
116
pool .Start ,
116
117
pool .End ,
117
118
err ,
118
119
)
119
120
}
120
121
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 )
123
129
}
124
130
}
125
131
0 commit comments