Skip to content

Commit 87e6164

Browse files
committed
fix: Capitalize messages in preflight check results
1 parent 3b9e71d commit 87e6164

File tree

10 files changed

+43
-40
lines changed

10 files changed

+43
-40
lines changed

pkg/webhook/preflight/generic/registry.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func defaultRegClientGetter(opts ...regclient.Opt) regClientPinger {
5858
}
5959

6060
func pingFailedReasonString(registryURL string, err error) string {
61-
return fmt.Sprintf("failed to ping registry %s with err: %s", registryURL, err.Error())
61+
return fmt.Sprintf("Failed to ping registry %s with err: %s", registryURL, err.Error())
6262
}
6363

6464
func (r *registryCheck) checkRegistry(
@@ -80,7 +80,7 @@ func (r *registryCheck) checkRegistry(
8080
result.InternalError = false
8181
result.Causes = append(result.Causes,
8282
preflight.Cause{
83-
Message: fmt.Sprintf("failed to parse registry url %s with error: %s", registryURL, err),
83+
Message: fmt.Sprintf("Failed to parse registry URL %q with error: %s", registryURL, err),
8484
Field: r.field + ".url",
8585
},
8686
)
@@ -115,8 +115,11 @@ func (r *registryCheck) checkRegistry(
115115
result.InternalError = true
116116
result.Causes = append(result.Causes,
117117
preflight.Cause{
118-
Message: fmt.Sprintf("failed to get Registry credentials Secret: %s", err),
119-
Field: r.field + ".credentials.secretRef",
118+
Message: fmt.Sprintf("Failed to get Registry credentials Secret %q: %s",
119+
credentials.SecretRef.Name,
120+
err,
121+
),
122+
Field: r.field + ".credentials.secretRef",
120123
},
121124
)
122125
return result

pkg/webhook/preflight/generic/registry_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func TestRegistryCheck(t *testing.T) {
135135
InternalError: true,
136136
Causes: []preflight.Cause{
137137
{
138-
Message: "failed to get Registry credentials Secret: fake error",
138+
Message: "Failed to get Registry credentials Secret \"test-secret\": fake error",
139139
//nolint:lll // this is a test for a field.
140140
Field: "cluster.spec.topology.variables[.name=clusterConfig].value.globalImageRegistryMirror.credentials.secretRef",
141141
},
@@ -268,7 +268,7 @@ func TestRegistryCheck(t *testing.T) {
268268
InternalError: false,
269269
Causes: []preflight.Cause{
270270
{
271-
Message: fmt.Sprintf("failed to parse registry url %s with error: "+
271+
Message: fmt.Sprintf("Failed to parse registry URL %q with error: "+
272272
"parse \"invalid-url\": invalid URI for request", "invalid-url"),
273273
Field: "cluster.spec.topology.variables[.name=clusterConfig].value.imageRegistries[0].url",
274274
},

pkg/webhook/preflight/nutanix/credentials.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func newCredentialsCheck(
7171
credentialsCheck.result.Allowed = false
7272
credentialsCheck.result.Causes = append(credentialsCheck.result.Causes,
7373
preflight.Cause{
74-
Message: fmt.Sprintf("failed to parse Prism Central endpoint URL: %s", err),
74+
Message: fmt.Sprintf("Failed to parse Prism Central endpoint URL: %s", err),
7575
Field: "$.spec.topology.variables[[email protected]==\"clusterConfig\"].value.nutanix.prismCentralEndpoint.url",
7676
},
7777
)
@@ -119,7 +119,7 @@ func newCredentialsCheck(
119119
credentialsCheck.result.Causes = append(credentialsCheck.result.Causes,
120120
preflight.Cause{
121121
Message: fmt.Sprintf(
122-
"credentials Secret %q is empty",
122+
"Credentials Secret %q is empty",
123123
prismCentralEndpointSpec.Credentials.SecretRef.Name,
124124
),
125125
Field: "$.spec.topology.variables[[email protected]==\"clusterConfig\"].value.nutanix.prismCentralEndpoint.credentials.secretRef",
@@ -134,7 +134,7 @@ func newCredentialsCheck(
134134
credentialsCheck.result.Causes = append(credentialsCheck.result.Causes,
135135
preflight.Cause{
136136
Message: fmt.Sprintf(
137-
"credentials Secret %q does not contain key %q",
137+
"Credentials Secret %q does not contain key %q",
138138
prismCentralEndpointSpec.Credentials.SecretRef.Name,
139139
credentialsSecretDataKey,
140140
),
@@ -149,7 +149,7 @@ func newCredentialsCheck(
149149
credentialsCheck.result.Allowed = false
150150
credentialsCheck.result.Causes = append(credentialsCheck.result.Causes,
151151
preflight.Cause{
152-
Message: fmt.Sprintf("failed to parse Prism Central credentials: %s", err),
152+
Message: fmt.Sprintf("Failed to parse Prism Central credentials: %s", err),
153153
Field: "$.spec.topology.variables[[email protected]==\"clusterConfig\"].value.nutanix.prismCentralEndpoint.credentials.secretRef",
154154
},
155155
)

pkg/webhook/preflight/nutanix/credentials_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestNewCredentialsCheck_InvalidURL(t *testing.T) {
7070
result := check.Run(context.Background())
7171
assert.False(t, result.Allowed)
7272
assert.False(t, result.InternalError)
73-
assert.Contains(t, result.Causes[0].Message, "failed to parse Prism Central endpoint URL")
73+
assert.Contains(t, result.Causes[0].Message, "Failed to parse Prism Central endpoint URL")
7474
}
7575

7676
func TestNewCredentialsCheck_SecretNotFound(t *testing.T) {
@@ -145,7 +145,7 @@ func TestNewCredentialsCheck_SecretEmpty(t *testing.T) {
145145
result := check.Run(context.Background())
146146
assert.False(t, result.Allowed)
147147
assert.False(t, result.InternalError)
148-
assert.Contains(t, result.Causes[0].Message, "credentials Secret \"ntnx-creds\" is empty")
148+
assert.Contains(t, result.Causes[0].Message, "Credentials Secret \"ntnx-creds\" is empty")
149149
}
150150

151151
func TestNewCredentialsCheck_SecretMissingKey(t *testing.T) {
@@ -186,7 +186,7 @@ func TestNewCredentialsCheck_InvalidCredentialsFormat(t *testing.T) {
186186
result := check.Run(context.Background())
187187
assert.False(t, result.Allowed)
188188
assert.False(t, result.InternalError)
189-
assert.Contains(t, result.Causes[0].Message, "failed to parse Prism Central credentials")
189+
assert.Contains(t, result.Causes[0].Message, "Failed to parse Prism Central credentials")
190190
}
191191

192192
func TestNewCredentialsCheck_FailedToCreateClient(t *testing.T) {

pkg/webhook/preflight/nutanix/image.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (c *imageCheck) Run(ctx context.Context) preflight.CheckResult {
3333
result.Allowed = true
3434
result.Warnings = append(
3535
result.Warnings,
36-
fmt.Sprintf("%s uses imageLookup, which is not yet supported by checks", c.field),
36+
fmt.Sprintf("Field %s uses imageLookup, which is not yet supported by checks", c.field),
3737
)
3838
return result
3939
}
@@ -44,7 +44,7 @@ func (c *imageCheck) Run(ctx context.Context) preflight.CheckResult {
4444
result.Allowed = false
4545
result.InternalError = true
4646
result.Causes = append(result.Causes, preflight.Cause{
47-
Message: fmt.Sprintf("failed to get VM Image: %s", err),
47+
Message: fmt.Sprintf("Failed to get VM Image: %s", err),
4848
Field: c.field + ".image",
4949
})
5050
return result
@@ -53,7 +53,7 @@ func (c *imageCheck) Run(ctx context.Context) preflight.CheckResult {
5353
if len(images) != 1 {
5454
result.Allowed = false
5555
result.Causes = append(result.Causes, preflight.Cause{
56-
Message: fmt.Sprintf("expected to find 1 VM Image, found %d", len(images)),
56+
Message: fmt.Sprintf("Expected to find 1 VM Image, found %d", len(images)),
5757
Field: c.field + ".image",
5858
})
5959
return result

pkg/webhook/preflight/nutanix/image_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func TestVMImageCheck(t *testing.T) {
126126
Allowed: false,
127127
Causes: []preflight.Cause{
128128
{
129-
Message: "expected to find 1 VM Image, found 0",
129+
Message: "Expected to find 1 VM Image, found 0",
130130
Field: "machineDetails.image",
131131
},
132132
},
@@ -168,7 +168,7 @@ func TestVMImageCheck(t *testing.T) {
168168
Allowed: false,
169169
Causes: []preflight.Cause{
170170
{
171-
Message: "expected to find 1 VM Image, found 2",
171+
Message: "Expected to find 1 VM Image, found 2",
172172
Field: "machineDetails.image",
173173
},
174174
},
@@ -192,7 +192,7 @@ func TestVMImageCheck(t *testing.T) {
192192
InternalError: true,
193193
Causes: []preflight.Cause{
194194
{
195-
Message: "failed to get VM Image: api error",
195+
Message: "Failed to get VM Image: api error",
196196
Field: "machineDetails.image",
197197
},
198198
},
@@ -225,7 +225,7 @@ func TestVMImageCheck(t *testing.T) {
225225
InternalError: true,
226226
Causes: []preflight.Cause{
227227
{
228-
Message: "failed to get VM Image: api error",
228+
Message: "Failed to get VM Image: api error",
229229
Field: "machineDetails.image",
230230
},
231231
},
@@ -261,7 +261,7 @@ func TestVMImageCheck(t *testing.T) {
261261
InternalError: true,
262262
Causes: []preflight.Cause{
263263
{
264-
Message: "failed to get VM Image: failed to get data returned by ListImages",
264+
Message: "Failed to get VM Image: failed to get data returned by ListImages",
265265
Field: "machineDetails.image",
266266
},
267267
},

pkg/webhook/preflight/nutanix/imagekubernetesversioncheck.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (c *imageKubernetesVersionCheck) Run(ctx context.Context) preflight.CheckRe
4242
InternalError: true,
4343
Causes: []preflight.Cause{
4444
{
45-
Message: fmt.Sprintf("failed to get VM Image: %s", err),
45+
Message: fmt.Sprintf("Failed to get VM Image: %s", err),
4646
Field: c.field + ".image",
4747
},
4848
},
@@ -84,15 +84,15 @@ func (c *imageKubernetesVersionCheck) checkKubernetesVersion(image *vmmv4.Image)
8484

8585
parsedVersion, err := semver.Parse(c.clusterK8sVersion)
8686
if err != nil {
87-
return fmt.Errorf("failed to parse kubernetes version '%s': %v", c.clusterK8sVersion, err)
87+
return fmt.Errorf("Failed to parse kubernetes version %q: %v", c.clusterK8sVersion, err)
8888
}
8989

9090
// For example, "1.33.1+fips.0" becomes "1.33.1".
9191
k8sVersion := parsedVersion.FinalizeVersion()
9292

9393
if !strings.Contains(imageName, k8sVersion) {
9494
return fmt.Errorf(
95-
"cluster kubernetes version '%s' is not part of image name '%s'",
95+
"Cluster kubernetes version %q is not part of image name %q",
9696
c.clusterK8sVersion,
9797
imageName,
9898
)

pkg/webhook/preflight/nutanix/imagekubernetesversioncheck_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestVMImageCheckWithKubernetesVersion(t *testing.T) {
7979
InternalError: false,
8080
Causes: []preflight.Cause{
8181
{
82-
Message: "cluster kubernetes version '1.32.3' is not part of image name 'kubedistro-ubuntu-22.04-vgpu-1.31.5-20250604180644'", //nolint:lll // cause message is long
82+
Message: "Cluster kubernetes version \"1.32.3\" is not part of image name \"kubedistro-ubuntu-22.04-vgpu-1.31.5-20250604180644\"", //nolint:lll // cause message is long
8383
Field: "machineDetails.image",
8484
},
8585
},
@@ -136,7 +136,7 @@ func TestVMImageCheckWithKubernetesVersion(t *testing.T) {
136136
InternalError: false,
137137
Causes: []preflight.Cause{
138138
{
139-
Message: "cluster kubernetes version '1.32.3' is not part of image name 'my-custom-image-name'",
139+
Message: "Cluster kubernetes version \"1.32.3\" is not part of image name \"my-custom-image-name\"",
140140
Field: "machineDetails.image",
141141
},
142142
},
@@ -168,7 +168,7 @@ func TestVMImageCheckWithKubernetesVersion(t *testing.T) {
168168
InternalError: false,
169169
Causes: []preflight.Cause{
170170
{
171-
Message: "failed to parse kubernetes version 'invalid.version': No Major.Minor.Patch elements found",
171+
Message: "Failed to parse kubernetes version \"invalid.version\": No Major.Minor.Patch elements found",
172172
Field: "machineDetails.image",
173173
},
174174
},
@@ -218,7 +218,7 @@ func TestVMImageCheckWithKubernetesVersion(t *testing.T) {
218218
want: preflight.CheckResult{
219219
Allowed: true,
220220
Warnings: []string{
221-
"test-field uses imageLookup, which is not yet supported by checks",
221+
"Field test-field uses imageLookup, which is not yet supported by checks",
222222
},
223223
},
224224
},
@@ -257,7 +257,7 @@ func TestVMImageCheckWithKubernetesVersion(t *testing.T) {
257257
InternalError: true,
258258
Causes: []preflight.Cause{
259259
{
260-
Message: "failed to get VM Image: some error",
260+
Message: "Failed to get VM Image: some error",
261261
Field: "machineDetails.image",
262262
},
263263
},

pkg/webhook/preflight/nutanix/storagecontainer.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (c *storageContainerCheck) Run(ctx context.Context) preflight.CheckResult {
8383
result.InternalError = true
8484
result.Causes = append(result.Causes, preflight.Cause{
8585
Message: fmt.Sprintf(
86-
"failed to check if storage container %q exists: failed to get cluster %q: %s",
86+
"Failed to check if storage container %q exists: failed to get cluster %q: %s",
8787
storageContainer,
8888
clusterIdentifier,
8989
err,
@@ -97,7 +97,7 @@ func (c *storageContainerCheck) Run(ctx context.Context) preflight.CheckResult {
9797
result.Allowed = false
9898
result.Causes = append(result.Causes, preflight.Cause{
9999
Message: fmt.Sprintf(
100-
"expected to find 1 cluster matching the reference, found %d",
100+
"Expected to find 1 cluster matching the reference, found %d",
101101
len(clusters),
102102
),
103103
Field: c.field,
@@ -114,7 +114,7 @@ func (c *storageContainerCheck) Run(ctx context.Context) preflight.CheckResult {
114114
result.InternalError = true
115115
result.Causes = append(result.Causes, preflight.Cause{
116116
Message: fmt.Sprintf(
117-
"failed to check if storage container %q exists in cluster %q: %s",
117+
"Failed to check if storage container %q exists in cluster %q: %s",
118118
storageContainer,
119119
clusterIdentifier,
120120
err,
@@ -128,7 +128,7 @@ func (c *storageContainerCheck) Run(ctx context.Context) preflight.CheckResult {
128128
result.Allowed = false
129129
result.Causes = append(result.Causes, preflight.Cause{
130130
Message: fmt.Sprintf(
131-
"expected to find 1 storage container named %q on cluster %q, found %d",
131+
"Expected to find 1 storage container named %q on cluster %q, found %d",
132132
storageContainer,
133133
clusterIdentifier,
134134
len(containers),

pkg/webhook/preflight/nutanix/storagecontainer_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ func TestStorageContainerCheck(t *testing.T) {
398398
},
399399
expectedAllowed: false,
400400
expectedError: false,
401-
expectedCauseMessage: "expected to find 1 storage container named \"missing-container\" " +
401+
expectedCauseMessage: "Expected to find 1 storage container named \"missing-container\" " +
402402
"on cluster \"test-cluster\", found 0",
403403
},
404404
{
@@ -474,7 +474,7 @@ func TestStorageContainerCheck(t *testing.T) {
474474
},
475475
expectedAllowed: false,
476476
expectedError: false,
477-
expectedCauseMessage: "expected to find 1 storage container named \"duplicate-container\" " +
477+
expectedCauseMessage: "Expected to find 1 storage container named \"duplicate-container\" " +
478478
"on cluster \"test-cluster\", found 2",
479479
},
480480
{
@@ -597,7 +597,7 @@ func TestStorageContainerCheck(t *testing.T) {
597597
},
598598
expectedAllowed: false,
599599
expectedError: false,
600-
expectedCauseMessage: "expected to find 1 cluster matching the reference, found 2",
600+
expectedCauseMessage: "Expected to find 1 cluster matching the reference, found 2",
601601
},
602602
{
603603
name: "error getting cluster",
@@ -637,7 +637,7 @@ func TestStorageContainerCheck(t *testing.T) {
637637
},
638638
expectedAllowed: false,
639639
expectedError: true,
640-
expectedCauseMessage: "failed to check if storage container \"valid-container\" exists: " +
640+
expectedCauseMessage: "Failed to check if storage container \"valid-container\" exists: " +
641641
"failed to get cluster \"test-cluster\": API error",
642642
},
643643
{
@@ -701,7 +701,7 @@ func TestStorageContainerCheck(t *testing.T) {
701701
},
702702
expectedAllowed: false,
703703
expectedError: true,
704-
expectedCauseMessage: "failed to check if storage container \"valid-container\" exists in cluster " +
704+
expectedCauseMessage: "Failed to check if storage container \"valid-container\" exists in cluster " +
705705
"\"test-cluster\": API error listing containers",
706706
},
707707
{
@@ -768,7 +768,7 @@ func TestStorageContainerCheck(t *testing.T) {
768768
},
769769
expectedAllowed: false,
770770
expectedError: true,
771-
expectedCauseMessage: "failed to check if storage container \"valid-container\" exists in cluster " +
771+
expectedCauseMessage: "Failed to check if storage container \"valid-container\" exists in cluster " +
772772
"\"test-cluster\": failed to get data returned by ListStorageContainers" +
773773
"(filter=\"name eq 'valid-container' and clusterExtId eq 'cluster-uuid-123'\")",
774774
},
@@ -833,7 +833,7 @@ func TestStorageContainerCheck(t *testing.T) {
833833
},
834834
expectedAllowed: false,
835835
expectedError: false,
836-
expectedCauseMessage: "expected to find 1 storage container named \"valid-container\" " +
836+
expectedCauseMessage: "Expected to find 1 storage container named \"valid-container\" " +
837837
"on cluster \"test-cluster\", found 0",
838838
},
839839
{

0 commit comments

Comments
 (0)