Skip to content

Commit 3b9e71d

Browse files
committed
fix: Use valid JSONPath to reference fields in preflight results
1 parent 3283e47 commit 3b9e71d

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

pkg/webhook/preflight/nutanix/credentials.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func newCredentialsCheck(
5656
credentialsCheck.result.Causes = append(credentialsCheck.result.Causes,
5757
preflight.Cause{
5858
Message: "Nutanix cluster configuration is not defined in the cluster spec",
59-
Field: "cluster.spec.topology.variables[.name=clusterConfig].nutanix",
59+
Field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.nutanix",
6060
},
6161
)
6262
return credentialsCheck
@@ -72,7 +72,7 @@ func newCredentialsCheck(
7272
credentialsCheck.result.Causes = append(credentialsCheck.result.Causes,
7373
preflight.Cause{
7474
Message: fmt.Sprintf("failed to parse Prism Central endpoint URL: %s", err),
75-
Field: "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint.url",
75+
Field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.nutanix.prismCentralEndpoint.url",
7676
},
7777
)
7878
return credentialsCheck
@@ -94,7 +94,7 @@ func newCredentialsCheck(
9494
preflight.Cause{
9595
Message: fmt.Sprintf("Prism Central credentials Secret %q not found",
9696
prismCentralEndpointSpec.Credentials.SecretRef.Name),
97-
Field: "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint.credentials.secretRef",
97+
Field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.nutanix.prismCentralEndpoint.credentials.secretRef",
9898
},
9999
)
100100
return credentialsCheck
@@ -108,7 +108,7 @@ func newCredentialsCheck(
108108
prismCentralEndpointSpec.Credentials.SecretRef.Name,
109109
err,
110110
),
111-
Field: "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint.credentials.secretRef",
111+
Field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.nutanix.prismCentralEndpoint.credentials.secretRef",
112112
},
113113
)
114114
return credentialsCheck
@@ -122,7 +122,7 @@ func newCredentialsCheck(
122122
"credentials Secret %q is empty",
123123
prismCentralEndpointSpec.Credentials.SecretRef.Name,
124124
),
125-
Field: "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint.credentials.secretRef",
125+
Field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.nutanix.prismCentralEndpoint.credentials.secretRef",
126126
},
127127
)
128128
return credentialsCheck
@@ -138,7 +138,7 @@ func newCredentialsCheck(
138138
prismCentralEndpointSpec.Credentials.SecretRef.Name,
139139
credentialsSecretDataKey,
140140
),
141-
Field: "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint.credentials.secretRef",
141+
Field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.nutanix.prismCentralEndpoint.credentials.secretRef",
142142
},
143143
)
144144
return credentialsCheck
@@ -150,7 +150,7 @@ func newCredentialsCheck(
150150
credentialsCheck.result.Causes = append(credentialsCheck.result.Causes,
151151
preflight.Cause{
152152
Message: fmt.Sprintf("failed to parse Prism Central credentials: %s", err),
153-
Field: "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint.credentials",
153+
Field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.nutanix.prismCentralEndpoint.credentials.secretRef",
154154
},
155155
)
156156
return credentialsCheck
@@ -173,7 +173,7 @@ func newCredentialsCheck(
173173
credentialsCheck.result.Causes = append(credentialsCheck.result.Causes,
174174
preflight.Cause{
175175
Message: fmt.Sprintf("Failed to initialize Nutanix client: %s", err),
176-
Field: "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint.credentials",
176+
Field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.nutanix.prismCentralEndpoint.credentials.secretRef",
177177
},
178178
)
179179
return credentialsCheck
@@ -188,7 +188,7 @@ func newCredentialsCheck(
188188
preflight.Cause{
189189
Message: fmt.Sprintf("Failed to validate credentials using the v3 API client. "+
190190
"The URL and/or credentials may be incorrect. (Error: %q)", err),
191-
Field: "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint",
191+
Field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.nutanix.prismCentralEndpoint",
192192
},
193193
)
194194
return credentialsCheck

pkg/webhook/preflight/nutanix/image.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func newVMImageChecks(
8282
checks = append(checks,
8383
&imageCheck{
8484
machineDetails: &cd.nutanixClusterConfigSpec.ControlPlane.Nutanix.MachineDetails,
85-
field: "cluster.spec.topology.variables[.name=clusterConfig]" +
85+
field: "$.spec.topology.variables[?@.name==\"clusterConfig\"]." +
8686
".value.nutanix.controlPlane.machineDetails",
8787
nclient: cd.nclient,
8888
},
@@ -94,8 +94,8 @@ func newVMImageChecks(
9494
checks = append(checks,
9595
&imageCheck{
9696
machineDetails: &nutanixWorkerNodeConfigSpec.Nutanix.MachineDetails,
97-
field: fmt.Sprintf("cluster.spec.topology.workers.machineDeployments[.name=%s]"+
98-
".variables[.name=workerConfig].value.nutanix.machineDetails", mdName),
97+
field: fmt.Sprintf("$.spec.topology.workers.machineDeployments[?@.name==%q]"+
98+
".variables[?@.name=workerConfig].value.nutanix.machineDetails", mdName),
9999
nclient: cd.nclient,
100100
},
101101
)

pkg/webhook/preflight/nutanix/imagekubernetesversioncheck.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func newVMImageKubernetesVersionChecks(
126126
checks = append(checks,
127127
&imageKubernetesVersionCheck{
128128
machineDetails: &cd.nutanixClusterConfigSpec.ControlPlane.Nutanix.MachineDetails,
129-
field: "cluster.spec.topology.variables[.name=clusterConfig]" +
129+
field: "$.spec.topology.variables[?@.name==\"clusterConfig\"]." +
130130
".value.nutanix.controlPlane.machineDetails",
131131
nclient: cd.nclient,
132132
clusterK8sVersion: clusterK8sVersion,
@@ -139,8 +139,8 @@ func newVMImageKubernetesVersionChecks(
139139
checks = append(checks,
140140
&imageKubernetesVersionCheck{
141141
machineDetails: &nutanixWorkerNodeConfigSpec.Nutanix.MachineDetails,
142-
field: fmt.Sprintf("cluster.spec.topology.workers.machineDeployments[.name=%s]"+
143-
".variables[.name=workerConfig].value.nutanix.machineDetails", mdName),
142+
field: fmt.Sprintf("$.spec.topology.workers.machineDeployments[?@.name==%q]"+
143+
".variables[?@.name=workerConfig].value.nutanix.machineDetails", mdName),
144144
nclient: cd.nclient,
145145
clusterK8sVersion: clusterK8sVersion,
146146
},

pkg/webhook/preflight/nutanix/specs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func newConfigurationCheck(
5353
carenv1.ClusterConfigVariableName,
5454
err,
5555
),
56-
Field: "cluster.spec.topology.variables[.name=clusterConfig].nutanix",
56+
Field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.nutanix",
5757
},
5858
)
5959
}
@@ -87,8 +87,8 @@ func newConfigurationCheck(
8787
err,
8888
),
8989
Field: fmt.Sprintf(
90-
"cluster.spec.topology.workers.machineDeployments[.name=%s]"+
91-
".variables[.name=workerConfig].value.nutanix.machineDetails",
90+
"$.spec.topology.workers.machineDeployments[?@.name==%q]"+
91+
".variables[?@.name=workerConfig].value.nutanix.machineDetails",
9292
md.Name,
9393
),
9494
},

pkg/webhook/preflight/nutanix/specs_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func TestNewConfigurationCheck(t *testing.T) {
138138
{
139139
Message: "Failed to unmarshal cluster variable clusterConfig: failed to unmarshal json:" +
140140
" invalid character 'i' looking for beginning of object key string",
141-
Field: "cluster.spec.topology.variables[.name=clusterConfig].nutanix",
141+
Field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.nutanix",
142142
},
143143
},
144144
},
@@ -186,8 +186,8 @@ func TestNewConfigurationCheck(t *testing.T) {
186186
{
187187
Message: "Failed to unmarshal topology machineDeployment variable workerConfig:" +
188188
" failed to unmarshal json: invalid character 'i' looking for beginning of object key string",
189-
Field: "cluster.spec.topology.workers.machineDeployments[.name=md-0]." +
190-
"variables[.name=workerConfig].value.nutanix.machineDetails",
189+
Field: "$.spec.topology.workers.machineDeployments[?@.name==\"md-0\"]" +
190+
".variables[?@.name=workerConfig].value.nutanix.machineDetails",
191191
},
192192
},
193193
},

pkg/webhook/preflight/nutanix/storagecontainer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func newStorageContainerChecks(cd *checkDependencies) []preflight.Check {
161161
checks = append(checks,
162162
&storageContainerCheck{
163163
machineSpec: &cd.nutanixClusterConfigSpec.ControlPlane.Nutanix.MachineDetails,
164-
field: "cluster.spec.topology[.name=clusterConfig].value.controlPlane.nutanix.machineDetails",
164+
field: "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.controlPlane.nutanix.machineDetails",
165165
csiSpec: &cd.nutanixClusterConfigSpec.Addons.CSI.Providers.NutanixCSI,
166166
nclient: cd.nclient,
167167
},
@@ -174,8 +174,8 @@ func newStorageContainerChecks(cd *checkDependencies) []preflight.Check {
174174
&storageContainerCheck{
175175
machineSpec: &nutanixWorkerNodeConfigSpec.Nutanix.MachineDetails,
176176
field: fmt.Sprintf(
177-
"cluster.spec.topology.workers.machineDeployments[.name=%s]"+
178-
".variables[.name=workerConfig].value.nutanix.machineDetails",
177+
"$.spec.topology.workers.machineDeployments[?@.name==%q]"+
178+
".variables[?@.name=workerConfig].value.nutanix.machineDetails",
179179
mdName,
180180
),
181181
csiSpec: &cd.nutanixClusterConfigSpec.Addons.CSI.Providers.NutanixCSI,

0 commit comments

Comments
 (0)