diff --git a/internal/operator-controller/applier/boxcutter_test.go b/internal/operator-controller/applier/boxcutter_test.go index 71187ec9c..cd38ac5ed 100644 --- a/internal/operator-controller/applier/boxcutter_test.go +++ b/internal/operator-controller/applier/boxcutter_test.go @@ -32,8 +32,8 @@ import ( "github.com/operator-framework/operator-controller/internal/operator-controller/labels" "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle" "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render" - testutils "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing" "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/bundlefs" + "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/clusterserviceversion" ) func Test_RegistryV1BundleRenderer_Render_Success(t *testing.T) { @@ -57,8 +57,8 @@ func Test_RegistryV1BundleRenderer_Render_Success(t *testing.T) { } bundleFS := bundlefs.Builder(). WithPackageName("some-package"). - WithCSV(testutils.MakeCSV(testutils.WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces))).Build() - + WithCSV(clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build()). + Build() objs, err := r.Render(bundleFS, &ocv1.ClusterExtension{ Spec: ocv1.ClusterExtensionSpec{ Namespace: "some-namespace", @@ -81,8 +81,8 @@ func Test_RegistryV1BundleRenderer_Render_Failure(t *testing.T) { } bundleFS := bundlefs.Builder(). WithPackageName("some-package"). - WithCSV(testutils.MakeCSV(testutils.WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces))).Build() - + WithCSV(clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build()). + Build() objs, err := r.Render(bundleFS, &ocv1.ClusterExtension{ Spec: ocv1.ClusterExtensionSpec{ Namespace: "some-namespace", diff --git a/internal/operator-controller/applier/provider_test.go b/internal/operator-controller/applier/provider_test.go index b1345dd30..74795f544 100644 --- a/internal/operator-controller/applier/provider_test.go +++ b/internal/operator-controller/applier/provider_test.go @@ -21,6 +21,7 @@ import ( "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle/source" "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render" . "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing" + "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/clusterserviceversion" ) func Test_RegistryV1HelmChartProvider_Get_ReturnsBundleSourceFailures(t *testing.T) { @@ -51,7 +52,7 @@ func Test_RegistryV1HelmChartProvider_Get_ReturnsBundleRendererFailures(t *testi b := source.FromBundle( bundle.RegistryV1{ - CSV: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces)), + CSV: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build(), }, ) @@ -70,7 +71,7 @@ func Test_RegistryV1HelmChartProvider_Get_NoAPIServiceDefinitions(t *testing.T) b := source.FromBundle( bundle.RegistryV1{ - CSV: MakeCSV(WithOwnedAPIServiceDescriptions(v1alpha1.APIServiceDescription{})), + CSV: clusterserviceversion.Builder().WithOwnedAPIServiceDescriptions(v1alpha1.APIServiceDescription{}).Build(), }, ) @@ -91,7 +92,7 @@ func Test_RegistryV1HelmChartProvider_Get_SingleOwnNamespace(t *testing.T) { b := source.FromBundle( bundle.RegistryV1{ - CSV: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeOwnNamespace)), + CSV: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeOwnNamespace).Build(), }, ) @@ -114,7 +115,7 @@ func Test_RegistryV1HelmChartProvider_Get_SingleOwnNamespace(t *testing.T) { b := source.FromBundle( bundle.RegistryV1{ - CSV: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeSingleNamespace)), + CSV: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeSingleNamespace).Build(), }, ) @@ -142,7 +143,7 @@ func Test_RegistryV1HelmChartProvider_Get_SingleOwnNamespace(t *testing.T) { b := source.FromBundle( bundle.RegistryV1{ - CSV: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeOwnNamespace)), + CSV: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeOwnNamespace).Build(), }, ) @@ -164,7 +165,7 @@ func Test_RegistryV1HelmChartProvider_Get_NoWebhooksWithoutCertProvider(t *testi b := source.FromBundle( bundle.RegistryV1{ - CSV: MakeCSV(WithWebhookDefinitions(v1alpha1.WebhookDescription{})), + CSV: clusterserviceversion.Builder().WithWebhookDefinitions(v1alpha1.WebhookDescription{}).Build(), }, ) @@ -186,7 +187,7 @@ func Test_RegistryV1HelmChartProvider_Get_WebhooksSupportDisabled(t *testing.T) b := source.FromBundle( bundle.RegistryV1{ - CSV: MakeCSV(WithWebhookDefinitions(v1alpha1.WebhookDescription{})), + CSV: clusterserviceversion.Builder().WithWebhookDefinitions(v1alpha1.WebhookDescription{}).Build(), }, ) @@ -209,10 +210,9 @@ func Test_RegistryV1HelmChartProvider_Get_WebhooksWithCertProvider(t *testing.T) b := source.FromBundle( bundle.RegistryV1{ - CSV: MakeCSV( - WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces), - WithWebhookDefinitions(v1alpha1.WebhookDescription{}), - ), + CSV: clusterserviceversion.Builder(). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces). + WithWebhookDefinitions(v1alpha1.WebhookDescription{}).Build(), }, ) @@ -245,7 +245,7 @@ func Test_RegistryV1HelmChartProvider_Get_BundleRendererIntegration(t *testing.T b := source.FromBundle( bundle.RegistryV1{ - CSV: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces, v1alpha1.InstallModeTypeSingleNamespace)), + CSV: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces, v1alpha1.InstallModeTypeSingleNamespace).Build(), }, ) @@ -315,10 +315,9 @@ func Test_RegistryV1HelmChartProvider_Get_Success(t *testing.T) { b := source.FromBundle( bundle.RegistryV1{ - CSV: MakeCSV( - WithAnnotations(map[string]string{"foo": "bar"}), - WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces), - ), + CSV: clusterserviceversion.Builder(). + WithAnnotations(map[string]string{"foo": "bar"}). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build(), Others: []unstructured.Unstructured{ *ToUnstructuredT(t, &corev1.Service{ TypeMeta: metav1.TypeMeta{ diff --git a/internal/operator-controller/rukpak/bundle/source/source_test.go b/internal/operator-controller/rukpak/bundle/source/source_test.go index 5acd9f065..45ccafd0d 100644 --- a/internal/operator-controller/rukpak/bundle/source/source_test.go +++ b/internal/operator-controller/rukpak/bundle/source/source_test.go @@ -13,8 +13,8 @@ import ( "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle" "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle/source" - testutils "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing" "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/bundlefs" + "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/clusterserviceversion" ) const ( @@ -34,13 +34,13 @@ func Test_FromFS_Success(t *testing.T) { bundleFS := bundlefs.Builder(). WithPackageName("test"). WithBundleProperty("from-file-key", "from-file-value"). - WithBundleResource("csv.yaml", ptr.To(testutils.MakeCSV( - testutils.WithName("test.v1.0.0"), - testutils.WithAnnotations(map[string]string{ + WithBundleResource("csv.yaml", ptr.To(clusterserviceversion.Builder(). + WithName("test.v1.0.0"). + WithAnnotations(map[string]string{ "olm.properties": `[{"type":"from-csv-annotations-key", "value":"from-csv-annotations-value"}]`, - }), - testutils.WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces)), - )).Build() + }). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build())). + Build() rv1, err := source.FromFS(bundleFS).GetBundle() require.NoError(t, err) @@ -72,12 +72,12 @@ func Test_FromFS_Fails(t *testing.T) { name: "bundle missing metadata/annotations.yaml", FS: bundlefs.Builder(). WithBundleProperty("foo", "bar"). - WithBundleResource("csv.yaml", ptr.To(testutils.MakeCSV())).Build(), + WithBundleResource("csv.yaml", ptr.To(clusterserviceversion.Builder().Build())).Build(), }, { name: "metadata/annotations.yaml missing package name annotation", FS: bundlefs.Builder(). WithBundleProperty("foo", "bar"). - WithBundleResource("csv.yaml", ptr.To(testutils.MakeCSV())).Build(), + WithBundleResource("csv.yaml", ptr.To(clusterserviceversion.Builder().Build())).Build(), }, { name: "bundle missing manifests directory", FS: bundlefs.Builder(). diff --git a/internal/operator-controller/rukpak/render/registryv1/generators/generators_test.go b/internal/operator-controller/rukpak/render/registryv1/generators/generators_test.go index 8176795db..59be3c6df 100644 --- a/internal/operator-controller/rukpak/render/registryv1/generators/generators_test.go +++ b/internal/operator-controller/rukpak/render/registryv1/generators/generators_test.go @@ -24,6 +24,7 @@ import ( "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render" "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render/registryv1/generators" . "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing" + "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/clusterserviceversion" ) func Test_ResourceGenerators(t *testing.T) { @@ -67,10 +68,10 @@ func Test_BundleCSVDeploymentGenerator_Succeeds(t *testing.T) { { name: "generates deployment resources", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithAnnotations(map[string]string{ "csv": "annotation", - }), + }). WithStrategyDeploymentSpecs( v1alpha1.StrategyDeploymentSpec{ Name: "deployment-one", @@ -94,8 +95,7 @@ func Test_BundleCSVDeploymentGenerator_Succeeds(t *testing.T) { Name: "deployment-two", Spec: appsv1.DeploymentSpec{}, }, - ), - ), + ).Build(), }, opts: render.Options{ InstallNamespace: "install-namespace", @@ -174,12 +174,12 @@ func Test_BundleCSVDeploymentGenerator_WithCertWithCertProvider_Succeeds(t *test } b := &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, DeploymentName: "deployment-one", - }), + }). // deployment must have a referencing webhook (or owned apiservice) definition to trigger cert secret WithStrategyDeploymentSpecs( v1alpha1.StrategyDeploymentSpec{ @@ -252,8 +252,7 @@ func Test_BundleCSVDeploymentGenerator_WithCertWithCertProvider_Succeeds(t *test }, }, }, - ), - ), + ).Build(), } objs, err := generators.BundleCSVDeploymentGenerator(b, render.Options{ @@ -370,8 +369,8 @@ func Test_BundleCSVPermissionsGenerator_Succeeds(t *testing.T) { UniqueNameGenerator: fakeUniqueNameGenerator, }, bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithName("csv"), + CSV: clusterserviceversion.Builder(). + WithName("csv"). WithPermissions( v1alpha1.StrategyDeploymentPermissions{ ServiceAccountName: "service-account-one", @@ -383,8 +382,7 @@ func Test_BundleCSVPermissionsGenerator_Succeeds(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, expectedResources: nil, }, @@ -396,8 +394,8 @@ func Test_BundleCSVPermissionsGenerator_Succeeds(t *testing.T) { UniqueNameGenerator: fakeUniqueNameGenerator, }, bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithName("csv"), + CSV: clusterserviceversion.Builder(). + WithName("csv"). WithPermissions( v1alpha1.StrategyDeploymentPermissions{ ServiceAccountName: "service-account-one", @@ -413,8 +411,7 @@ func Test_BundleCSVPermissionsGenerator_Succeeds(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, expectedResources: []client.Object{ &rbacv1.Role{ @@ -471,8 +468,8 @@ func Test_BundleCSVPermissionsGenerator_Succeeds(t *testing.T) { UniqueNameGenerator: fakeUniqueNameGenerator, }, bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithName("csv"), + CSV: clusterserviceversion.Builder(). + WithName("csv"). WithPermissions( v1alpha1.StrategyDeploymentPermissions{ ServiceAccountName: "service-account-one", @@ -488,8 +485,7 @@ func Test_BundleCSVPermissionsGenerator_Succeeds(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, expectedResources: []client.Object{ &rbacv1.Role{ @@ -590,8 +586,8 @@ func Test_BundleCSVPermissionsGenerator_Succeeds(t *testing.T) { UniqueNameGenerator: fakeUniqueNameGenerator, }, bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithName("csv"), + CSV: clusterserviceversion.Builder(). + WithName("csv"). WithPermissions( v1alpha1.StrategyDeploymentPermissions{ ServiceAccountName: "service-account-one", @@ -613,8 +609,7 @@ func Test_BundleCSVPermissionsGenerator_Succeeds(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, expectedResources: []client.Object{ &rbacv1.Role{ @@ -707,8 +702,8 @@ func Test_BundleCSVPermissionsGenerator_Succeeds(t *testing.T) { UniqueNameGenerator: fakeUniqueNameGenerator, }, bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithName("csv"), + CSV: clusterserviceversion.Builder(). + WithName("csv"). WithPermissions( v1alpha1.StrategyDeploymentPermissions{ ServiceAccountName: "", @@ -720,8 +715,7 @@ func Test_BundleCSVPermissionsGenerator_Succeeds(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, expectedResources: []client.Object{ &rbacv1.Role{ @@ -804,8 +798,8 @@ func Test_BundleCSVClusterPermissionsGenerator_Succeeds(t *testing.T) { UniqueNameGenerator: fakeUniqueNameGenerator, }, bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithName("csv"), + CSV: clusterserviceversion.Builder(). + WithName("csv"). WithPermissions( v1alpha1.StrategyDeploymentPermissions{ ServiceAccountName: "service-account-one", @@ -827,8 +821,7 @@ func Test_BundleCSVClusterPermissionsGenerator_Succeeds(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, expectedResources: []client.Object{ &rbacv1.ClusterRole{ @@ -925,8 +918,8 @@ func Test_BundleCSVClusterPermissionsGenerator_Succeeds(t *testing.T) { UniqueNameGenerator: fakeUniqueNameGenerator, }, bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithName("csv"), + CSV: clusterserviceversion.Builder(). + WithName("csv"). WithClusterPermissions( v1alpha1.StrategyDeploymentPermissions{ ServiceAccountName: "service-account-one", @@ -948,8 +941,7 @@ func Test_BundleCSVClusterPermissionsGenerator_Succeeds(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, expectedResources: []client.Object{ &rbacv1.ClusterRole{ @@ -1038,8 +1030,8 @@ func Test_BundleCSVClusterPermissionsGenerator_Succeeds(t *testing.T) { UniqueNameGenerator: fakeUniqueNameGenerator, }, bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithName("csv"), + CSV: clusterserviceversion.Builder(). + WithName("csv"). WithClusterPermissions( v1alpha1.StrategyDeploymentPermissions{ ServiceAccountName: "", @@ -1051,8 +1043,7 @@ func Test_BundleCSVClusterPermissionsGenerator_Succeeds(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, expectedResources: []client.Object{ &rbacv1.ClusterRole{ @@ -1127,8 +1118,8 @@ func Test_BundleCSVServiceAccountGenerator_Succeeds(t *testing.T) { InstallNamespace: "install-namespace", }, bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithName("csv"), + CSV: clusterserviceversion.Builder(). + WithName("csv"). WithPermissions( v1alpha1.StrategyDeploymentPermissions{ ServiceAccountName: "service-account-1", @@ -1150,7 +1141,7 @@ func Test_BundleCSVServiceAccountGenerator_Succeeds(t *testing.T) { }, }, }, - ), + ). WithClusterPermissions( v1alpha1.StrategyDeploymentPermissions{ ServiceAccountName: "service-account-2", @@ -1172,8 +1163,7 @@ func Test_BundleCSVServiceAccountGenerator_Succeeds(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, expectedResources: []client.Object{ &corev1.ServiceAccount{ @@ -1214,8 +1204,8 @@ func Test_BundleCSVServiceAccountGenerator_Succeeds(t *testing.T) { InstallNamespace: "install-namespace", }, bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithName("csv"), + CSV: clusterserviceversion.Builder(). + WithName("csv"). WithPermissions( v1alpha1.StrategyDeploymentPermissions{ ServiceAccountName: "", @@ -1227,7 +1217,7 @@ func Test_BundleCSVServiceAccountGenerator_Succeeds(t *testing.T) { }, }, }, - ), + ). WithClusterPermissions( v1alpha1.StrategyDeploymentPermissions{ ServiceAccountName: "", @@ -1239,8 +1229,7 @@ func Test_BundleCSVServiceAccountGenerator_Succeeds(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, expectedResources: nil, }, @@ -1298,7 +1287,7 @@ func Test_BundleCRDGenerator_WithConversionWebhook_Succeeds(t *testing.T) { {ObjectMeta: metav1.ObjectMeta{Name: "crd-one"}}, {ObjectMeta: metav1.ObjectMeta{Name: "crd-two"}}, }, - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ConversionWebhook, @@ -1316,8 +1305,7 @@ func Test_BundleCRDGenerator_WithConversionWebhook_Succeeds(t *testing.T) { ConversionCRDs: []string{"crd-two"}, DeploymentName: "some-deployment", }, - ), - ), + ).Build(), } objs, err := generators.BundleCRDGenerator(bundle, opts) @@ -1383,7 +1371,7 @@ func Test_BundleCRDGenerator_WithConversionWebhook_Fails(t *testing.T) { }, }, }, - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ConversionWebhook, @@ -1393,8 +1381,7 @@ func Test_BundleCRDGenerator_WithConversionWebhook_Fails(t *testing.T) { ConversionCRDs: []string{"crd-one"}, DeploymentName: "some-deployment", }, - ), - ), + ).Build(), } objs, err := generators.BundleCRDGenerator(bundle, opts) @@ -1424,7 +1411,7 @@ func Test_BundleCRDGenerator_WithCertProvider_Succeeds(t *testing.T) { {ObjectMeta: metav1.ObjectMeta{Name: "crd-one"}}, {ObjectMeta: metav1.ObjectMeta{Name: "crd-two"}}, }, - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ConversionWebhook, @@ -1433,8 +1420,7 @@ func Test_BundleCRDGenerator_WithCertProvider_Succeeds(t *testing.T) { "crd-one", }, }, - ), - ), + ).Build(), } objs, err := generators.BundleCRDGenerator(bundle, opts) @@ -1514,7 +1500,7 @@ func Test_BundleValidatingWebhookResourceGenerator_Succeeds(t *testing.T) { { name: "generates validating webhook configuration resources described in the bundle's cluster service version", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -1547,8 +1533,7 @@ func Test_BundleValidatingWebhookResourceGenerator_Succeeds(t *testing.T) { WebhookPath: ptr.To("/webhook-path"), ContainerPort: 443, }, - ), - ), + ).Build(), }, opts: render.Options{ InstallNamespace: "install-namespace", @@ -1608,7 +1593,7 @@ func Test_BundleValidatingWebhookResourceGenerator_Succeeds(t *testing.T) { { name: "removes any - suffixes from the webhook name (v0 used GenerateName to allow multiple operator installations - we don't want that in v1)", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -1641,8 +1626,7 @@ func Test_BundleValidatingWebhookResourceGenerator_Succeeds(t *testing.T) { WebhookPath: ptr.To("/webhook-path"), ContainerPort: 443, }, - ), - ), + ).Build(), }, opts: render.Options{ InstallNamespace: "install-namespace", @@ -1710,7 +1694,7 @@ func Test_BundleValidatingWebhookResourceGenerator_Succeeds(t *testing.T) { { name: "generates validating webhook configuration resources with certificate provider modifications", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -1718,8 +1702,7 @@ func Test_BundleValidatingWebhookResourceGenerator_Succeeds(t *testing.T) { DeploymentName: "my-deployment", ContainerPort: 443, }, - ), - ), + ).Build(), }, opts: render.Options{ InstallNamespace: "install-namespace", @@ -1797,7 +1780,7 @@ func Test_BundleMutatingWebhookResourceGenerator_Succeeds(t *testing.T) { { name: "generates validating webhook configuration resources described in the bundle's cluster service version", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.MutatingAdmissionWebhook, @@ -1831,8 +1814,7 @@ func Test_BundleMutatingWebhookResourceGenerator_Succeeds(t *testing.T) { ContainerPort: 443, ReinvocationPolicy: ptr.To(admissionregistrationv1.IfNeededReinvocationPolicy), }, - ), - ), + ).Build(), }, opts: render.Options{ InstallNamespace: "install-namespace", @@ -1893,7 +1875,7 @@ func Test_BundleMutatingWebhookResourceGenerator_Succeeds(t *testing.T) { { name: "removes any - suffixes from the webhook name (v0 used GenerateName to allow multiple operator installations - we don't want that in v1)", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.MutatingAdmissionWebhook, @@ -1927,8 +1909,7 @@ func Test_BundleMutatingWebhookResourceGenerator_Succeeds(t *testing.T) { ContainerPort: 443, ReinvocationPolicy: ptr.To(admissionregistrationv1.IfNeededReinvocationPolicy), }, - ), - ), + ).Build(), }, opts: render.Options{ InstallNamespace: "install-namespace", @@ -1997,7 +1978,7 @@ func Test_BundleMutatingWebhookResourceGenerator_Succeeds(t *testing.T) { { name: "generates validating webhook configuration resources with certificate provider modifications", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.MutatingAdmissionWebhook, @@ -2005,8 +1986,7 @@ func Test_BundleMutatingWebhookResourceGenerator_Succeeds(t *testing.T) { DeploymentName: "my-deployment", ContainerPort: 443, }, - ), - ), + ).Build(), }, opts: render.Options{ InstallNamespace: "install-namespace", @@ -2084,18 +2064,17 @@ func Test_BundleDeploymentServiceResourceGenerator_Succeeds(t *testing.T) { { name: "generates webhook services using container port 443 and target port 443 by default", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithStrategyDeploymentSpecs( v1alpha1.StrategyDeploymentSpec{ Name: "my-deployment", - }), + }). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.MutatingAdmissionWebhook, DeploymentName: "my-deployment", }, - ), - ), + ).Build(), }, opts: render.Options{ InstallNamespace: "install-namespace", @@ -2129,19 +2108,18 @@ func Test_BundleDeploymentServiceResourceGenerator_Succeeds(t *testing.T) { { name: "generates webhook services using the given container port and setting target port the same as the container port if not given", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithStrategyDeploymentSpecs( v1alpha1.StrategyDeploymentSpec{ Name: "my-deployment", - }), + }). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, DeploymentName: "my-deployment", ContainerPort: int32(8443), }, - ), - ), + ).Build(), }, opts: render.Options{ InstallNamespace: "install-namespace", @@ -2175,11 +2153,11 @@ func Test_BundleDeploymentServiceResourceGenerator_Succeeds(t *testing.T) { { name: "generates webhook services using given container port of 443 and given target port", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithStrategyDeploymentSpecs( v1alpha1.StrategyDeploymentSpec{ Name: "my-deployment", - }), + }). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ConversionWebhook, @@ -2189,8 +2167,7 @@ func Test_BundleDeploymentServiceResourceGenerator_Succeeds(t *testing.T) { IntVal: 8080, }, }, - ), - ), + ).Build(), }, opts: render.Options{ InstallNamespace: "install-namespace", @@ -2224,11 +2201,11 @@ func Test_BundleDeploymentServiceResourceGenerator_Succeeds(t *testing.T) { { name: "generates webhook services using given container port and target port", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithStrategyDeploymentSpecs( v1alpha1.StrategyDeploymentSpec{ Name: "my-deployment", - }), + }). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ConversionWebhook, @@ -2239,8 +2216,7 @@ func Test_BundleDeploymentServiceResourceGenerator_Succeeds(t *testing.T) { IntVal: 9099, }, }, - ), - ), + ).Build(), }, opts: render.Options{ InstallNamespace: "install-namespace", @@ -2274,7 +2250,7 @@ func Test_BundleDeploymentServiceResourceGenerator_Succeeds(t *testing.T) { { name: "generates webhook services using referenced deployment defined label selector", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithStrategyDeploymentSpecs( v1alpha1.StrategyDeploymentSpec{ Name: "my-deployment", @@ -2285,7 +2261,7 @@ func Test_BundleDeploymentServiceResourceGenerator_Succeeds(t *testing.T) { }, }, }, - }), + }). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ConversionWebhook, @@ -2296,8 +2272,7 @@ func Test_BundleDeploymentServiceResourceGenerator_Succeeds(t *testing.T) { IntVal: 9099, }, }, - ), - ), + ).Build(), }, opts: render.Options{ InstallNamespace: "install-namespace", @@ -2334,7 +2309,7 @@ func Test_BundleDeploymentServiceResourceGenerator_Succeeds(t *testing.T) { { name: "aggregates all webhook definitions referencing the same deployment into a single service", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithStrategyDeploymentSpecs( v1alpha1.StrategyDeploymentSpec{ Name: "my-deployment", @@ -2345,7 +2320,7 @@ func Test_BundleDeploymentServiceResourceGenerator_Succeeds(t *testing.T) { }, }, }, - }), + }). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.MutatingAdmissionWebhook, @@ -2373,8 +2348,7 @@ func Test_BundleDeploymentServiceResourceGenerator_Succeeds(t *testing.T) { IntVal: 9099, }, }, - ), - ), + ).Build(), }, opts: render.Options{ InstallNamespace: "install-namespace", @@ -2432,18 +2406,17 @@ func Test_BundleDeploymentServiceResourceGenerator_Succeeds(t *testing.T) { { name: "applies cert provider modifiers to webhook service", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithStrategyDeploymentSpecs( v1alpha1.StrategyDeploymentSpec{ Name: "my-deployment", - }), + }). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.MutatingAdmissionWebhook, DeploymentName: "my-deployment", }, - ), - ), + ).Build(), }, opts: render.Options{ InstallNamespace: "install-namespace", @@ -2507,14 +2480,14 @@ func Test_CertProviderResourceGenerator_Succeeds(t *testing.T) { } objs, err := generators.CertProviderResourceGenerator(&bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( // only generate resources for deployments referenced by webhook definitions v1alpha1.WebhookDescription{ Type: v1alpha1.MutatingAdmissionWebhook, DeploymentName: "my-deployment", }, - ), + ). WithStrategyDeploymentSpecs( v1alpha1.StrategyDeploymentSpec{ Name: "my-deployment", @@ -2522,8 +2495,7 @@ func Test_CertProviderResourceGenerator_Succeeds(t *testing.T) { v1alpha1.StrategyDeploymentSpec{ Name: "my-other-deployment", }, - ), - ), + ).Build(), }, render.Options{ InstallNamespace: "install-namespace", CertificateProvider: fakeProvider, diff --git a/internal/operator-controller/rukpak/render/registryv1/registryv1_test.go b/internal/operator-controller/rukpak/render/registryv1/registryv1_test.go index afe19d805..b092cc8e1 100644 --- a/internal/operator-controller/rukpak/render/registryv1/registryv1_test.go +++ b/internal/operator-controller/rukpak/render/registryv1/registryv1_test.go @@ -17,6 +17,7 @@ import ( "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render/registryv1/generators" "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render/registryv1/validators" . "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing" + "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/clusterserviceversion" ) func Test_BundleValidatorHasAllValidationFns(t *testing.T) { @@ -64,12 +65,11 @@ func Test_ResourceGeneratorsHasAllGenerators(t *testing.T) { } func Test_Renderer_Success(t *testing.T) { - bundle := bundle.RegistryV1{ + someBundle := bundle.RegistryV1{ PackageName: "my-package", - CSV: MakeCSV( - WithName("test-bundle"), - WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces), - ), + CSV: clusterserviceversion.Builder(). + WithName("test-bundle"). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build(), Others: []unstructured.Unstructured{ *ToUnstructuredT(t, &corev1.Service{ TypeMeta: metav1.TypeMeta{ @@ -83,7 +83,7 @@ func Test_Renderer_Success(t *testing.T) { }, } - objs, err := registryv1.Renderer.Render(bundle, "install-namespace") + objs, err := registryv1.Renderer.Render(someBundle, "install-namespace") t.Log("Check renderer returns objects and no errors") require.NoError(t, err) require.NotEmpty(t, objs) @@ -98,12 +98,11 @@ func Test_Renderer_Success(t *testing.T) { } func Test_Renderer_Failure_UnsupportedKind(t *testing.T) { - bundle := bundle.RegistryV1{ + someBundle := bundle.RegistryV1{ PackageName: "my-package", - CSV: MakeCSV( - WithName("test-bundle"), - WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces), - ), + CSV: clusterserviceversion.Builder(). + WithName("test-bundle"). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build(), Others: []unstructured.Unstructured{ *ToUnstructuredT(t, &corev1.Event{ TypeMeta: metav1.TypeMeta{ @@ -117,7 +116,7 @@ func Test_Renderer_Failure_UnsupportedKind(t *testing.T) { }, } - objs, err := registryv1.Renderer.Render(bundle, "install-namespace") + objs, err := registryv1.Renderer.Render(someBundle, "install-namespace") t.Log("Check renderer returns objects and no errors") require.Error(t, err) require.Contains(t, err.Error(), "unsupported resource") diff --git a/internal/operator-controller/rukpak/render/registryv1/validators/validator_test.go b/internal/operator-controller/rukpak/render/registryv1/validators/validator_test.go index 135a942ec..b9377c81a 100644 --- a/internal/operator-controller/rukpak/render/registryv1/validators/validator_test.go +++ b/internal/operator-controller/rukpak/render/registryv1/validators/validator_test.go @@ -13,7 +13,7 @@ import ( "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle" "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render/registryv1/validators" - . "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing" + "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/clusterserviceversion" ) func Test_CheckDeploymentSpecUniqueness(t *testing.T) { @@ -25,24 +25,22 @@ func Test_CheckDeploymentSpecUniqueness(t *testing.T) { { name: "accepts bundles with unique deployment strategy spec names", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithStrategyDeploymentSpecs( v1alpha1.StrategyDeploymentSpec{Name: "test-deployment-one"}, v1alpha1.StrategyDeploymentSpec{Name: "test-deployment-two"}, - ), - ), + ).Build(), }, expectedErrs: []error{}, }, { name: "rejects bundles with duplicate deployment strategy spec names", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithStrategyDeploymentSpecs( v1alpha1.StrategyDeploymentSpec{Name: "test-deployment-one"}, v1alpha1.StrategyDeploymentSpec{Name: "test-deployment-two"}, v1alpha1.StrategyDeploymentSpec{Name: "test-deployment-one"}, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("cluster service version contains duplicate strategy deployment spec 'test-deployment-one'"), @@ -50,15 +48,14 @@ func Test_CheckDeploymentSpecUniqueness(t *testing.T) { }, { name: "errors are ordered by deployment strategy spec name", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithStrategyDeploymentSpecs( v1alpha1.StrategyDeploymentSpec{Name: "test-deployment-a"}, v1alpha1.StrategyDeploymentSpec{Name: "test-deployment-b"}, v1alpha1.StrategyDeploymentSpec{Name: "test-deployment-c"}, v1alpha1.StrategyDeploymentSpec{Name: "test-deployment-b"}, v1alpha1.StrategyDeploymentSpec{Name: "test-deployment-a"}, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("cluster service version contains duplicate strategy deployment spec 'test-deployment-a'"), @@ -82,24 +79,22 @@ func Test_CheckDeploymentNameIsDNS1123SubDomain(t *testing.T) { { name: "accepts valid deployment strategy spec names", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithStrategyDeploymentSpecs( v1alpha1.StrategyDeploymentSpec{Name: "test-deployment-one"}, v1alpha1.StrategyDeploymentSpec{Name: "test-deployment-two"}, - ), - ), + ).Build(), }, expectedErrs: []error{}, }, { name: "rejects bundles with invalid deployment strategy spec names - errors are sorted by name", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithStrategyDeploymentSpecs( v1alpha1.StrategyDeploymentSpec{Name: "-bad-name"}, v1alpha1.StrategyDeploymentSpec{Name: "b-name-is-waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay-too-long"}, v1alpha1.StrategyDeploymentSpec{Name: "a-name-is-waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay-too-long-and-bad-"}, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("invalid cluster service version strategy deployment name '-bad-name': a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')"), @@ -173,21 +168,19 @@ func Test_CheckOwnedCRDExistence(t *testing.T) { {ObjectMeta: metav1.ObjectMeta{Name: "a.crd.something"}}, {ObjectMeta: metav1.ObjectMeta{Name: "b.crd.something"}}, }, - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithOwnedCRDs( v1alpha1.CRDDescription{Name: "a.crd.something"}, v1alpha1.CRDDescription{Name: "b.crd.something"}, - ), - ), + ).Build(), }, expectedErrs: []error{}, }, { name: "rejects bundles with missing owned custom resource definition resources", bundle: &bundle.RegistryV1{ CRDs: []apiextensionsv1.CustomResourceDefinition{}, - CSV: MakeCSV( - WithOwnedCRDs(v1alpha1.CRDDescription{Name: "a.crd.something"}), - ), + CSV: clusterserviceversion.Builder(). + WithOwnedCRDs(v1alpha1.CRDDescription{Name: "a.crd.something"}).Build(), }, expectedErrs: []error{ errors.New("cluster service definition references owned custom resource definition 'a.crd.something' not found in bundle"), @@ -196,13 +189,12 @@ func Test_CheckOwnedCRDExistence(t *testing.T) { name: "errors are ordered by owned custom resource definition name", bundle: &bundle.RegistryV1{ CRDs: []apiextensionsv1.CustomResourceDefinition{}, - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithOwnedCRDs( v1alpha1.CRDDescription{Name: "a.crd.something"}, v1alpha1.CRDDescription{Name: "c.crd.something"}, v1alpha1.CRDDescription{Name: "b.crd.something"}, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("cluster service definition references owned custom resource definition 'a.crd.something' not found in bundle"), @@ -253,47 +245,44 @@ func Test_CheckWebhookSupport(t *testing.T) { { name: "accepts bundles with conversion webhook definitions when they only support AllNamespaces install mode", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces), + CSV: clusterserviceversion.Builder(). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ConversionWebhook, }, - ), - ), + ).Build(), }, }, { name: "accepts bundles with validating webhook definitions when they support more modes than AllNamespaces install mode", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces, v1alpha1.InstallModeTypeSingleNamespace), + CSV: clusterserviceversion.Builder(). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces, v1alpha1.InstallModeTypeSingleNamespace). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, }, - ), - ), + ).Build(), }, }, { name: "accepts bundles with mutating webhook definitions when they support more modes than AllNamespaces install mode", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces, v1alpha1.InstallModeTypeSingleNamespace), + CSV: clusterserviceversion.Builder(). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces, v1alpha1.InstallModeTypeSingleNamespace). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.MutatingAdmissionWebhook, }, - ), - ), + ).Build(), }, }, { name: "rejects bundles with conversion webhook definitions when they support more modes than AllNamespaces install mode", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithInstallModeSupportFor(v1alpha1.InstallModeTypeSingleNamespace, v1alpha1.InstallModeTypeAllNamespaces), + CSV: clusterserviceversion.Builder(). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeSingleNamespace, v1alpha1.InstallModeTypeAllNamespaces). WithWebhookDefinitions( v1alpha1.WebhookDescription{ GenerateName: "webhook-b", @@ -303,8 +292,7 @@ func Test_CheckWebhookSupport(t *testing.T) { GenerateName: "webhook-a", Type: v1alpha1.ConversionWebhook, }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("bundle contains conversion webhook \"webhook-b\" and supports install modes [AllNamespaces SingleNamespace] - conversion webhooks are only supported for bundles that only support AllNamespaces install mode"), @@ -328,8 +316,8 @@ func Test_CheckWebhookRules(t *testing.T) { { name: "accepts bundles with webhook definitions without rules", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces), + CSV: clusterserviceversion.Builder(). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -337,15 +325,14 @@ func Test_CheckWebhookRules(t *testing.T) { v1alpha1.WebhookDescription{ Type: v1alpha1.MutatingAdmissionWebhook, }, - ), - ), + ).Build(), }, }, { name: "accepts bundles with webhook definitions with supported rules", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces), + CSV: clusterserviceversion.Builder(). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -369,15 +356,14 @@ func Test_CheckWebhookRules(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, }, { name: "reject bundles with webhook definitions with rules containing '*' api group", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces), + CSV: clusterserviceversion.Builder(). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -401,8 +387,7 @@ func Test_CheckWebhookRules(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("webhook \"webhook-z\" contains forbidden rule: admission webhook rules cannot reference API group \"*\""), @@ -412,8 +397,8 @@ func Test_CheckWebhookRules(t *testing.T) { { name: "reject bundles with webhook definitions with rules containing 'olm.operatorframework.io' api group", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces), + CSV: clusterserviceversion.Builder(). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -437,8 +422,7 @@ func Test_CheckWebhookRules(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("webhook \"webhook-z\" contains forbidden rule: admission webhook rules cannot reference API group \"olm.operatorframework.io\""), @@ -448,8 +432,8 @@ func Test_CheckWebhookRules(t *testing.T) { { name: "reject bundles with webhook definitions with rules containing 'admissionregistration.k8s.io' api group and '*' resource", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces), + CSV: clusterserviceversion.Builder(). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -463,8 +447,7 @@ func Test_CheckWebhookRules(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("webhook \"webhook-a\" contains forbidden rule: admission webhook rules cannot reference resource \"*\" for API group \"admissionregistration.k8s.io\""), @@ -473,8 +456,8 @@ func Test_CheckWebhookRules(t *testing.T) { { name: "reject bundles with webhook definitions with rules containing 'admissionregistration.k8s.io' api group and 'MutatingWebhookConfiguration' resource", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces), + CSV: clusterserviceversion.Builder(). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -488,8 +471,7 @@ func Test_CheckWebhookRules(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("webhook \"webhook-a\" contains forbidden rule: admission webhook rules cannot reference resource \"MutatingWebhookConfiguration\" for API group \"admissionregistration.k8s.io\""), @@ -498,8 +480,8 @@ func Test_CheckWebhookRules(t *testing.T) { { name: "reject bundles with webhook definitions with rules containing 'admissionregistration.k8s.io' api group and 'mutatingwebhookconfiguration' resource", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces), + CSV: clusterserviceversion.Builder(). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -513,8 +495,7 @@ func Test_CheckWebhookRules(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("webhook \"webhook-a\" contains forbidden rule: admission webhook rules cannot reference resource \"mutatingwebhookconfiguration\" for API group \"admissionregistration.k8s.io\""), @@ -523,8 +504,8 @@ func Test_CheckWebhookRules(t *testing.T) { { name: "reject bundles with webhook definitions with rules containing 'admissionregistration.k8s.io' api group and 'mutatingwebhookconfigurations' resource", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces), + CSV: clusterserviceversion.Builder(). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -538,8 +519,7 @@ func Test_CheckWebhookRules(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("webhook \"webhook-a\" contains forbidden rule: admission webhook rules cannot reference resource \"mutatingwebhookconfigurations\" for API group \"admissionregistration.k8s.io\""), @@ -548,8 +528,8 @@ func Test_CheckWebhookRules(t *testing.T) { { name: "reject bundles with webhook definitions with rules containing 'admissionregistration.k8s.io' api group and 'ValidatingWebhookConfiguration' resource", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces), + CSV: clusterserviceversion.Builder(). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -563,8 +543,7 @@ func Test_CheckWebhookRules(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("webhook \"webhook-a\" contains forbidden rule: admission webhook rules cannot reference resource \"ValidatingWebhookConfiguration\" for API group \"admissionregistration.k8s.io\""), @@ -573,8 +552,8 @@ func Test_CheckWebhookRules(t *testing.T) { { name: "reject bundles with webhook definitions with rules containing 'admissionregistration.k8s.io' api group and 'validatingwebhookconfiguration' resource", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces), + CSV: clusterserviceversion.Builder(). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -588,8 +567,7 @@ func Test_CheckWebhookRules(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("webhook \"webhook-a\" contains forbidden rule: admission webhook rules cannot reference resource \"validatingwebhookconfiguration\" for API group \"admissionregistration.k8s.io\""), @@ -598,8 +576,8 @@ func Test_CheckWebhookRules(t *testing.T) { { name: "reject bundles with webhook definitions with rules containing 'admissionregistration.k8s.io' api group and 'validatingwebhookconfigurations' resource", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( - WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces), + CSV: clusterserviceversion.Builder(). + WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -613,8 +591,7 @@ func Test_CheckWebhookRules(t *testing.T) { }, }, }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("webhook \"webhook-a\" contains forbidden rule: admission webhook rules cannot reference resource \"validatingwebhookconfigurations\" for API group \"admissionregistration.k8s.io\""), @@ -637,35 +614,33 @@ func Test_CheckWebhookDeploymentReferentialIntegrity(t *testing.T) { { name: "accepts bundles where webhook definitions reference existing strategy deployment specs", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithStrategyDeploymentSpecs( v1alpha1.StrategyDeploymentSpec{Name: "test-deployment-one"}, v1alpha1.StrategyDeploymentSpec{Name: "test-deployment-two"}, - ), + ). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.MutatingAdmissionWebhook, GenerateName: "test-webhook", DeploymentName: "test-deployment-one", }, - ), - ), + ).Build(), }, }, { name: "rejects bundles with webhook definitions that reference non-existing strategy deployment specs", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithStrategyDeploymentSpecs( v1alpha1.StrategyDeploymentSpec{Name: "test-deployment-one"}, - ), + ). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, GenerateName: "test-webhook", DeploymentName: "test-deployment-two", }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("webhook of type 'ValidatingAdmissionWebhook' with name 'test-webhook' references non-existent deployment 'test-deployment-two'"), @@ -673,10 +648,10 @@ func Test_CheckWebhookDeploymentReferentialIntegrity(t *testing.T) { }, { name: "errors are ordered by deployment strategy spec name, webhook type, and webhook name", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithStrategyDeploymentSpecs( v1alpha1.StrategyDeploymentSpec{Name: "test-deployment-one"}, - ), + ). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -706,8 +681,7 @@ func Test_CheckWebhookDeploymentReferentialIntegrity(t *testing.T) { GenerateName: "test-conv-webhook-c-a", DeploymentName: "test-deployment-c", }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("webhook of type 'MutatingAdmissionWebhook' with name 'test-mute-webhook-a' references non-existent deployment 'test-deployment-a'"), @@ -735,12 +709,12 @@ func Test_CheckWebhookNameUniqueness(t *testing.T) { { name: "accepts bundles without webhook definitions", bundle: &bundle.RegistryV1{ - CSV: MakeCSV(), + CSV: clusterserviceversion.Builder().Build(), }, }, { name: "accepts bundles with unique webhook names", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.MutatingAdmissionWebhook, @@ -761,13 +735,12 @@ func Test_CheckWebhookNameUniqueness(t *testing.T) { Type: v1alpha1.ConversionWebhook, GenerateName: "test-webhook-six", }, - ), - ), + ).Build(), }, }, { name: "accepts bundles with webhooks with the same name but different types", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.MutatingAdmissionWebhook, @@ -779,13 +752,12 @@ func Test_CheckWebhookNameUniqueness(t *testing.T) { Type: v1alpha1.ConversionWebhook, GenerateName: "test-webhook", }, - ), - ), + ).Build(), }, }, { name: "rejects bundles with duplicate validating webhook definitions", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -794,8 +766,7 @@ func Test_CheckWebhookNameUniqueness(t *testing.T) { Type: v1alpha1.ValidatingAdmissionWebhook, GenerateName: "test-webhook", }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("duplicate webhook 'test-webhook' of type 'ValidatingAdmissionWebhook'"), @@ -803,7 +774,7 @@ func Test_CheckWebhookNameUniqueness(t *testing.T) { }, { name: "rejects bundles with duplicate mutating webhook definitions", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.MutatingAdmissionWebhook, @@ -812,8 +783,7 @@ func Test_CheckWebhookNameUniqueness(t *testing.T) { Type: v1alpha1.MutatingAdmissionWebhook, GenerateName: "test-webhook", }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("duplicate webhook 'test-webhook' of type 'MutatingAdmissionWebhook'"), @@ -821,7 +791,7 @@ func Test_CheckWebhookNameUniqueness(t *testing.T) { }, { name: "rejects bundles with duplicate conversion webhook definitions", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ConversionWebhook, @@ -830,8 +800,7 @@ func Test_CheckWebhookNameUniqueness(t *testing.T) { Type: v1alpha1.ConversionWebhook, GenerateName: "test-webhook", }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("duplicate webhook 'test-webhook' of type 'ConversionWebhook'"), @@ -839,7 +808,7 @@ func Test_CheckWebhookNameUniqueness(t *testing.T) { }, { name: "orders errors by webhook type and name", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -882,8 +851,7 @@ func Test_CheckWebhookNameUniqueness(t *testing.T) { Type: v1alpha1.MutatingAdmissionWebhook, GenerateName: "test-mute-webhook-b", }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("duplicate webhook 'test-conv-webhook-a' of type 'ConversionWebhook'"), @@ -914,7 +882,7 @@ func Test_CheckConversionWebhooksReferenceOwnedCRDs(t *testing.T) { }, { name: "accepts bundles without conversion webhook definitions", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -924,17 +892,16 @@ func Test_CheckConversionWebhooksReferenceOwnedCRDs(t *testing.T) { Type: v1alpha1.MutatingAdmissionWebhook, GenerateName: "test-mute-webhook", }, - ), - ), + ).Build(), }, }, { name: "accepts bundles with conversion webhooks that reference owned CRDs", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithOwnedCRDs( v1alpha1.CRDDescription{Name: "some.crd.something"}, v1alpha1.CRDDescription{Name: "another.crd.something"}, - ), + ). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ConversionWebhook, @@ -944,16 +911,15 @@ func Test_CheckConversionWebhooksReferenceOwnedCRDs(t *testing.T) { "another.crd.something", }, }, - ), - ), + ).Build(), }, }, { name: "rejects bundles with conversion webhooks that reference existing CRDs that are not owned", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithOwnedCRDs( v1alpha1.CRDDescription{Name: "some.crd.something"}, - ), + ). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ConversionWebhook, @@ -963,8 +929,7 @@ func Test_CheckConversionWebhooksReferenceOwnedCRDs(t *testing.T) { "another.crd.something", }, }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("conversion webhook 'test-webhook' references custom resource definition 'another.crd.something' not owned bundle"), @@ -972,10 +937,10 @@ func Test_CheckConversionWebhooksReferenceOwnedCRDs(t *testing.T) { }, { name: "errors are ordered by webhook name and CRD name", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithOwnedCRDs( v1alpha1.CRDDescription{Name: "b.crd.something"}, - ), + ). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ConversionWebhook, @@ -998,8 +963,7 @@ func Test_CheckConversionWebhooksReferenceOwnedCRDs(t *testing.T) { "d.crd.something", }, }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("conversion webhook 'test-webhook-a' references custom resource definition 'a.crd.something' not owned bundle"), @@ -1030,7 +994,7 @@ func Test_CheckConversionWebhookCRDReferenceUniqueness(t *testing.T) { { name: "accepts bundles without conversion webhook definitions", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -1040,19 +1004,18 @@ func Test_CheckConversionWebhookCRDReferenceUniqueness(t *testing.T) { Type: v1alpha1.MutatingAdmissionWebhook, GenerateName: "test-mute-webhook", }, - ), - ), + ).Build(), }, expectedErrs: []error{}, }, { name: "accepts bundles with conversion webhooks that reference different CRDs", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithOwnedCRDs( v1alpha1.CRDDescription{Name: "some.crd.something"}, v1alpha1.CRDDescription{Name: "another.crd.something"}, - ), + ). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ConversionWebhook, @@ -1068,18 +1031,17 @@ func Test_CheckConversionWebhookCRDReferenceUniqueness(t *testing.T) { "another.crd.something", }, }, - ), - ), + ).Build(), }, expectedErrs: []error{}, }, { name: "rejects bundles with conversion webhooks that reference the same CRD", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithOwnedCRDs( v1alpha1.CRDDescription{Name: "some.crd.something"}, - ), + ). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ConversionWebhook, @@ -1095,8 +1057,7 @@ func Test_CheckConversionWebhookCRDReferenceUniqueness(t *testing.T) { "some.crd.something", }, }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("conversion webhooks [test-webhook,test-webhook-two] reference same custom resource definition 'some.crd.something'"), @@ -1105,10 +1066,10 @@ func Test_CheckConversionWebhookCRDReferenceUniqueness(t *testing.T) { { name: "errors are ordered by CRD name and webhook names", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithOwnedCRDs( v1alpha1.CRDDescription{Name: "b.crd.something"}, - ), + ). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ConversionWebhook, @@ -1133,8 +1094,7 @@ func Test_CheckConversionWebhookCRDReferenceUniqueness(t *testing.T) { "d.crd.something", }, }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("conversion webhooks [test-webhook-a,test-webhook-b] reference same custom resource definition 'a.crd.something'"), @@ -1159,12 +1119,12 @@ func Test_CheckWebhookNameIsDNS1123SubDomain(t *testing.T) { { name: "accepts bundles without webhook definitions", bundle: &bundle.RegistryV1{ - CSV: MakeCSV(), + CSV: clusterserviceversion.Builder().Build(), }, }, { name: "rejects bundles with invalid webhook definitions names and orders errors by webhook type and name", bundle: &bundle.RegistryV1{ - CSV: MakeCSV( + CSV: clusterserviceversion.Builder(). WithWebhookDefinitions( v1alpha1.WebhookDescription{ Type: v1alpha1.ValidatingAdmissionWebhook, @@ -1192,8 +1152,7 @@ func Test_CheckWebhookNameIsDNS1123SubDomain(t *testing.T) { Type: v1alpha1.ConversionWebhook, GenerateName: "a-bad-name-", }, - ), - ), + ).Build(), }, expectedErrs: []error{ errors.New("webhook of type 'ConversionWebhook' has invalid name 'a-bad-name-': a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')"), diff --git a/internal/operator-controller/rukpak/render/render_test.go b/internal/operator-controller/rukpak/render/render_test.go index 004c3edb6..9483bd8cb 100644 --- a/internal/operator-controller/rukpak/render/render_test.go +++ b/internal/operator-controller/rukpak/render/render_test.go @@ -16,13 +16,14 @@ import ( "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle" "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render" . "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing" + "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/clusterserviceversion" ) func Test_BundleRenderer_NoConfig(t *testing.T) { renderer := render.BundleRenderer{} objs, err := renderer.Render( bundle.RegistryV1{ - CSV: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces)), + CSV: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build(), }, "", nil) require.NoError(t, err) require.Empty(t, objs) @@ -72,14 +73,14 @@ func Test_BundleRenderer_ValidatesRenderOptions(t *testing.T) { { name: "accepts empty targetNamespaces (because it is ignored)", installNamespace: "install-namespace", - csv: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces)), + csv: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build(), opts: []render.Option{ render.WithTargetNamespaces(), }, }, { name: "rejects nil unique name generator", installNamespace: "install-namespace", - csv: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces)), + csv: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build(), opts: []render.Option{ render.WithUniqueNameGenerator(nil), }, @@ -87,7 +88,7 @@ func Test_BundleRenderer_ValidatesRenderOptions(t *testing.T) { }, { name: "rejects all namespace install if AllNamespaces install mode is not supported", installNamespace: "install-namespace", - csv: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeSingleNamespace)), + csv: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeSingleNamespace).Build(), opts: []render.Option{ render.WithTargetNamespaces(corev1.NamespaceAll), }, @@ -95,7 +96,7 @@ func Test_BundleRenderer_ValidatesRenderOptions(t *testing.T) { }, { name: "rejects own namespace install if only AllNamespace install mode is supported", installNamespace: "install-namespace", - csv: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces)), + csv: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build(), opts: []render.Option{ render.WithTargetNamespaces("install-namespace"), }, @@ -103,7 +104,7 @@ func Test_BundleRenderer_ValidatesRenderOptions(t *testing.T) { }, { name: "rejects install out of own namespace if only OwnNamespace install mode is supported", installNamespace: "install-namespace", - csv: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeOwnNamespace)), + csv: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeOwnNamespace).Build(), opts: []render.Option{ render.WithTargetNamespaces("not-install-namespace"), }, @@ -111,7 +112,7 @@ func Test_BundleRenderer_ValidatesRenderOptions(t *testing.T) { }, { name: "rejects multi-namespace install if MultiNamespace install mode is not supported", installNamespace: "install-namespace", - csv: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces)), + csv: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build(), opts: []render.Option{ render.WithTargetNamespaces("ns1", "ns2", "ns3"), }, @@ -119,7 +120,7 @@ func Test_BundleRenderer_ValidatesRenderOptions(t *testing.T) { }, { name: "rejects if bundle supports no install modes", installNamespace: "install-namespace", - csv: MakeCSV(), + csv: clusterserviceversion.Builder().Build(), opts: []render.Option{ render.WithTargetNamespaces("some-namespace"), }, @@ -127,42 +128,42 @@ func Test_BundleRenderer_ValidatesRenderOptions(t *testing.T) { }, { name: "accepts all namespace render if AllNamespaces install mode is supported", installNamespace: "install-namespace", - csv: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces)), + csv: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build(), opts: []render.Option{ render.WithTargetNamespaces(""), }, }, { name: "accepts install namespace render if SingleNamespace install mode is supported", installNamespace: "install-namespace", - csv: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeSingleNamespace)), + csv: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeSingleNamespace).Build(), opts: []render.Option{ render.WithTargetNamespaces("some-namespace"), }, }, { name: "accepts all install namespace render if OwnNamespace install mode is supported", installNamespace: "install-namespace", - csv: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeOwnNamespace)), + csv: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeOwnNamespace).Build(), opts: []render.Option{ render.WithTargetNamespaces("install-namespace"), }, }, { name: "accepts single namespace render if SingleNamespace install mode is supported", installNamespace: "install-namespace", - csv: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeSingleNamespace)), + csv: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeSingleNamespace).Build(), opts: []render.Option{ render.WithTargetNamespaces("some-namespace"), }, }, { name: "accepts multi namespace render if MultiNamespace install mode is supported", installNamespace: "install-namespace", - csv: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeMultiNamespace)), + csv: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeMultiNamespace).Build(), opts: []render.Option{ render.WithTargetNamespaces("n1", "n2", "n3"), }, }, { name: "reject multi namespace render if OwnNamespace install mode is not supported and target namespaces include install namespace", installNamespace: "install-namespace", - csv: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeMultiNamespace)), + csv: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeMultiNamespace).Build(), opts: []render.Option{ render.WithTargetNamespaces("n1", "n2", "n3", "install-namespace"), }, @@ -233,7 +234,7 @@ func Test_BundleRenderer_CallsResourceGenerators(t *testing.T) { } objs, err := renderer.Render( bundle.RegistryV1{ - CSV: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces)), + CSV: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build(), }, "") require.NoError(t, err) require.Equal(t, []client.Object{&corev1.Namespace{}, &corev1.Service{}, &appsv1.Deployment{}}, objs) @@ -252,7 +253,7 @@ func Test_BundleRenderer_ReturnsResourceGeneratorErrors(t *testing.T) { } objs, err := renderer.Render( bundle.RegistryV1{ - CSV: MakeCSV(WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces)), + CSV: clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces).Build(), }, "") require.Nil(t, objs) require.Error(t, err) diff --git a/internal/operator-controller/rukpak/util/testing/bundlefs/bundlefs_test.go b/internal/operator-controller/rukpak/util/testing/bundlefs/bundlefs_test.go index 2b323ced5..74e8410f3 100644 --- a/internal/operator-controller/rukpak/util/testing/bundlefs/bundlefs_test.go +++ b/internal/operator-controller/rukpak/util/testing/bundlefs/bundlefs_test.go @@ -8,8 +8,8 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - testutils "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing" "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/bundlefs" + "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/clusterserviceversion" ) func Test_BundleFSBuilder(t *testing.T) { @@ -85,7 +85,7 @@ status: }) t.Run("WithCSV adds a csv to the manifests directory", func(t *testing.T) { - bundleFs := bundlefs.Builder().WithCSV(testutils.MakeCSV(testutils.WithName("some-csv"))).Build() + bundleFs := bundlefs.Builder().WithCSV(clusterserviceversion.Builder().WithName("some-csv").Build()).Build() require.Contains(t, bundleFs, "manifests/csv.yaml") require.Equal(t, []byte(`apiVersion: operators.coreos.com/v1alpha1 kind: ClusterServiceVersion diff --git a/internal/operator-controller/rukpak/util/testing/clusterserviceversion/builder.go b/internal/operator-controller/rukpak/util/testing/clusterserviceversion/builder.go new file mode 100644 index 000000000..e7ae2195d --- /dev/null +++ b/internal/operator-controller/rukpak/util/testing/clusterserviceversion/builder.go @@ -0,0 +1,103 @@ +package clusterserviceversion + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/sets" + + "github.com/operator-framework/api/pkg/operators/v1alpha1" +) + +var installModes = []v1alpha1.InstallModeType{ + v1alpha1.InstallModeTypeAllNamespaces, + v1alpha1.InstallModeTypeSingleNamespace, + v1alpha1.InstallModeTypeMultiNamespace, + v1alpha1.InstallModeTypeOwnNamespace, +} + +// ClusterServiceVersionBuilder build a ClusterServiceVersion resource +type ClusterServiceVersionBuilder interface { + WithName(name string) ClusterServiceVersionBuilder + WithStrategyDeploymentSpecs(strategyDeploymentSpecs ...v1alpha1.StrategyDeploymentSpec) ClusterServiceVersionBuilder + WithAnnotations(annotations map[string]string) ClusterServiceVersionBuilder + WithPermissions(permissions ...v1alpha1.StrategyDeploymentPermissions) ClusterServiceVersionBuilder + WithClusterPermissions(permissions ...v1alpha1.StrategyDeploymentPermissions) ClusterServiceVersionBuilder + WithOwnedCRDs(crdDesc ...v1alpha1.CRDDescription) ClusterServiceVersionBuilder + WithInstallModeSupportFor(installModeType ...v1alpha1.InstallModeType) ClusterServiceVersionBuilder + WithWebhookDefinitions(webhookDefinitions ...v1alpha1.WebhookDescription) ClusterServiceVersionBuilder + WithOwnedAPIServiceDescriptions(ownedAPIServiceDescriptions ...v1alpha1.APIServiceDescription) ClusterServiceVersionBuilder + Build() v1alpha1.ClusterServiceVersion +} + +// Builder creates a new ClusterServiceVersionBuilder for building ClusterServiceVersion resources +func Builder() ClusterServiceVersionBuilder { + return &clusterServiceVersionBuilder{ + csv: v1alpha1.ClusterServiceVersion{ + TypeMeta: metav1.TypeMeta{ + APIVersion: v1alpha1.SchemeGroupVersion.String(), + Kind: "ClusterServiceVersion", + }, + }, + } +} + +type clusterServiceVersionBuilder struct { + csv v1alpha1.ClusterServiceVersion +} + +//nolint:unparam +func (b *clusterServiceVersionBuilder) WithName(name string) ClusterServiceVersionBuilder { + b.csv.Name = name + return b +} + +func (b *clusterServiceVersionBuilder) WithStrategyDeploymentSpecs(strategyDeploymentSpecs ...v1alpha1.StrategyDeploymentSpec) ClusterServiceVersionBuilder { + b.csv.Spec.InstallStrategy.StrategySpec.DeploymentSpecs = strategyDeploymentSpecs + return b +} + +func (b *clusterServiceVersionBuilder) WithAnnotations(annotations map[string]string) ClusterServiceVersionBuilder { + b.csv.Annotations = annotations + return b +} + +func (b *clusterServiceVersionBuilder) WithPermissions(permissions ...v1alpha1.StrategyDeploymentPermissions) ClusterServiceVersionBuilder { + b.csv.Spec.InstallStrategy.StrategySpec.Permissions = permissions + return b +} + +func (b *clusterServiceVersionBuilder) WithClusterPermissions(permissions ...v1alpha1.StrategyDeploymentPermissions) ClusterServiceVersionBuilder { + b.csv.Spec.InstallStrategy.StrategySpec.ClusterPermissions = permissions + return b +} + +func (b *clusterServiceVersionBuilder) WithOwnedCRDs(crdDesc ...v1alpha1.CRDDescription) ClusterServiceVersionBuilder { + b.csv.Spec.CustomResourceDefinitions.Owned = crdDesc + return b +} + +func (b *clusterServiceVersionBuilder) WithInstallModeSupportFor(installModeType ...v1alpha1.InstallModeType) ClusterServiceVersionBuilder { + supportedInstallModes := sets.New(installModeType...) + csvInstallModes := make([]v1alpha1.InstallMode, 0, len(installModeType)) + for _, t := range installModes { + csvInstallModes = append(csvInstallModes, v1alpha1.InstallMode{ + Type: t, + Supported: supportedInstallModes.Has(t), + }) + } + b.csv.Spec.InstallModes = csvInstallModes + return b +} + +func (b *clusterServiceVersionBuilder) WithWebhookDefinitions(webhookDefinitions ...v1alpha1.WebhookDescription) ClusterServiceVersionBuilder { + b.csv.Spec.WebhookDefinitions = webhookDefinitions + return b +} + +func (b *clusterServiceVersionBuilder) WithOwnedAPIServiceDescriptions(ownedAPIServiceDescriptions ...v1alpha1.APIServiceDescription) ClusterServiceVersionBuilder { + b.csv.Spec.APIServiceDefinitions.Owned = ownedAPIServiceDescriptions + return b +} + +func (b *clusterServiceVersionBuilder) Build() v1alpha1.ClusterServiceVersion { + return b.csv +} diff --git a/internal/operator-controller/rukpak/util/testing/clusterserviceversion/builder_test.go b/internal/operator-controller/rukpak/util/testing/clusterserviceversion/builder_test.go new file mode 100644 index 000000000..45bad4e53 --- /dev/null +++ b/internal/operator-controller/rukpak/util/testing/clusterserviceversion/builder_test.go @@ -0,0 +1,215 @@ +package clusterserviceversion_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + rbacv1 "k8s.io/api/rbac/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/operator-framework/api/pkg/operators/v1alpha1" + + "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing/clusterserviceversion" +) + +func Test_Builder(t *testing.T) { + t.Run("builds an empty csv by default", func(t *testing.T) { + obj := clusterserviceversion.Builder().Build() + require.Equal(t, v1alpha1.ClusterServiceVersion{ + TypeMeta: metav1.TypeMeta{ + Kind: "ClusterServiceVersion", + APIVersion: v1alpha1.SchemeGroupVersion.String(), + }, + }, obj) + }) + + t.Run("WithName sets csv .metadata.name", func(t *testing.T) { + obj := clusterserviceversion.Builder().WithName("some-name").Build() + require.Equal(t, v1alpha1.ClusterServiceVersion{ + TypeMeta: metav1.TypeMeta{ + Kind: "ClusterServiceVersion", + APIVersion: v1alpha1.SchemeGroupVersion.String(), + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "some-name", + }, + }, obj) + }) + + t.Run("WithStrategyDeploymentSpecs sets csv .spec.install.spec.deployments", func(t *testing.T) { + obj := clusterserviceversion.Builder().WithStrategyDeploymentSpecs( + v1alpha1.StrategyDeploymentSpec{ + Name: "spec-one", + }, + v1alpha1.StrategyDeploymentSpec{ + Name: "spec-two", + }, + ).Build() + + require.Equal(t, v1alpha1.ClusterServiceVersion{ + TypeMeta: metav1.TypeMeta{ + Kind: "ClusterServiceVersion", + APIVersion: v1alpha1.SchemeGroupVersion.String(), + }, + Spec: v1alpha1.ClusterServiceVersionSpec{ + InstallStrategy: v1alpha1.NamedInstallStrategy{ + StrategySpec: v1alpha1.StrategyDetailsDeployment{ + DeploymentSpecs: []v1alpha1.StrategyDeploymentSpec{ + { + Name: "spec-one", + }, + { + Name: "spec-two", + }, + }, + }, + }, + }, + }, obj) + }) + + t.Run("WithPermissions sets csv .spec.install.spec.permissions", func(t *testing.T) { + obj := clusterserviceversion.Builder().WithPermissions( + v1alpha1.StrategyDeploymentPermissions{ + ServiceAccountName: "service-account", + Rules: []rbacv1.PolicyRule{ + { + APIGroups: []string{""}, + Resources: []string{"secrets"}, + Verbs: []string{"list", "watch"}, + }, + }, + }, + v1alpha1.StrategyDeploymentPermissions{ + ServiceAccountName: "", + }, + ).Build() + + require.Equal(t, v1alpha1.ClusterServiceVersion{ + TypeMeta: metav1.TypeMeta{ + Kind: "ClusterServiceVersion", + APIVersion: v1alpha1.SchemeGroupVersion.String(), + }, + Spec: v1alpha1.ClusterServiceVersionSpec{ + InstallStrategy: v1alpha1.NamedInstallStrategy{ + StrategySpec: v1alpha1.StrategyDetailsDeployment{ + Permissions: []v1alpha1.StrategyDeploymentPermissions{ + { + ServiceAccountName: "service-account", + Rules: []rbacv1.PolicyRule{ + { + APIGroups: []string{""}, + Resources: []string{"secrets"}, + Verbs: []string{"list", "watch"}, + }, + }, + }, + { + ServiceAccountName: "", + }, + }, + }, + }, + }, + }, obj) + }) + + t.Run("WithClusterPermissions sets csv .spec.install.spec.clusterPermissions", func(t *testing.T) { + obj := clusterserviceversion.Builder().WithClusterPermissions( + v1alpha1.StrategyDeploymentPermissions{ + ServiceAccountName: "service-account", + Rules: []rbacv1.PolicyRule{ + { + APIGroups: []string{""}, + Resources: []string{"secrets"}, + Verbs: []string{"list", "watch"}, + }, + }, + }, + v1alpha1.StrategyDeploymentPermissions{ + ServiceAccountName: "", + }, + ).Build() + + require.Equal(t, v1alpha1.ClusterServiceVersion{ + TypeMeta: metav1.TypeMeta{ + Kind: "ClusterServiceVersion", + APIVersion: v1alpha1.SchemeGroupVersion.String(), + }, + Spec: v1alpha1.ClusterServiceVersionSpec{ + InstallStrategy: v1alpha1.NamedInstallStrategy{ + StrategySpec: v1alpha1.StrategyDetailsDeployment{ + ClusterPermissions: []v1alpha1.StrategyDeploymentPermissions{ + { + ServiceAccountName: "service-account", + Rules: []rbacv1.PolicyRule{ + { + APIGroups: []string{""}, + Resources: []string{"secrets"}, + Verbs: []string{"list", "watch"}, + }, + }, + }, + { + ServiceAccountName: "", + }, + }, + }, + }, + }, + }, obj) + }) + + t.Run("WithClusterPermissions sets csv .spec.customresourcedefinitions.owned", func(t *testing.T) { + obj := clusterserviceversion.Builder().WithOwnedCRDs( + v1alpha1.CRDDescription{Name: "a.crd.something"}, + v1alpha1.CRDDescription{Name: "b.crd.something"}, + ).Build() + + require.Equal(t, v1alpha1.ClusterServiceVersion{ + TypeMeta: metav1.TypeMeta{ + Kind: "ClusterServiceVersion", + APIVersion: v1alpha1.SchemeGroupVersion.String(), + }, + Spec: v1alpha1.ClusterServiceVersionSpec{ + CustomResourceDefinitions: v1alpha1.CustomResourceDefinitions{ + Owned: []v1alpha1.CRDDescription{ + {Name: "a.crd.something"}, + {Name: "b.crd.something"}, + }, + }, + }, + }, obj) + }) + + t.Run("WithInstallModeSupportFor adds all install modes to .spec.installModes and sets supported to true for the given supported install modes", func(t *testing.T) { + obj := clusterserviceversion.Builder().WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces, v1alpha1.InstallModeTypeSingleNamespace).Build() + + require.Equal(t, v1alpha1.ClusterServiceVersion{ + TypeMeta: metav1.TypeMeta{ + Kind: "ClusterServiceVersion", + APIVersion: v1alpha1.SchemeGroupVersion.String(), + }, + Spec: v1alpha1.ClusterServiceVersionSpec{ + InstallModes: []v1alpha1.InstallMode{ + { + Type: v1alpha1.InstallModeTypeAllNamespaces, + Supported: true, + }, + { + Type: v1alpha1.InstallModeTypeSingleNamespace, + Supported: true, + }, + { + Type: v1alpha1.InstallModeTypeMultiNamespace, + Supported: false, + }, + { + Type: v1alpha1.InstallModeTypeOwnNamespace, + Supported: false, + }, + }, + }, + }, obj) + }) +} diff --git a/internal/operator-controller/rukpak/util/testing/testing.go b/internal/operator-controller/rukpak/util/testing/testing.go index e544e546c..2670091a1 100644 --- a/internal/operator-controller/rukpak/util/testing/testing.go +++ b/internal/operator-controller/rukpak/util/testing/testing.go @@ -4,102 +4,14 @@ import ( "testing" "github.com/stretchr/testify/require" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/util/sets" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/operator-framework/api/pkg/operators/v1alpha1" - "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle" "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render" "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util" ) -type CSVOption func(version *v1alpha1.ClusterServiceVersion) - -//nolint:unparam -func WithName(name string) CSVOption { - return func(csv *v1alpha1.ClusterServiceVersion) { - csv.Name = name - } -} - -func WithStrategyDeploymentSpecs(strategyDeploymentSpecs ...v1alpha1.StrategyDeploymentSpec) CSVOption { - return func(csv *v1alpha1.ClusterServiceVersion) { - csv.Spec.InstallStrategy.StrategySpec.DeploymentSpecs = strategyDeploymentSpecs - } -} - -func WithAnnotations(annotations map[string]string) CSVOption { - return func(csv *v1alpha1.ClusterServiceVersion) { - csv.Annotations = annotations - } -} - -func WithPermissions(permissions ...v1alpha1.StrategyDeploymentPermissions) CSVOption { - return func(csv *v1alpha1.ClusterServiceVersion) { - csv.Spec.InstallStrategy.StrategySpec.Permissions = permissions - } -} - -func WithClusterPermissions(permissions ...v1alpha1.StrategyDeploymentPermissions) CSVOption { - return func(csv *v1alpha1.ClusterServiceVersion) { - csv.Spec.InstallStrategy.StrategySpec.ClusterPermissions = permissions - } -} - -func WithOwnedCRDs(crdDesc ...v1alpha1.CRDDescription) CSVOption { - return func(csv *v1alpha1.ClusterServiceVersion) { - csv.Spec.CustomResourceDefinitions.Owned = crdDesc - } -} - -func WithInstallModeSupportFor(installModeType ...v1alpha1.InstallModeType) CSVOption { - var installModes = []v1alpha1.InstallModeType{ - v1alpha1.InstallModeTypeAllNamespaces, - v1alpha1.InstallModeTypeSingleNamespace, - v1alpha1.InstallModeTypeMultiNamespace, - v1alpha1.InstallModeTypeOwnNamespace, - } - return func(csv *v1alpha1.ClusterServiceVersion) { - supportedInstallModes := sets.New(installModeType...) - csvInstallModes := make([]v1alpha1.InstallMode, 0, len(installModeType)) - for _, t := range installModes { - csvInstallModes = append(csvInstallModes, v1alpha1.InstallMode{ - Type: t, - Supported: supportedInstallModes.Has(t), - }) - } - csv.Spec.InstallModes = csvInstallModes - } -} - -func WithWebhookDefinitions(webhookDefinitions ...v1alpha1.WebhookDescription) CSVOption { - return func(csv *v1alpha1.ClusterServiceVersion) { - csv.Spec.WebhookDefinitions = webhookDefinitions - } -} - -func WithOwnedAPIServiceDescriptions(ownedAPIServiceDescriptions ...v1alpha1.APIServiceDescription) CSVOption { - return func(csv *v1alpha1.ClusterServiceVersion) { - csv.Spec.APIServiceDefinitions.Owned = ownedAPIServiceDescriptions - } -} - -func MakeCSV(opts ...CSVOption) v1alpha1.ClusterServiceVersion { - csv := v1alpha1.ClusterServiceVersion{ - TypeMeta: metav1.TypeMeta{ - APIVersion: v1alpha1.SchemeGroupVersion.String(), - Kind: "ClusterServiceVersion", - }, - } - for _, opt := range opts { - opt(&csv) - } - return csv -} - type FakeCertProvider struct { InjectCABundleFn func(obj client.Object, cfg render.CertificateProvisionerConfig) error AdditionalObjectsFn func(cfg render.CertificateProvisionerConfig) ([]unstructured.Unstructured, error) diff --git a/internal/operator-controller/rukpak/util/testing/testing_test.go b/internal/operator-controller/rukpak/util/testing/testing_test.go deleted file mode 100644 index 703cc0018..000000000 --- a/internal/operator-controller/rukpak/util/testing/testing_test.go +++ /dev/null @@ -1,223 +0,0 @@ -package testing_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - rbacv1 "k8s.io/api/rbac/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/operator-framework/api/pkg/operators/v1alpha1" - - . "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util/testing" -) - -func Test_MakeCSV(t *testing.T) { - csv := MakeCSV() - require.Equal(t, v1alpha1.ClusterServiceVersion{ - TypeMeta: metav1.TypeMeta{ - Kind: "ClusterServiceVersion", - APIVersion: v1alpha1.SchemeGroupVersion.String(), - }, - }, csv) -} - -func Test_MakeCSV_WithName(t *testing.T) { - csv := MakeCSV(WithName("some-name")) - require.Equal(t, v1alpha1.ClusterServiceVersion{ - TypeMeta: metav1.TypeMeta{ - Kind: "ClusterServiceVersion", - APIVersion: v1alpha1.SchemeGroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "some-name", - }, - }, csv) -} - -func Test_MakeCSV_WithStrategyDeploymentSpecs(t *testing.T) { - csv := MakeCSV( - WithStrategyDeploymentSpecs( - v1alpha1.StrategyDeploymentSpec{ - Name: "spec-one", - }, - v1alpha1.StrategyDeploymentSpec{ - Name: "spec-two", - }, - ), - ) - - require.Equal(t, v1alpha1.ClusterServiceVersion{ - TypeMeta: metav1.TypeMeta{ - Kind: "ClusterServiceVersion", - APIVersion: v1alpha1.SchemeGroupVersion.String(), - }, - Spec: v1alpha1.ClusterServiceVersionSpec{ - InstallStrategy: v1alpha1.NamedInstallStrategy{ - StrategySpec: v1alpha1.StrategyDetailsDeployment{ - DeploymentSpecs: []v1alpha1.StrategyDeploymentSpec{ - { - Name: "spec-one", - }, - { - Name: "spec-two", - }, - }, - }, - }, - }, - }, csv) -} - -func Test_MakeCSV_WithPermissions(t *testing.T) { - csv := MakeCSV( - WithPermissions( - v1alpha1.StrategyDeploymentPermissions{ - ServiceAccountName: "service-account", - Rules: []rbacv1.PolicyRule{ - { - APIGroups: []string{""}, - Resources: []string{"secrets"}, - Verbs: []string{"list", "watch"}, - }, - }, - }, - v1alpha1.StrategyDeploymentPermissions{ - ServiceAccountName: "", - }, - ), - ) - - require.Equal(t, v1alpha1.ClusterServiceVersion{ - TypeMeta: metav1.TypeMeta{ - Kind: "ClusterServiceVersion", - APIVersion: v1alpha1.SchemeGroupVersion.String(), - }, - Spec: v1alpha1.ClusterServiceVersionSpec{ - InstallStrategy: v1alpha1.NamedInstallStrategy{ - StrategySpec: v1alpha1.StrategyDetailsDeployment{ - Permissions: []v1alpha1.StrategyDeploymentPermissions{ - { - ServiceAccountName: "service-account", - Rules: []rbacv1.PolicyRule{ - { - APIGroups: []string{""}, - Resources: []string{"secrets"}, - Verbs: []string{"list", "watch"}, - }, - }, - }, - { - ServiceAccountName: "", - }, - }, - }, - }, - }, - }, csv) -} - -func Test_MakeCSV_WithClusterPermissions(t *testing.T) { - csv := MakeCSV( - WithClusterPermissions( - v1alpha1.StrategyDeploymentPermissions{ - ServiceAccountName: "service-account", - Rules: []rbacv1.PolicyRule{ - { - APIGroups: []string{""}, - Resources: []string{"secrets"}, - Verbs: []string{"list", "watch"}, - }, - }, - }, - v1alpha1.StrategyDeploymentPermissions{ - ServiceAccountName: "", - }, - ), - ) - - require.Equal(t, v1alpha1.ClusterServiceVersion{ - TypeMeta: metav1.TypeMeta{ - Kind: "ClusterServiceVersion", - APIVersion: v1alpha1.SchemeGroupVersion.String(), - }, - Spec: v1alpha1.ClusterServiceVersionSpec{ - InstallStrategy: v1alpha1.NamedInstallStrategy{ - StrategySpec: v1alpha1.StrategyDetailsDeployment{ - ClusterPermissions: []v1alpha1.StrategyDeploymentPermissions{ - { - ServiceAccountName: "service-account", - Rules: []rbacv1.PolicyRule{ - { - APIGroups: []string{""}, - Resources: []string{"secrets"}, - Verbs: []string{"list", "watch"}, - }, - }, - }, - { - ServiceAccountName: "", - }, - }, - }, - }, - }, - }, csv) -} - -func Test_MakeCSV_WithOwnedCRDs(t *testing.T) { - csv := MakeCSV( - WithOwnedCRDs( - v1alpha1.CRDDescription{Name: "a.crd.something"}, - v1alpha1.CRDDescription{Name: "b.crd.something"}, - ), - ) - - require.Equal(t, v1alpha1.ClusterServiceVersion{ - TypeMeta: metav1.TypeMeta{ - Kind: "ClusterServiceVersion", - APIVersion: v1alpha1.SchemeGroupVersion.String(), - }, - Spec: v1alpha1.ClusterServiceVersionSpec{ - CustomResourceDefinitions: v1alpha1.CustomResourceDefinitions{ - Owned: []v1alpha1.CRDDescription{ - {Name: "a.crd.something"}, - {Name: "b.crd.something"}, - }, - }, - }, - }, csv) -} - -func Test_MakeCSV_WithInstallModeSupportFor(t *testing.T) { - csv := MakeCSV( - WithInstallModeSupportFor(v1alpha1.InstallModeTypeAllNamespaces, v1alpha1.InstallModeTypeSingleNamespace), - ) - - require.Equal(t, v1alpha1.ClusterServiceVersion{ - TypeMeta: metav1.TypeMeta{ - Kind: "ClusterServiceVersion", - APIVersion: v1alpha1.SchemeGroupVersion.String(), - }, - Spec: v1alpha1.ClusterServiceVersionSpec{ - InstallModes: []v1alpha1.InstallMode{ - { - Type: v1alpha1.InstallModeTypeAllNamespaces, - Supported: true, - }, - { - Type: v1alpha1.InstallModeTypeSingleNamespace, - Supported: true, - }, - { - Type: v1alpha1.InstallModeTypeMultiNamespace, - Supported: false, - }, - { - Type: v1alpha1.InstallModeTypeOwnNamespace, - Supported: false, - }, - }, - }, - }, csv) -}