- 
                Notifications
    You must be signed in to change notification settings 
- Fork 68
🐛 OPRUN-4217: OwnNamespace default handling #2283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d971b1b
              2f00924
              8f705cc
              e994682
              c57eeb6
              7c79e70
              305ec39
              f995320
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|  | @@ -244,15 +244,6 @@ func Test_RegistryV1ManifestProvider_SingleOwnNamespaceSupport(t *testing.T) { | |||||
| t.Run("rejects bundles without AllNamespaces install mode and with SingleNamespace support when Single/OwnNamespace install mode support is enabled", func(t *testing.T) { | ||||||
| expectedWatchNamespace := "some-namespace" | ||||||
| provider := applier.RegistryV1ManifestProvider{ | ||||||
| BundleRenderer: render.BundleRenderer{ | ||||||
| ResourceGenerators: []render.ResourceGenerator{ | ||||||
| func(rv1 *bundle.RegistryV1, opts render.Options) ([]client.Object, error) { | ||||||
| t.Log("ensure watch namespace is appropriately configured") | ||||||
| require.Equal(t, []string{expectedWatchNamespace}, opts.TargetNamespaces) | ||||||
| return nil, nil | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| IsSingleOwnNamespaceEnabled: false, | ||||||
| } | ||||||
|  | ||||||
|  | @@ -289,7 +280,7 @@ func Test_RegistryV1ManifestProvider_SingleOwnNamespaceSupport(t *testing.T) { | |||||
| require.Contains(t, err.Error(), "unsupported bundle") | ||||||
| }) | ||||||
|  | ||||||
| t.Run("accepts bundles without AllNamespaces install mode and with SingleNamespace support when Single/OwnNamespace install mode support is enabled", func(t *testing.T) { | ||||||
| t.Run("accepts bundles with install modes {SingleNamespace} when the appropriate configuration is given", func(t *testing.T) { | ||||||
| expectedWatchNamespace := "some-namespace" | ||||||
| provider := applier.RegistryV1ManifestProvider{ | ||||||
| BundleRenderer: render.BundleRenderer{ | ||||||
|  | @@ -321,20 +312,89 @@ func Test_RegistryV1ManifestProvider_SingleOwnNamespaceSupport(t *testing.T) { | |||||
| require.NoError(t, err) | ||||||
| }) | ||||||
|  | ||||||
| t.Run("accepts bundles without AllNamespaces install mode and with OwnNamespace support when Single/OwnNamespace install mode support is enabled", func(t *testing.T) { | ||||||
| t.Run("rejects bundles with {SingleNamespace} install modes when no configuration is given", func(t *testing.T) { | ||||||
| provider := applier.RegistryV1ManifestProvider{ | ||||||
| IsSingleOwnNamespaceEnabled: true, | ||||||
| } | ||||||
|  | ||||||
| bundleFS := bundlefs.Builder().WithPackageName("test"). | ||||||
| WithCSV(clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeOwnNamespace).Build()).Build() | ||||||
| WithCSV(clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeSingleNamespace).Build()).Build() | ||||||
|  | ||||||
| _, err := provider.Get(bundleFS, &ocv1.ClusterExtension{ | ||||||
| Spec: ocv1.ClusterExtensionSpec{ | ||||||
| Namespace: "install-namespace", | ||||||
| }, | ||||||
| }) | ||||||
| require.Error(t, err) | ||||||
| require.Contains(t, err.Error(), "required field \"watchNamespace\" is missing") | ||||||
| }) | ||||||
|  | ||||||
| t.Run("accepts bundles with {OwnNamespace} install modes when the appropriate configuration is given", func(t *testing.T) { | ||||||
| installNamespace := "some-namespace" | ||||||
| provider := applier.RegistryV1ManifestProvider{ | ||||||
| BundleRenderer: render.BundleRenderer{ | ||||||
| ResourceGenerators: []render.ResourceGenerator{ | ||||||
| func(rv1 *bundle.RegistryV1, opts render.Options) ([]client.Object, error) { | ||||||
| t.Log("ensure watch namespace is appropriately configured") | ||||||
| require.Equal(t, []string{installNamespace}, opts.TargetNamespaces) | ||||||
| return nil, nil | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| IsSingleOwnNamespaceEnabled: true, | ||||||
| } | ||||||
| bundleFS := bundlefs.Builder().WithPackageName("test"). | ||||||
| WithCSV(clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeOwnNamespace).Build()).Build() | ||||||
| _, err := provider.Get(bundleFS, &ocv1.ClusterExtension{ | ||||||
| Spec: ocv1.ClusterExtensionSpec{ | ||||||
| Namespace: installNamespace, | ||||||
| Config: &ocv1.ClusterExtensionConfig{ | ||||||
| ConfigType: ocv1.ClusterExtensionConfigTypeInline, | ||||||
| Inline: &apiextensionsv1.JSON{ | ||||||
| Raw: []byte(`{"watchNamespace": "` + installNamespace + `"}`), | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| }) | ||||||
| require.NoError(t, err) | ||||||
| }) | ||||||
|  | ||||||
|         
                  camilamacedo86 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||||||
| t.Run("rejects bundles with {OwnNamespace} install modes when no configuration is given", func(t *testing.T) { | ||||||
| provider := applier.RegistryV1ManifestProvider{ | ||||||
| IsSingleOwnNamespaceEnabled: true, | ||||||
| } | ||||||
| bundleFS := bundlefs.Builder().WithPackageName("test"). | ||||||
| WithCSV(clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeOwnNamespace).Build()).Build() | ||||||
| _, err := provider.Get(bundleFS, &ocv1.ClusterExtension{ | ||||||
| Spec: ocv1.ClusterExtensionSpec{ | ||||||
| Namespace: "install-namespace", | ||||||
| }, | ||||||
| }) | ||||||
| require.Error(t, err) | ||||||
| require.Contains(t, err.Error(), "required field \"watchNamespace\" is missing") | ||||||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
        Suggested change
       
 What about adding an install mode and having unique errors, not only to make it easier to understand but also to make troubleshooting easier? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we want to surface these concerns up. It's not that bundle supports this or that. It's configuration is required/optional, the value is valid/invalid, etc. Install modes are a v0 thing. We don't want to leak it here I don't think. | ||||||
| }) | ||||||
|  | ||||||
| t.Run("rejects bundles with {OwnNamespace} install modes when watchNamespace is not install namespace", func(t *testing.T) { | ||||||
| provider := applier.RegistryV1ManifestProvider{ | ||||||
| IsSingleOwnNamespaceEnabled: true, | ||||||
| } | ||||||
| bundleFS := bundlefs.Builder().WithPackageName("test"). | ||||||
| WithCSV(clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeOwnNamespace).Build()).Build() | ||||||
| _, err := provider.Get(bundleFS, &ocv1.ClusterExtension{ | ||||||
| Spec: ocv1.ClusterExtensionSpec{ | ||||||
| Namespace: "install-namespace", | ||||||
| Config: &ocv1.ClusterExtensionConfig{ | ||||||
| ConfigType: ocv1.ClusterExtensionConfigTypeInline, | ||||||
| Inline: &apiextensionsv1.JSON{ | ||||||
| Raw: []byte(`{"watchNamespace": "not-install-namespace"}`), | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| }) | ||||||
| require.Error(t, err) | ||||||
| require.Contains(t, err.Error(), "invalid 'watchNamespace' \"not-install-namespace\": must be install namespace (install-namespace)") | ||||||
| }) | ||||||
|  | ||||||
| t.Run("rejects bundles without AllNamespaces, SingleNamespace, or OwnNamespace install mode support when Single/OwnNamespace install mode support is enabled", func(t *testing.T) { | ||||||
| provider := applier.RegistryV1ManifestProvider{ | ||||||
| IsSingleOwnNamespaceEnabled: true, | ||||||
|  | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|  | @@ -12,7 +12,7 @@ import ( | |||||
| "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/clusterserviceversion" | ||||||
| ) | ||||||
|  | ||||||
| func Test_UnmarshallConfig(t *testing.T) { | ||||||
| func Test_UnmarshalConfig(t *testing.T) { | ||||||
| for _, tc := range []struct { | ||||||
| name string | ||||||
| rawConfig []byte | ||||||
|  | @@ -22,7 +22,7 @@ func Test_UnmarshallConfig(t *testing.T) { | |||||
| expectedConfig *bundle.Config | ||||||
| }{ | ||||||
| { | ||||||
| name: "accepts nil raw config", | ||||||
| name: "returns nil for nil config", | ||||||
| rawConfig: nil, | ||||||
| expectedConfig: nil, | ||||||
| }, | ||||||
|  | @@ -91,16 +91,28 @@ func Test_UnmarshallConfig(t *testing.T) { | |||||
| expectedErrMessage: "unknown field \"watchNamespace\"", | ||||||
| }, | ||||||
| { | ||||||
| name: "reject with unknown field when install modes {OwnNamespace}", | ||||||
| name: "reject with required field when install modes {OwnNamespace} and watchNamespace is null", | ||||||
| supportedInstallModes: []v1alpha1.InstallModeType{v1alpha1.InstallModeTypeOwnNamespace}, | ||||||
| rawConfig: []byte(`{"watchNamespace": "some-namespace"}`), | ||||||
| expectedErrMessage: "unknown field \"watchNamespace\"", | ||||||
| rawConfig: []byte(`{"watchNamespace": null}`), | ||||||
| expectedErrMessage: "required field \"watchNamespace\" is missing", | ||||||
| }, | ||||||
| { | ||||||
| name: "reject with required field when install modes {OwnNamespace} and watchNamespace is missing", | ||||||
| supportedInstallModes: []v1alpha1.InstallModeType{v1alpha1.InstallModeTypeOwnNamespace}, | ||||||
| rawConfig: []byte(`{}`), | ||||||
| expectedErrMessage: "required field \"watchNamespace\" is missing", | ||||||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
        Suggested change
       
 What about adding an install mode and having unique errors, not only to make it easier to understand but also to make troubleshooting easier? | ||||||
| }, | ||||||
| { | ||||||
| name: "reject with unknown field when install modes {MultiNamespace, OwnNamespace}", | ||||||
| name: "reject with required field when install modes {MultiNamespace, OwnNamespace} and watchNamespace is null", | ||||||
| supportedInstallModes: []v1alpha1.InstallModeType{v1alpha1.InstallModeTypeMultiNamespace, v1alpha1.InstallModeTypeOwnNamespace}, | ||||||
| rawConfig: []byte(`{"watchNamespace": "some-namespace"}`), | ||||||
| expectedErrMessage: "unknown field \"watchNamespace\"", | ||||||
| rawConfig: []byte(`{"watchNamespace": null}`), | ||||||
| expectedErrMessage: "required field \"watchNamespace\" is missing", | ||||||
| }, | ||||||
| { | ||||||
| name: "reject with required field when install modes {MultiNamespace, OwnNamespace} and watchNamespace is missing", | ||||||
| supportedInstallModes: []v1alpha1.InstallModeType{v1alpha1.InstallModeTypeMultiNamespace, v1alpha1.InstallModeTypeOwnNamespace}, | ||||||
| rawConfig: []byte(`{}`), | ||||||
| expectedErrMessage: "required field \"watchNamespace\" is missing", | ||||||
| }, | ||||||
| { | ||||||
| name: "accepts when install modes {SingleNamespace} and watchNamespace != install namespace", | ||||||
|  | @@ -202,6 +214,27 @@ func Test_UnmarshallConfig(t *testing.T) { | |||||
| installNamespace: "not-some-namespace", | ||||||
| expectedErrMessage: "required field \"watchNamespace\" is missing", | ||||||
| }, | ||||||
| { | ||||||
| name: "rejects with required field error when install modes {SingleNamespace} and watchNamespace is missing", | ||||||
| supportedInstallModes: []v1alpha1.InstallModeType{v1alpha1.InstallModeTypeSingleNamespace}, | ||||||
| rawConfig: []byte(`{}`), | ||||||
| installNamespace: "not-some-namespace", | ||||||
| expectedErrMessage: "required field \"watchNamespace\" is missing", | ||||||
| }, | ||||||
| { | ||||||
| name: "rejects with required field error when install modes {SingleNamespace, OwnNamespace} and watchNamespace is missing", | ||||||
| supportedInstallModes: []v1alpha1.InstallModeType{v1alpha1.InstallModeTypeSingleNamespace, v1alpha1.InstallModeTypeOwnNamespace}, | ||||||
| rawConfig: []byte(`{}`), | ||||||
| installNamespace: "not-some-namespace", | ||||||
| expectedErrMessage: "required field \"watchNamespace\" is missing", | ||||||
| }, | ||||||
| { | ||||||
| name: "rejects with required field error when install modes {SingleNamespace, MultiNamespace} and watchNamespace is missing", | ||||||
| supportedInstallModes: []v1alpha1.InstallModeType{v1alpha1.InstallModeTypeSingleNamespace, v1alpha1.InstallModeTypeMultiNamespace}, | ||||||
| rawConfig: []byte(`{}`), | ||||||
| installNamespace: "not-some-namespace", | ||||||
| expectedErrMessage: "required field \"watchNamespace\" is missing", | ||||||
| }, | ||||||
| { | ||||||
| name: "rejects with required field error when install modes {SingleNamespace, OwnNamespace, MultiNamespace} and watchNamespace is nil", | ||||||
| supportedInstallModes: []v1alpha1.InstallModeType{v1alpha1.InstallModeTypeSingleNamespace, v1alpha1.InstallModeTypeOwnNamespace, v1alpha1.InstallModeTypeMultiNamespace}, | ||||||
|  | @@ -227,6 +260,24 @@ func Test_UnmarshallConfig(t *testing.T) { | |||||
| WatchNamespace: nil, | ||||||
| }, | ||||||
| }, | ||||||
| { | ||||||
| name: "accepts no watchNamespace when install modes {AllNamespaces, OwnNamespace} and watchNamespace is nil", | ||||||
| supportedInstallModes: []v1alpha1.InstallModeType{v1alpha1.InstallModeTypeAllNamespaces, v1alpha1.InstallModeTypeOwnNamespace}, | ||||||
| rawConfig: []byte(`{}`), | ||||||
| installNamespace: "not-some-namespace", | ||||||
| expectedConfig: &bundle.Config{ | ||||||
| WatchNamespace: nil, | ||||||
| }, | ||||||
| }, | ||||||
| { | ||||||
| name: "accepts no watchNamespace when install modes {AllNamespaces, OwnNamespace, MultiNamespace} and watchNamespace is nil", | ||||||
| supportedInstallModes: []v1alpha1.InstallModeType{v1alpha1.InstallModeTypeAllNamespaces, v1alpha1.InstallModeTypeOwnNamespace, v1alpha1.InstallModeTypeMultiNamespace}, | ||||||
| rawConfig: []byte(`{}`), | ||||||
| installNamespace: "not-some-namespace", | ||||||
| expectedConfig: &bundle.Config{ | ||||||
| WatchNamespace: nil, | ||||||
| }, | ||||||
| }, | ||||||
| { | ||||||
| name: "rejects with format error when install modes are {SingleNamespace, OwnNamespace} and watchNamespace is ''", | ||||||
| supportedInstallModes: []v1alpha1.InstallModeType{v1alpha1.InstallModeTypeSingleNamespace, v1alpha1.InstallModeTypeOwnNamespace}, | ||||||
|  | @@ -246,7 +297,7 @@ func Test_UnmarshallConfig(t *testing.T) { | |||||
| } | ||||||
| } | ||||||
|  | ||||||
| config, err := bundle.UnmarshallConfig(tc.rawConfig, rv1, tc.installNamespace) | ||||||
| config, err := bundle.UnmarshalConfig(tc.rawConfig, rv1, tc.installNamespace) | ||||||
| require.Equal(t, tc.expectedConfig, config) | ||||||
| if tc.expectedErrMessage != "" { | ||||||
| require.Error(t, err) | ||||||
|  | ||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding an install mode and having unique errors, not only to make it easier to understand but also to make troubleshooting easier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to surface install mode concerns through the errors. Treat it as configuration.