@@ -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"
@@ -56,7 +57,7 @@ func newCredentialsCheck(
5657 credentialsCheck .result .Causes = append (credentialsCheck .result .Causes ,
5758 preflight.Cause {
5859 Message : "Nutanix cluster configuration is not defined in the cluster spec" ,
59- Field : "cluster .spec.topology.variables[.name=clusterConfig] .nutanix" ,
60+ Field : "$ .spec.topology.variables[?@ .name== \" clusterConfig\" ].value .nutanix" ,
6061 },
6162 )
6263 return credentialsCheck
@@ -71,8 +72,9 @@ func newCredentialsCheck(
7172 credentialsCheck .result .Allowed = false
7273 credentialsCheck .result .Causes = append (credentialsCheck .result .Causes ,
7374 preflight.Cause {
74- Message : fmt .Sprintf ("failed to parse Prism Central endpoint URL: %s" , err ),
75- Field : "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint.url" ,
75+ Message : fmt .Sprintf ("Failed to parse Prism Central endpoint URL: %s" , err ),
76+ Field :
"$.spec.topology.variables[[email protected] ==\" clusterConfig\" ]" + 77+ ".value.nutanix.prismCentralEndpoint.url" ,
7678 },
7779 )
7880 return credentialsCheck
@@ -94,7 +96,8 @@ func newCredentialsCheck(
9496 preflight.Cause {
9597 Message : fmt .Sprintf ("Prism Central credentials Secret %q not found" ,
9698 prismCentralEndpointSpec .Credentials .SecretRef .Name ),
97- Field : "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint.credentials.secretRef" ,
99+ Field :
"$.spec.topology.variables[[email protected] ==\" clusterConfig\" ]" + 100+ ".value.nutanix.prismCentralEndpoint.credentials.secretRef" ,
98101 },
99102 )
100103 return credentialsCheck
@@ -108,7 +111,8 @@ func newCredentialsCheck(
108111 prismCentralEndpointSpec .Credentials .SecretRef .Name ,
109112 err ,
110113 ),
111- Field : "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint.credentials.secretRef" ,
114+ Field :
"$.spec.topology.variables[[email protected] ==\" clusterConfig\" ]" + 115+ ".value.nutanix.prismCentralEndpoint.credentials.secretRef" ,
112116 },
113117 )
114118 return credentialsCheck
@@ -119,10 +123,11 @@ func newCredentialsCheck(
119123 credentialsCheck .result .Causes = append (credentialsCheck .result .Causes ,
120124 preflight.Cause {
121125 Message : fmt .Sprintf (
122- "credentials Secret %q is empty" ,
126+ "Credentials Secret %q is empty" ,
123127 prismCentralEndpointSpec .Credentials .SecretRef .Name ,
124128 ),
125- Field : "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint.credentials.secretRef" ,
129+ Field :
"$.spec.topology.variables[[email protected] ==\" clusterConfig\" ]" + 130+ ".value.nutanix.prismCentralEndpoint.credentials.secretRef" ,
126131 },
127132 )
128133 return credentialsCheck
@@ -134,11 +139,12 @@ func newCredentialsCheck(
134139 credentialsCheck .result .Causes = append (credentialsCheck .result .Causes ,
135140 preflight.Cause {
136141 Message : fmt .Sprintf (
137- "credentials Secret %q does not contain key %q" ,
142+ "Credentials Secret %q does not contain key %q" ,
138143 prismCentralEndpointSpec .Credentials .SecretRef .Name ,
139144 credentialsSecretDataKey ,
140145 ),
141- Field : "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint.credentials.secretRef" ,
146+ Field :
"$.spec.topology.variables[[email protected] ==\" clusterConfig\" ]" + 147+ ".value.nutanix.prismCentralEndpoint.credentials.secretRef" ,
142148 },
143149 )
144150 return credentialsCheck
@@ -149,8 +155,9 @@ func newCredentialsCheck(
149155 credentialsCheck .result .Allowed = false
150156 credentialsCheck .result .Causes = append (credentialsCheck .result .Causes ,
151157 preflight.Cause {
152- Message : fmt .Sprintf ("failed to parse Prism Central credentials: %s" , err ),
153- Field : "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint.credentials" ,
158+ Message : fmt .Sprintf ("Failed to parse Prism Central credentials: %s" , err ),
159+ Field :
"$.spec.topology.variables[[email protected] ==\" clusterConfig\" ]" + 160+ ".value.nutanix.prismCentralEndpoint.credentials.secretRef" ,
154161 },
155162 )
156163 return credentialsCheck
@@ -173,29 +180,40 @@ func newCredentialsCheck(
173180 credentialsCheck .result .Causes = append (credentialsCheck .result .Causes ,
174181 preflight.Cause {
175182 Message : fmt .Sprintf ("Failed to initialize Nutanix client: %s" , err ),
176- Field : "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint.credentials" ,
183+ Field :
"$.spec.topology.variables[[email protected] ==\" clusterConfig\" ]" + 184+ ".value.nutanix.prismCentralEndpoint.credentials.secretRef" ,
177185 },
178186 )
179187 return credentialsCheck
180188 }
181189
182190 // Validate the credentials using an API call.
183191 _ , err = nclient .GetCurrentLoggedInUser (ctx )
184- if err != nil {
192+ if err == nil {
193+ // We initialized both clients, and verified the credentials using the v3 client.
194+ cd .nclient = nclient
195+ return credentialsCheck
196+ }
197+
198+ if strings .Contains (err .Error (), "invalid Nutanix credentials" ) {
185199 credentialsCheck .result .Allowed = false
186- credentialsCheck .result .InternalError = true
187200 credentialsCheck .result .Causes = append (credentialsCheck .result .Causes ,
188201 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 : "cluster.spec.topology.variables[.name=clusterConfig]. nutanix.prismCentralEndpoint" ,
202+ Message : fmt .Sprintf ("Failed to validate credentials using the v3 API client: %s" , err ),
203+ Field : "$.spec.topology.variables[[email protected] == \" clusterConfig \" ]" + 204+ ".value. nutanix.prismCentralEndpoint.credentials.secretRef " ,
192205 },
193206 )
194207 return credentialsCheck
195208 }
196209
197- // We initialized both clients, and verified the credentials using the v3 client.
198- cd .nclient = nclient
199-
210+ credentialsCheck .result .Allowed = false
211+ credentialsCheck .result .InternalError = true
212+ credentialsCheck .result .Causes = append (credentialsCheck .result .Causes ,
213+ preflight.Cause {
214+ Message : fmt .Sprintf ("Failed to validate credentials using the v3 API client: %s" , err ),
215+ Field :
"$.spec.topology.variables[[email protected] ==\" clusterConfig\" ].value.nutanix.prismCentralEndpoint" ,
216+ },
217+ )
200218 return credentialsCheck
201219}
0 commit comments