-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turn installed package variable source into a func
Signed-off-by: Mikalai Radchuk <[email protected]>
- Loading branch information
Showing
3 changed files
with
111 additions
and
95 deletions.
There are no files selected for viewing
This file contains 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
100 changes: 50 additions & 50 deletions
100
internal/resolution/variablesources/installed_package.go
This file contains 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 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 |
---|---|---|
@@ -1,24 +1,25 @@ | ||
package variablesources_test | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/operator-framework/deppy/pkg/deppy" | ||
"github.com/operator-framework/operator-registry/alpha/declcfg" | ||
"github.com/operator-framework/operator-registry/alpha/property" | ||
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
featuregatetesting "k8s.io/component-base/featuregate/testing" | ||
|
||
"github.com/operator-framework/operator-controller/internal/catalogmetadata" | ||
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables" | ||
"github.com/operator-framework/operator-controller/internal/resolution/variablesources" | ||
"github.com/operator-framework/operator-controller/pkg/features" | ||
) | ||
|
||
func TestInstalledPackageVariableSource(t *testing.T) { | ||
func TestMakeInstalledPackageVariables(t *testing.T) { | ||
someOtherPackageChannel := catalogmetadata.Channel{Channel: declcfg.Channel{ | ||
Name: "stable", | ||
Package: "some-other-package", | ||
|
@@ -81,7 +82,7 @@ func TestInstalledPackageVariableSource(t *testing.T) { | |
}, | ||
}, | ||
}} | ||
bundleList := []*catalogmetadata.Bundle{ | ||
allBundles := []*catalogmetadata.Bundle{ | ||
{Bundle: declcfg.Bundle{ | ||
Name: "test-package.v0.0.1", | ||
Package: "test-package", | ||
|
@@ -201,19 +202,41 @@ func TestInstalledPackageVariableSource(t *testing.T) { | |
}, | ||
} | ||
|
||
fakeBundleDeployments := func(bundleImages ...string) []rukpakv1alpha1.BundleDeployment { | ||
bundleDeployments := []rukpakv1alpha1.BundleDeployment{} | ||
for idx, bundleImage := range bundleImages { | ||
bd := rukpakv1alpha1.BundleDeployment{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: fmt.Sprintf("bd-%d", idx), | ||
}, | ||
Spec: rukpakv1alpha1.BundleDeploymentSpec{ | ||
Template: &rukpakv1alpha1.BundleTemplate{ | ||
Spec: rukpakv1alpha1.BundleSpec{ | ||
Source: rukpakv1alpha1.BundleSource{ | ||
Image: &rukpakv1alpha1.ImageSource{ | ||
Ref: bundleImage, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
bundleDeployments = append(bundleDeployments, bd) | ||
} | ||
|
||
return bundleDeployments | ||
} | ||
|
||
t.Run("with ForceSemverUpgradeConstraints feature gate enabled", func(t *testing.T) { | ||
defer featuregatetesting.SetFeatureGateDuringTest(t, features.OperatorControllerFeatureGate, features.ForceSemverUpgradeConstraints, true)() | ||
|
||
t.Run("with non-zero major version", func(t *testing.T) { | ||
const bundleImage = "registry.io/repo/[email protected]" | ||
ipvs, err := variablesources.NewInstalledPackageVariableSource(bundleList, bundleImage) | ||
installedPackages, err := variablesources.MakeInstalledPackageVariables(allBundles, fakeBundleDeployments(bundleImage)) | ||
require.NoError(t, err) | ||
|
||
variables, err := ipvs.GetVariables(context.TODO()) | ||
require.NoError(t, err) | ||
require.Len(t, variables, 1) | ||
packageVariable, ok := variables[0].(*olmvariables.InstalledPackageVariable) | ||
assert.True(t, ok) | ||
require.Len(t, installedPackages, 1) | ||
packageVariable := installedPackages[0] | ||
assert.Equal(t, deppy.IdentifierFromString("installed package test-package"), packageVariable.Identifier()) | ||
|
||
// ensure bundles are in version order (high to low) | ||
|
@@ -227,14 +250,11 @@ func TestInstalledPackageVariableSource(t *testing.T) { | |
t.Run("with zero major version", func(t *testing.T) { | ||
t.Run("with zero minor version", func(t *testing.T) { | ||
const bundleImage = "registry.io/repo/[email protected]" | ||
ipvs, err := variablesources.NewInstalledPackageVariableSource(bundleList, bundleImage) | ||
installedPackages, err := variablesources.MakeInstalledPackageVariables(allBundles, fakeBundleDeployments(bundleImage)) | ||
require.NoError(t, err) | ||
|
||
variables, err := ipvs.GetVariables(context.TODO()) | ||
require.NoError(t, err) | ||
require.Len(t, variables, 1) | ||
packageVariable, ok := variables[0].(*olmvariables.InstalledPackageVariable) | ||
assert.True(t, ok) | ||
require.Len(t, installedPackages, 1) | ||
packageVariable := installedPackages[0] | ||
assert.Equal(t, deppy.IdentifierFromString("installed package test-package"), packageVariable.Identifier()) | ||
|
||
// No upgrades are allowed in major version zero when minor version is also zero | ||
|
@@ -245,14 +265,11 @@ func TestInstalledPackageVariableSource(t *testing.T) { | |
|
||
t.Run("with non-zero minor version", func(t *testing.T) { | ||
const bundleImage = "registry.io/repo/[email protected]" | ||
ipvs, err := variablesources.NewInstalledPackageVariableSource(bundleList, bundleImage) | ||
installedPackages, err := variablesources.MakeInstalledPackageVariables(allBundles, fakeBundleDeployments(bundleImage)) | ||
require.NoError(t, err) | ||
|
||
variables, err := ipvs.GetVariables(context.TODO()) | ||
require.NoError(t, err) | ||
require.Len(t, variables, 1) | ||
packageVariable, ok := variables[0].(*olmvariables.InstalledPackageVariable) | ||
assert.True(t, ok) | ||
require.Len(t, installedPackages, 1) | ||
packageVariable := installedPackages[0] | ||
assert.Equal(t, deppy.IdentifierFromString("installed package test-package"), packageVariable.Identifier()) | ||
|
||
// Patch version upgrades are allowed, but not minor upgrades | ||
|
@@ -268,14 +285,11 @@ func TestInstalledPackageVariableSource(t *testing.T) { | |
defer featuregatetesting.SetFeatureGateDuringTest(t, features.OperatorControllerFeatureGate, features.ForceSemverUpgradeConstraints, false)() | ||
|
||
const bundleImage = "registry.io/repo/[email protected]" | ||
ipvs, err := variablesources.NewInstalledPackageVariableSource(bundleList, bundleImage) | ||
installedPackages, err := variablesources.MakeInstalledPackageVariables(allBundles, fakeBundleDeployments(bundleImage)) | ||
require.NoError(t, err) | ||
|
||
variables, err := ipvs.GetVariables(context.TODO()) | ||
require.NoError(t, err) | ||
require.Len(t, variables, 1) | ||
packageVariable, ok := variables[0].(*olmvariables.InstalledPackageVariable) | ||
assert.True(t, ok) | ||
require.Len(t, installedPackages, 1) | ||
packageVariable := installedPackages[0] | ||
assert.Equal(t, deppy.IdentifierFromString("installed package test-package"), packageVariable.Identifier()) | ||
|
||
// ensure bundles are in version order (high to low) | ||
|
@@ -284,4 +298,11 @@ func TestInstalledPackageVariableSource(t *testing.T) { | |
assert.Equal(t, "test-package.v2.1.0", packageVariable.Bundles()[0].Name) | ||
assert.Equal(t, "test-package.v2.0.0", packageVariable.Bundles()[1].Name) | ||
}) | ||
|
||
t.Run("installed bundle not found", func(t *testing.T) { | ||
const bundleImage = "registry.io/repo/[email protected]" | ||
installedPackages, err := variablesources.MakeInstalledPackageVariables(allBundles, fakeBundleDeployments(bundleImage)) | ||
assert.Nil(t, installedPackages) | ||
assert.ErrorContains(t, err, `bundleImage "registry.io/repo/[email protected]" not found`) | ||
}) | ||
} |