-
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
Mikalai Radchuk
committed
Nov 6, 2023
1 parent
7f61f6d
commit d2a06e8
Showing
3 changed files
with
129 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,24 @@ | ||
package variablesources_test | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"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 +81,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 +201,40 @@ func TestInstalledPackageVariableSource(t *testing.T) { | |
}, | ||
} | ||
|
||
fakeBundleDeployment := func(name, bundleImage string) rukpakv1alpha1.BundleDeployment { | ||
return rukpakv1alpha1.BundleDeployment{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: name, | ||
}, | ||
Spec: rukpakv1alpha1.BundleDeploymentSpec{ | ||
Template: &rukpakv1alpha1.BundleTemplate{ | ||
Spec: rukpakv1alpha1.BundleSpec{ | ||
Source: rukpakv1alpha1.BundleSource{ | ||
Image: &rukpakv1alpha1.ImageSource{ | ||
Ref: bundleImage, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
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, | ||
[]rukpakv1alpha1.BundleDeployment{ | ||
fakeBundleDeployment("test-bd", 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 +248,16 @@ 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, | ||
[]rukpakv1alpha1.BundleDeployment{ | ||
fakeBundleDeployment("test-bd", 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 +268,16 @@ 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, | ||
[]rukpakv1alpha1.BundleDeployment{ | ||
fakeBundleDeployment("test-bd", 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 +293,16 @@ 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, | ||
[]rukpakv1alpha1.BundleDeployment{ | ||
fakeBundleDeployment("test-bd", 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 +311,16 @@ 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, | ||
[]rukpakv1alpha1.BundleDeployment{ | ||
fakeBundleDeployment("test-bd", bundleImage), | ||
}, | ||
) | ||
assert.Nil(t, installedPackages) | ||
assert.ErrorContains(t, err, `bundleImage "registry.io/repo/[email protected]" not found`) | ||
}) | ||
} |