@@ -5,6 +5,7 @@ package cluster
55
66import (
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
0 commit comments