-
Notifications
You must be signed in to change notification settings - Fork 71
✨Extract and pass deploymentConfig to bundle renderer #2482
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
Merged
anik120
merged 1 commit into
operator-framework:main
from
anik120:config-api-controller-integration
Feb 3, 2026
+268
−10
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -444,6 +444,218 @@ func Test_RegistryV1ManifestProvider_SingleOwnNamespaceSupport(t *testing.T) { | |
| }) | ||
| } | ||
|
|
||
| func Test_RegistryV1ManifestProvider_DeploymentConfig(t *testing.T) { | ||
| t.Run("passes deploymentConfig to renderer when provided in configuration", func(t *testing.T) { | ||
| expectedEnvVars := []corev1.EnvVar{ | ||
| {Name: "TEST_ENV", Value: "test-value"}, | ||
| } | ||
| provider := applier.RegistryV1ManifestProvider{ | ||
| BundleRenderer: render.BundleRenderer{ | ||
| ResourceGenerators: []render.ResourceGenerator{ | ||
| func(rv1 *bundle.RegistryV1, opts render.Options) ([]client.Object, error) { | ||
| t.Log("ensure deploymentConfig is passed to renderer") | ||
| require.NotNil(t, opts.DeploymentConfig) | ||
| require.Equal(t, expectedEnvVars, opts.DeploymentConfig.Env) | ||
| return nil, nil | ||
| }, | ||
| }, | ||
| }, | ||
| IsSingleOwnNamespaceEnabled: true, | ||
| } | ||
|
|
||
| bundleFS := bundlefs.Builder().WithPackageName("test"). | ||
| WithCSV(clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).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(`{"deploymentConfig": {"env": [{"name": "TEST_ENV", "value": "test-value"}]}}`), | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| require.NoError(t, err) | ||
| }) | ||
|
|
||
| t.Run("does not pass deploymentConfig to renderer when not provided in configuration", func(t *testing.T) { | ||
| provider := applier.RegistryV1ManifestProvider{ | ||
| BundleRenderer: render.BundleRenderer{ | ||
| ResourceGenerators: []render.ResourceGenerator{ | ||
| func(rv1 *bundle.RegistryV1, opts render.Options) ([]client.Object, error) { | ||
| t.Log("ensure deploymentConfig is nil when not provided") | ||
| require.Nil(t, opts.DeploymentConfig) | ||
| return nil, nil | ||
| }, | ||
| }, | ||
| }, | ||
| IsSingleOwnNamespaceEnabled: true, | ||
| } | ||
|
|
||
| bundleFS := bundlefs.Builder().WithPackageName("test"). | ||
| WithCSV(clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build()).Build() | ||
|
|
||
| _, err := provider.Get(bundleFS, &ocv1.ClusterExtension{ | ||
| Spec: ocv1.ClusterExtensionSpec{ | ||
| Namespace: "install-namespace", | ||
| // No config provided | ||
| }, | ||
| }) | ||
| require.NoError(t, err) | ||
| }) | ||
|
|
||
| t.Run("passes deploymentConfig with multiple fields to renderer", func(t *testing.T) { | ||
| expectedNodeSelector := map[string]string{"kubernetes.io/os": "linux"} | ||
| expectedTolerations := []corev1.Toleration{ | ||
| {Key: "key1", Operator: "Equal", Value: "value1", Effect: "NoSchedule"}, | ||
| } | ||
| provider := applier.RegistryV1ManifestProvider{ | ||
| BundleRenderer: render.BundleRenderer{ | ||
| ResourceGenerators: []render.ResourceGenerator{ | ||
| func(rv1 *bundle.RegistryV1, opts render.Options) ([]client.Object, error) { | ||
| t.Log("ensure all deploymentConfig fields are passed to renderer") | ||
| require.NotNil(t, opts.DeploymentConfig) | ||
| require.Equal(t, expectedNodeSelector, opts.DeploymentConfig.NodeSelector) | ||
| require.Equal(t, expectedTolerations, opts.DeploymentConfig.Tolerations) | ||
| return nil, nil | ||
| }, | ||
| }, | ||
| }, | ||
| IsSingleOwnNamespaceEnabled: true, | ||
| } | ||
|
|
||
| bundleFS := bundlefs.Builder().WithPackageName("test"). | ||
| WithCSV(clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).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(`{ | ||
| "deploymentConfig": { | ||
| "nodeSelector": {"kubernetes.io/os": "linux"}, | ||
| "tolerations": [{"key": "key1", "operator": "Equal", "value": "value1", "effect": "NoSchedule"}] | ||
| } | ||
| }`), | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| require.NoError(t, err) | ||
| }) | ||
|
|
||
| t.Run("passes both watchNamespace and deploymentConfig when both provided", func(t *testing.T) { | ||
| expectedWatchNamespace := "some-namespace" | ||
| expectedEnvVars := []corev1.EnvVar{ | ||
| {Name: "TEST_ENV", Value: "test-value"}, | ||
| } | ||
| provider := applier.RegistryV1ManifestProvider{ | ||
| BundleRenderer: render.BundleRenderer{ | ||
| ResourceGenerators: []render.ResourceGenerator{ | ||
| func(rv1 *bundle.RegistryV1, opts render.Options) ([]client.Object, error) { | ||
| t.Log("ensure both watchNamespace and deploymentConfig are passed to renderer") | ||
| require.Equal(t, []string{expectedWatchNamespace}, opts.TargetNamespaces) | ||
| require.NotNil(t, opts.DeploymentConfig) | ||
| require.Equal(t, expectedEnvVars, opts.DeploymentConfig.Env) | ||
| return nil, nil | ||
| }, | ||
| }, | ||
| }, | ||
| IsSingleOwnNamespaceEnabled: true, | ||
| } | ||
|
|
||
| bundleFS := bundlefs.Builder().WithPackageName("test"). | ||
| WithCSV(clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeSingleNamespace).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": "some-namespace", | ||
| "deploymentConfig": { | ||
| "env": [{"name": "TEST_ENV", "value": "test-value"}] | ||
| } | ||
| }`), | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| require.NoError(t, err) | ||
| }) | ||
|
|
||
| t.Run("handles empty deploymentConfig gracefully", func(t *testing.T) { | ||
| provider := applier.RegistryV1ManifestProvider{ | ||
| BundleRenderer: render.BundleRenderer{ | ||
| ResourceGenerators: []render.ResourceGenerator{ | ||
| func(rv1 *bundle.RegistryV1, opts render.Options) ([]client.Object, error) { | ||
| t.Log("ensure deploymentConfig is nil for empty config object") | ||
| require.Nil(t, opts.DeploymentConfig) | ||
|
Contributor
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. Although, you do seem to test it here. |
||
| return nil, nil | ||
| }, | ||
| }, | ||
| }, | ||
| IsSingleOwnNamespaceEnabled: true, | ||
| } | ||
|
|
||
| bundleFS := bundlefs.Builder().WithPackageName("test"). | ||
| WithCSV(clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).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(`{"deploymentConfig": {}}`), | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| require.NoError(t, err) | ||
| }) | ||
|
|
||
| t.Run("returns terminal error when deploymentConfig has invalid structure", func(t *testing.T) { | ||
| provider := applier.RegistryV1ManifestProvider{ | ||
| BundleRenderer: render.BundleRenderer{ | ||
| ResourceGenerators: []render.ResourceGenerator{ | ||
| func(rv1 *bundle.RegistryV1, opts render.Options) ([]client.Object, error) { | ||
| return nil, nil | ||
| }, | ||
| }, | ||
| }, | ||
| IsSingleOwnNamespaceEnabled: true, | ||
| } | ||
|
|
||
| bundleFS := bundlefs.Builder().WithPackageName("test"). | ||
| WithCSV(clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build()).Build() | ||
|
|
||
| // Provide deploymentConfig with invalid structure - env should be array, not string | ||
| // Schema validation catches this before conversion | ||
| _, err := provider.Get(bundleFS, &ocv1.ClusterExtension{ | ||
| Spec: ocv1.ClusterExtensionSpec{ | ||
| Namespace: "install-namespace", | ||
| Config: &ocv1.ClusterExtensionConfig{ | ||
| ConfigType: ocv1.ClusterExtensionConfigTypeInline, | ||
| Inline: &apiextensionsv1.JSON{ | ||
| Raw: []byte(`{"deploymentConfig": {"env": "not-an-array"}}`), | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| require.Error(t, err) | ||
| require.Contains(t, err.Error(), "invalid ClusterExtension configuration") | ||
| require.Contains(t, err.Error(), "deploymentConfig.env") | ||
| require.ErrorIs(t, err, reconcile.TerminalError(nil), "config validation errors should be terminal") | ||
| }) | ||
| } | ||
|
|
||
| func Test_RegistryV1HelmChartProvider_Integration(t *testing.T) { | ||
| t.Run("surfaces bundle source errors", func(t *testing.T) { | ||
| provider := applier.RegistryV1HelmChartProvider{ | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 happens when deploymentConfig is nil (i.e. first return case. of
return nil, nil?