@@ -6,6 +6,7 @@ package nutanix
6
6
import (
7
7
"context"
8
8
"fmt"
9
+ "strings"
9
10
10
11
corev1 "k8s.io/api/core/v1"
11
12
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -56,7 +57,7 @@ func newCredentialsCheck(
56
57
credentialsCheck .result .Causes = append (credentialsCheck .result .Causes ,
57
58
preflight.Cause {
58
59
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" ,
60
61
},
61
62
)
62
63
return credentialsCheck
@@ -71,8 +72,9 @@ func newCredentialsCheck(
71
72
credentialsCheck .result .Allowed = false
72
73
credentialsCheck .result .Causes = append (credentialsCheck .result .Causes ,
73
74
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" ,
76
78
},
77
79
)
78
80
return credentialsCheck
@@ -94,7 +96,8 @@ func newCredentialsCheck(
94
96
preflight.Cause {
95
97
Message : fmt .Sprintf ("Prism Central credentials Secret %q not found" ,
96
98
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" ,
98
101
},
99
102
)
100
103
return credentialsCheck
@@ -108,7 +111,8 @@ func newCredentialsCheck(
108
111
prismCentralEndpointSpec .Credentials .SecretRef .Name ,
109
112
err ,
110
113
),
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" ,
112
116
},
113
117
)
114
118
return credentialsCheck
@@ -119,10 +123,11 @@ func newCredentialsCheck(
119
123
credentialsCheck .result .Causes = append (credentialsCheck .result .Causes ,
120
124
preflight.Cause {
121
125
Message : fmt .Sprintf (
122
- "credentials Secret %q is empty" ,
126
+ "Credentials Secret %q is empty" ,
123
127
prismCentralEndpointSpec .Credentials .SecretRef .Name ,
124
128
),
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" ,
126
131
},
127
132
)
128
133
return credentialsCheck
@@ -134,11 +139,12 @@ func newCredentialsCheck(
134
139
credentialsCheck .result .Causes = append (credentialsCheck .result .Causes ,
135
140
preflight.Cause {
136
141
Message : fmt .Sprintf (
137
- "credentials Secret %q does not contain key %q" ,
142
+ "Credentials Secret %q does not contain key %q" ,
138
143
prismCentralEndpointSpec .Credentials .SecretRef .Name ,
139
144
credentialsSecretDataKey ,
140
145
),
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" ,
142
148
},
143
149
)
144
150
return credentialsCheck
@@ -149,8 +155,9 @@ func newCredentialsCheck(
149
155
credentialsCheck .result .Allowed = false
150
156
credentialsCheck .result .Causes = append (credentialsCheck .result .Causes ,
151
157
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" ,
154
161
},
155
162
)
156
163
return credentialsCheck
@@ -173,29 +180,40 @@ func newCredentialsCheck(
173
180
credentialsCheck .result .Causes = append (credentialsCheck .result .Causes ,
174
181
preflight.Cause {
175
182
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" ,
177
185
},
178
186
)
179
187
return credentialsCheck
180
188
}
181
189
182
190
// Validate the credentials using an API call.
183
191
_ , 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" ) {
185
199
credentialsCheck .result .Allowed = false
186
- credentialsCheck .result .InternalError = true
187
200
credentialsCheck .result .Causes = append (credentialsCheck .result .Causes ,
188
201
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 " ,
192
205
},
193
206
)
194
207
return credentialsCheck
195
208
}
196
209
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
+ )
200
218
return credentialsCheck
201
219
}
0 commit comments