Skip to content

Commit b5944d5

Browse files
(feat): Improved Error Messages for watchNamespace Configuration
1 parent 6ef62de commit b5944d5

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

internal/operator-controller/config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ func formatSingleError(errUnit jsonschema.OutputUnit) string {
267267
// Unknown/additional field
268268
fieldName := extractFieldNameFromMessage(errUnit.Error)
269269
if fieldName != "" {
270+
// Special case: if watchNamespace is rejected as unknown, it means only
271+
// AllNamespaces install mode is supported
272+
if fieldName == "watchNamespace" {
273+
return fmt.Sprintf("field %q not allowed: only AllNamespaces install mode is supported", fieldName)
274+
}
270275
return fmt.Sprintf("unknown field %q", fieldName)
271276
}
272277
return "unknown field"

internal/operator-controller/config/config_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,22 @@ func Test_UnmarshalConfig(t *testing.T) {
8080
expectedErrMessage: `got object, want string`,
8181
},
8282
{
83-
name: "rejects with unknown field when install modes {AllNamespaces}",
83+
name: "rejects with descriptive message when install modes {AllNamespaces}",
8484
supportedInstallModes: []v1alpha1.InstallModeType{v1alpha1.InstallModeTypeAllNamespaces},
8585
rawConfig: []byte(`{"watchNamespace": "some-namespace"}`),
86-
expectedErrMessage: `unknown field "watchNamespace"`,
86+
expectedErrMessage: `field "watchNamespace" not allowed: only AllNamespaces install mode is supported`,
8787
},
8888
{
89-
name: "rejects with unknown field when install modes {MultiNamespace}",
89+
name: "rejects with descriptive message when install modes {MultiNamespace}",
9090
supportedInstallModes: []v1alpha1.InstallModeType{v1alpha1.InstallModeTypeMultiNamespace},
9191
rawConfig: []byte(`{"watchNamespace": "some-namespace"}`),
92-
expectedErrMessage: `unknown field "watchNamespace"`,
92+
expectedErrMessage: `field "watchNamespace" not allowed: only AllNamespaces install mode is supported`,
9393
},
9494
{
95-
name: "reject with unknown field when install modes {AllNamespaces, MultiNamespace}",
95+
name: "reject with descriptive message when install modes {AllNamespaces, MultiNamespace}",
9696
supportedInstallModes: []v1alpha1.InstallModeType{v1alpha1.InstallModeTypeAllNamespaces, v1alpha1.InstallModeTypeMultiNamespace},
9797
rawConfig: []byte(`{"watchNamespace": "some-namespace"}`),
98-
expectedErrMessage: `unknown field "watchNamespace"`,
98+
expectedErrMessage: `field "watchNamespace" not allowed: only AllNamespaces install mode is supported`,
9999
},
100100
{
101101
name: "reject with required field when install modes {OwnNamespace} and watchNamespace is null",

0 commit comments

Comments
 (0)