Skip to content

Commit ebe2c00

Browse files
authored
fix: Include correct field name in registry preflight check results (#1194)
**What problem does this PR solve?**: The registry check was returning the wrong field in some cases. **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 87360e2 commit ebe2c00

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

pkg/webhook/preflight/generic/registry.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import (
2222
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/webhook/preflight"
2323
)
2424

25-
var registryMirrorVarPath = "cluster.spec.topology.variables[.name=clusterConfig].value.globalImageRegistryMirror"
26-
2725
type registryCheck struct {
2826
field string
2927
kclient ctrlclient.Client
@@ -81,8 +79,8 @@ func (r *registryCheck) checkRegistry(
8179
result.Error = true
8280
result.Causes = append(result.Causes,
8381
preflight.Cause{
84-
Message: fmt.Sprintf("failed to parse registry url %s with error : %s", registryURL, err),
85-
Field: registryMirrorVarPath,
82+
Message: fmt.Sprintf("failed to parse registry url %s with error: %s", registryURL, err),
83+
Field: r.field + ".url",
8684
},
8785
)
8886
return result
@@ -106,7 +104,7 @@ func (r *registryCheck) checkRegistry(
106104
result.Causes = append(result.Causes,
107105
preflight.Cause{
108106
Message: fmt.Sprintf("failed to get Registry credentials Secret: %s", err),
109-
Field: fmt.Sprintf("%s.credentials.secretRef", registryMirrorVarPath),
107+
Field: r.field + ".credentials.secretRef",
110108
},
111109
)
112110
return result
@@ -134,7 +132,7 @@ func (r *registryCheck) checkRegistry(
134132
result.Causes = append(result.Causes,
135133
preflight.Cause{
136134
Message: fmt.Sprintf("failed to create a client to verify registry configuration %s", err.Error()),
137-
Field: registryMirrorVarPath,
135+
Field: r.field,
138136
},
139137
)
140138
return result
@@ -145,7 +143,7 @@ func (r *registryCheck) checkRegistry(
145143
result.Causes = append(result.Causes,
146144
preflight.Cause{
147145
Message: pingFailedReasonString(registryURL, err),
148-
Field: registryMirrorVarPath,
146+
Field: r.field,
149147
},
150148
)
151149
return result

pkg/webhook/preflight/generic/registry_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func (m *mockK8sClient) Get(
6363
func TestRegistryCheck(t *testing.T) {
6464
testCases := []struct {
6565
name string
66+
field string
6667
registryMirror *carenv1.GlobalImageRegistryMirror
6768
imageRegistry *carenv1.ImageRegistry
6869
kclient ctrlclient.Client
@@ -109,7 +110,8 @@ func TestRegistryCheck(t *testing.T) {
109110
},
110111
},
111112
{
112-
name: "registry mirror with invalid credentials secret",
113+
name: "registry mirror with invalid credentials secret",
114+
field: "cluster.spec.topology.variables[.name=clusterConfig].value.globalImageRegistryMirror",
113115
registryMirror: &carenv1.GlobalImageRegistryMirror{
114116
URL: testRegistryURL,
115117
Credentials: &carenv1.RegistryCredentials{
@@ -140,7 +142,8 @@ func TestRegistryCheck(t *testing.T) {
140142
},
141143
},
142144
{
143-
name: "registry mirror ping failure",
145+
name: "registry mirror ping failure",
146+
field: "cluster.spec.topology.variables[.name=clusterConfig].value.globalImageRegistryMirror",
144147
registryMirror: &carenv1.GlobalImageRegistryMirror{
145148
URL: testRegistryURL,
146149
},
@@ -209,6 +212,7 @@ func TestRegistryCheck(t *testing.T) {
209212

210213
// Create the check
211214
check := &registryCheck{
215+
field: tc.field,
212216
kclient: tc.kclient,
213217
cluster: cluster,
214218
regClientPingerGetter: tc.mockRegClientPingerFactory,

0 commit comments

Comments
 (0)