Skip to content

Commit 2fcbefa

Browse files
author
Per Goncalves da Silva
committed
Update target namespace validation to reject own namespace installation on single namespace mode
Signed-off-by: Per Goncalves da Silva <pegoncal@redhat.com>
1 parent 0a263ed commit 2fcbefa

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

internal/operator-controller/rukpak/render/render.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,13 @@ func validateTargetNamespaces(rv1 *bundle.RegistryV1, installNamespace string, t
159159
}
160160
return fmt.Errorf("supported install modes %v do not support targeting all namespaces", sets.List(supportedInstallModes))
161161
case set.Len() == 1 && !set.Has(""):
162-
if supportedInstallModes.Has(v1alpha1.InstallModeTypeSingleNamespace) {
162+
if targetNamespaces[0] == installNamespace {
163+
if !supportedInstallModes.Has(v1alpha1.InstallModeTypeOwnNamespace) {
164+
return fmt.Errorf("supported install modes %v do not support targeting own namespace", sets.List(supportedInstallModes))
165+
}
163166
return nil
164167
}
165-
if supportedInstallModes.Has(v1alpha1.InstallModeTypeOwnNamespace) && targetNamespaces[0] == installNamespace {
168+
if supportedInstallModes.Has(v1alpha1.InstallModeTypeSingleNamespace) {
166169
return nil
167170
}
168171
default:

internal/operator-controller/rukpak/render/render_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func Test_BundleRenderer_ValidatesRenderOptions(t *testing.T) {
213213
opts: []render.Option{
214214
render.WithTargetNamespaces("install-namespace"),
215215
},
216-
err: errors.New("invalid option(s): invalid target namespaces [install-namespace]: supported install modes [AllNamespaces] do not support target namespaces [install-namespace]"),
216+
err: errors.New("invalid option(s): invalid target namespaces [install-namespace]: supported install modes [AllNamespaces] do not support targeting own namespace"),
217217
}, {
218218
name: "rejects install out of own namespace if only OwnNamespace install mode is supported",
219219
installNamespace: "install-namespace",
@@ -266,6 +266,14 @@ func Test_BundleRenderer_ValidatesRenderOptions(t *testing.T) {
266266
opts: []render.Option{
267267
render.WithTargetNamespaces("some-namespace"),
268268
},
269+
}, {
270+
name: "rejects single namespace render if OwnNamespace install mode is unsupported and targets own namespace",
271+
installNamespace: "install-namespace",
272+
csv: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeSingleNamespace)),
273+
opts: []render.Option{
274+
render.WithTargetNamespaces("install-namespace"),
275+
},
276+
err: errors.New("invalid option(s): invalid target namespaces [install-namespace]: supported install modes [SingleNamespace] do not support targeting own namespace"),
269277
}, {
270278
name: "accepts multi namespace render if MultiNamespace install mode is supported",
271279
installNamespace: "install-namespace",

0 commit comments

Comments
 (0)