@@ -6,6 +6,7 @@ package nutanix
66import (
77 "context"
88 "fmt"
9+ "strings"
910
1011 corev1 "k8s.io/api/core/v1"
1112 apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -181,21 +182,30 @@ func newCredentialsCheck(
181182
182183 // Validate the credentials using an API call.
183184 _ , err = nclient .GetCurrentLoggedInUser (ctx )
184- if err != nil {
185+ if err == nil {
186+ // We initialized both clients, and verified the credentials using the v3 client.
187+ cd .nclient = nclient
188+ return credentialsCheck
189+ }
190+
191+ if strings .Contains (err .Error (), "invalid Nutanix credentials" ) {
185192 credentialsCheck .result .Allowed = false
186- credentialsCheck .result .InternalError = true
187193 credentialsCheck .result .Causes = append (credentialsCheck .result .Causes ,
188194 preflight.Cause {
189- Message : fmt .Sprintf ("Failed to validate credentials using the v3 API client. " +
190- "The URL and/or credentials may be incorrect. (Error: %q)" , err ),
191- Field :
"$.spec.topology.variables[[email protected] ==\" clusterConfig\" ].value.nutanix.prismCentralEndpoint" ,
195+ Message : fmt .Sprintf ("Failed to validate credentials using the v3 API client: %s" , err ),
196+ Field :
"$.spec.topology.variables[[email protected] ==\" clusterConfig\" ].value.nutanix.prismCentralEndpoint.credentials.secretRef" ,
192197 },
193198 )
194199 return credentialsCheck
195200 }
196201
197- // We initialized both clients, and verified the credentials using the v3 client.
198- cd .nclient = nclient
199-
202+ credentialsCheck .result .Allowed = false
203+ credentialsCheck .result .InternalError = true
204+ credentialsCheck .result .Causes = append (credentialsCheck .result .Causes ,
205+ preflight.Cause {
206+ Message : fmt .Sprintf ("Failed to validate credentials using the v3 API client: %s" , err ),
207+ Field :
"$.spec.topology.variables[[email protected] ==\" clusterConfig\" ].value.nutanix.prismCentralEndpoint" ,
208+ },
209+ )
200210 return credentialsCheck
201211}
0 commit comments