Skip to content

Commit d69c324

Browse files
authored
fix: Use JSONPath in check result fields (#1221)
**What problem does this PR solve?**: Some fields were still not using valid JSONPath. I already fixed the other fields earlier in #1202. **Which issue(s) this PR fixes**: Fixes # **How Has This Been Tested?**: <!-- Please describe the tests that you ran to verify your changes. Provide output from the tests and any manual steps needed to replicate the tests. --> **Special notes for your reviewer**: <!-- Use this to provide any additional information to the reviewers. This may include: - Best way to review the PR. - Where the author wants the most review attention on. - etc. -->
1 parent c145c99 commit d69c324

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

pkg/webhook/preflight/generic/registry.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func newRegistryCheck(
201201
if cd.genericClusterConfigSpec != nil &&
202202
cd.genericClusterConfigSpec.GlobalImageRegistryMirror != nil {
203203
checks = append(checks, &registryCheck{
204-
field: "cluster.spec.topology.variables[.name=clusterConfig].value.globalImageRegistryMirror",
204+
field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.globalImageRegistryMirror",
205205
kclient: cd.kclient,
206206
cluster: cd.cluster,
207207
regClientPingerGetter: defaultRegClientGetter,
@@ -215,7 +215,7 @@ func newRegistryCheck(
215215
registry := cd.genericClusterConfigSpec.ImageRegistries[i]
216216
checks = append(checks, &registryCheck{
217217
field: fmt.Sprintf(
218-
"cluster.spec.topology.variables[.name=clusterConfig].value.imageRegistries[%d]",
218+
"$.spec.topology.variables[?@.name==\"clusterConfig\"].value.imageRegistries[%d]",
219219
i,
220220
),
221221
kclient: cd.kclient,

pkg/webhook/preflight/generic/registry_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func TestRegistryCheck(t *testing.T) {
112112
},
113113
{
114114
name: "registry mirror with invalid credentials secret",
115-
field: "cluster.spec.topology.variables[.name=clusterConfig].value.globalImageRegistryMirror",
115+
field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.globalImageRegistryMirror",
116116
registryMirror: &carenv1.GlobalImageRegistryMirror{
117117
URL: testRegistryURL,
118118
Credentials: &carenv1.RegistryCredentials{
@@ -136,14 +136,14 @@ func TestRegistryCheck(t *testing.T) {
136136
Causes: []preflight.Cause{
137137
{
138138
Message: "Failed to get Registry credentials Secret \"test-secret\": fake error. This is usually a temporary error. Please retry.", ///nolint:lll // Message is long.
139-
Field: "cluster.spec.topology.variables[.name=clusterConfig].value.globalImageRegistryMirror.credentials.secretRef", //nolint:lll // Field is long.
139+
Field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.globalImageRegistryMirror.credentials.secretRef", //nolint:lll // Field is long.
140140
},
141141
},
142142
},
143143
},
144144
{
145145
name: "registry mirror with missing credentials secret",
146-
field: "cluster.spec.topology.variables[.name=clusterConfig].value.globalImageRegistryMirror",
146+
field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.globalImageRegistryMirror",
147147
registryMirror: &carenv1.GlobalImageRegistryMirror{
148148
URL: testRegistryURL,
149149
Credentials: &carenv1.RegistryCredentials{
@@ -166,15 +166,15 @@ func TestRegistryCheck(t *testing.T) {
166166
InternalError: false,
167167
Causes: []preflight.Cause{
168168
{
169-
Message: "Registry credentials Secret \"test-secret\" not found. Create the Secret first, then create the Cluster.", ///nolint:lll // Message is long.
170-
Field: "cluster.spec.topology.variables[.name=clusterConfig].value.globalImageRegistryMirror.credentials.secretRef", //nolint:lll // Field is long.
169+
Message: "Registry credentials Secret \"test-secret\" not found. Create the Secret first, then create the Cluster.", ///nolint:lll // Message is long.
170+
Field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.globalImageRegistryMirror.credentials.secretRef", //nolint:lll // Field is long.
171171
},
172172
},
173173
},
174174
},
175175
{
176176
name: "registry mirror ping failure",
177-
field: "cluster.spec.topology.variables[.name=clusterConfig].value.globalImageRegistryMirror",
177+
field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.globalImageRegistryMirror",
178178
registryMirror: &carenv1.GlobalImageRegistryMirror{
179179
URL: testRegistryURL,
180180
},
@@ -191,7 +191,7 @@ func TestRegistryCheck(t *testing.T) {
191191
testRegistryURL,
192192
testPingFailedError,
193193
),
194-
Field: "cluster.spec.topology.variables[.name=clusterConfig].value.globalImageRegistryMirror",
194+
Field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.globalImageRegistryMirror",
195195
},
196196
},
197197
},
@@ -264,7 +264,7 @@ func TestRegistryCheck(t *testing.T) {
264264
},
265265
{
266266
name: "image registry with invalid URL",
267-
field: "cluster.spec.topology.variables[.name=clusterConfig].value.imageRegistries[0]",
267+
field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.imageRegistries[0]",
268268
imageRegistry: &carenv1.ImageRegistry{
269269
URL: "invalid-url",
270270
Credentials: &carenv1.RegistryCredentials{
@@ -299,14 +299,14 @@ func TestRegistryCheck(t *testing.T) {
299299
Causes: []preflight.Cause{
300300
{
301301
Message: "Failed to parse registry URL \"invalid-url\" with error: parse \"invalid-url\": invalid URI for request. Review the Cluster.", ///nolint:lll // Message is long.
302-
Field: "cluster.spec.topology.variables[.name=clusterConfig].value.imageRegistries[0].url",
302+
Field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.imageRegistries[0].url",
303303
},
304304
},
305305
},
306306
},
307307
{
308308
name: "image registry with invalid URL scheme",
309-
field: "cluster.spec.topology.variables[.name=clusterConfig].value.imageRegistries[0]",
309+
field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.imageRegistries[0]",
310310
imageRegistry: &carenv1.ImageRegistry{
311311
URL: "tcp://some-registry.lol",
312312
Credentials: &carenv1.RegistryCredentials{
@@ -341,7 +341,7 @@ func TestRegistryCheck(t *testing.T) {
341341
Causes: []preflight.Cause{
342342
{
343343
Message: "The registry URL \"tcp://some-registry.lol\" uses the scheme \"tcp\". This scheme is not supported. Use either the \"http\" or \"https\" scheme.", ///nolint:lll // Message is long.
344-
Field: "cluster.spec.topology.variables[.name=clusterConfig].value.imageRegistries[0].url",
344+
Field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.imageRegistries[0].url",
345345
},
346346
},
347347
},

pkg/webhook/preflight/generic/spec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func newConfigurationCheck(
5050
carenv1.ClusterConfigVariableName,
5151
err,
5252
),
53-
Field: "cluster.spec.topology.variables[.name=clusterConfig].genericClusterConfigSpec",
53+
Field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].genericClusterConfigSpec",
5454
},
5555
)
5656
}

pkg/webhook/preflight/generic/spec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func TestNewConfigurationCheck(t *testing.T) {
107107
Causes: []preflight.Cause{
108108
{
109109
Message: "Failed to unmarshal cluster variable \"clusterConfig\": failed to unmarshal json: invalid character 'i' looking for beginning of object key string. Review the Cluster.", ///nolint:lll // The message is long.
110-
Field: "cluster.spec.topology.variables[.name=clusterConfig].genericClusterConfigSpec",
110+
Field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].genericClusterConfigSpec",
111111
},
112112
},
113113
},

0 commit comments

Comments
 (0)