Skip to content

Commit 269b3ac

Browse files
author
Per G. da Silva
committed
Make watchNamespace config to be required for OwnNamespace bundles
Signed-off-by: Per G. da Silva <[email protected]>
1 parent 0ebf4b2 commit 269b3ac

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

internal/operator-controller/rukpak/bundle/config.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,19 @@ func validateConfig(config *Config, installNamespace string, bundleInstallModeSe
8383
}
8484

8585
// isWatchNamespaceConfigSupported returns true when the bundle exposes a watchNamespace configuration. This happens when:
86-
// - SingleNamespace install more is supported, or
87-
// - OwnNamespace and AllNamespaces install modes are supported
86+
// - SingleNamespace and/or OwnNamespace install modes are supported
8887
func isWatchNamespaceConfigSupported(bundleInstallModeSet sets.Set[v1alpha1.InstallMode]) bool {
89-
return bundleInstallModeSet.Has(v1alpha1.InstallMode{Type: v1alpha1.InstallModeTypeSingleNamespace, Supported: true}) ||
90-
bundleInstallModeSet.HasAll(
91-
v1alpha1.InstallMode{Type: v1alpha1.InstallModeTypeOwnNamespace, Supported: true},
92-
v1alpha1.InstallMode{Type: v1alpha1.InstallModeTypeAllNamespaces, Supported: true})
88+
return bundleInstallModeSet.HasAny(
89+
v1alpha1.InstallMode{Type: v1alpha1.InstallModeTypeSingleNamespace, Supported: true},
90+
v1alpha1.InstallMode{Type: v1alpha1.InstallModeTypeOwnNamespace, Supported: true},
91+
)
9392
}
9493

9594
// isWatchNamespaceConfigRequired returns true if the watchNamespace configuration is required. This happens when
96-
// AllNamespaces install mode is not supported and SingleNamespace is supported
95+
// AllNamespaces install mode is not supported and SingleNamespace and/or OwnNamespace is supported
9796
func isWatchNamespaceConfigRequired(bundleInstallModeSet sets.Set[v1alpha1.InstallMode]) bool {
98-
return !bundleInstallModeSet.Has(v1alpha1.InstallMode{Type: v1alpha1.InstallModeTypeAllNamespaces, Supported: true}) &&
99-
bundleInstallModeSet.Has(v1alpha1.InstallMode{Type: v1alpha1.InstallModeTypeSingleNamespace, Supported: true})
97+
return isWatchNamespaceConfigSupported(bundleInstallModeSet) &&
98+
!bundleInstallModeSet.Has(v1alpha1.InstallMode{Type: v1alpha1.InstallModeTypeAllNamespaces, Supported: true})
10099
}
101100

102101
// formatUnmarshallError format JSON unmarshal errors to be more readable

internal/operator-controller/rukpak/bundle/config_test.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,28 @@ func Test_UnmarshallConfig(t *testing.T) {
9191
expectedErrMessage: "unknown field \"watchNamespace\"",
9292
},
9393
{
94-
name: "reject with unknown field when install modes {OwnNamespace}",
94+
name: "reject with required field when install modes {OwnNamespace} and watchNamespace is null",
9595
supportedInstallModes: []v1alpha1.InstallModeType{v1alpha1.InstallModeTypeOwnNamespace},
96-
rawConfig: []byte(`{"watchNamespace": "some-namespace"}`),
97-
expectedErrMessage: "unknown field \"watchNamespace\"",
96+
rawConfig: []byte(`{"watchNamespace": null}`),
97+
expectedErrMessage: "required field \"watchNamespace\" is missing",
98+
},
99+
{
100+
name: "reject with required field when install modes {OwnNamespace} and watchNamespace is missing",
101+
supportedInstallModes: []v1alpha1.InstallModeType{v1alpha1.InstallModeTypeOwnNamespace},
102+
rawConfig: []byte(`{}`),
103+
expectedErrMessage: "required field \"watchNamespace\" is missing",
98104
},
99105
{
100-
name: "reject with unknown field when install modes {MultiNamespace, OwnNamespace}",
106+
name: "reject with required field when install modes {MultiNamespace, OwnNamespace} and watchNamespace is null",
101107
supportedInstallModes: []v1alpha1.InstallModeType{v1alpha1.InstallModeTypeMultiNamespace, v1alpha1.InstallModeTypeOwnNamespace},
102-
rawConfig: []byte(`{"watchNamespace": "some-namespace"}`),
103-
expectedErrMessage: "unknown field \"watchNamespace\"",
108+
rawConfig: []byte(`{"watchNamespace": null}`),
109+
expectedErrMessage: "required field \"watchNamespace\" is missing",
110+
},
111+
{
112+
name: "reject with required field when install modes {MultiNamespace, OwnNamespace} and watchNamespace is missing",
113+
supportedInstallModes: []v1alpha1.InstallModeType{v1alpha1.InstallModeTypeMultiNamespace, v1alpha1.InstallModeTypeOwnNamespace},
114+
rawConfig: []byte(`{}`),
115+
expectedErrMessage: "required field \"watchNamespace\" is missing",
104116
},
105117
{
106118
name: "accepts when install modes {SingleNamespace} and watchNamespace != install namespace",

0 commit comments

Comments
 (0)