-
Notifications
You must be signed in to change notification settings - Fork 64
Makes OLMVariableSource
responsible for fetching
#245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,14 +11,25 @@ import ( | |
. "github.com/onsi/gomega" | ||
"github.com/operator-framework/deppy/pkg/deppy" | ||
"github.com/operator-framework/deppy/pkg/deppy/input" | ||
"github.com/operator-framework/operator-controller/api/v1alpha1" | ||
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1" | ||
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/bundles_and_dependencies" | ||
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/crd_constraints" | ||
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/olm" | ||
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/required_package" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
) | ||
|
||
func FakeClient(objects ...client.Object) client.Client { | ||
scheme := runtime.NewScheme() | ||
utilruntime.Must(v1alpha1.AddToScheme(scheme)) | ||
return fake.NewClientBuilder().WithScheme(scheme).WithObjects(objects...).Build() | ||
} | ||
|
||
func TestGlobalConstraints(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "OLMVariableSource Suite") | ||
|
@@ -59,7 +70,7 @@ func withVersionRange(versionRange string) opOption { | |
} | ||
} | ||
|
||
func operator(name string, opts ...opOption) operatorsv1alpha1.Operator { | ||
func operator(name string, opts ...opOption) *operatorsv1alpha1.Operator { | ||
op := operatorsv1alpha1.Operator{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: name, | ||
|
@@ -73,7 +84,7 @@ func operator(name string, opts ...opOption) operatorsv1alpha1.Operator { | |
Fail(err.Error()) | ||
} | ||
} | ||
return op | ||
return &op | ||
} | ||
|
||
var _ = Describe("OLMVariableSource", func() { | ||
|
@@ -84,20 +95,30 @@ var _ = Describe("OLMVariableSource", func() { | |
}) | ||
|
||
It("should produce RequiredPackage variables", func() { | ||
olmVariableSource := olm.NewOLMVariableSource(operator("prometheus"), operator("packageA")) | ||
cl := FakeClient(operator("prometheus"), operator("packageA")) | ||
|
||
olmVariableSource := olm.NewOLMVariableSource(cl) | ||
variables, err := olmVariableSource.GetVariables(context.Background(), testEntitySource) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
packageRequiredVariables := filterVariables[*required_package.RequiredPackageVariable](variables) | ||
Expect(packageRequiredVariables).To(HaveLen(2)) | ||
Expect(packageRequiredVariables[0].Identifier()).To(Equal(deppy.IdentifierFromString("required package prometheus"))) | ||
Expect(packageRequiredVariables[0].BundleEntities()).To(HaveLen(2)) | ||
Expect(packageRequiredVariables[1].Identifier()).To(Equal(deppy.IdentifierFromString("required package packageA"))) | ||
Expect(packageRequiredVariables[1].BundleEntities()).To(HaveLen(1)) | ||
Expect(packageRequiredVariables).To(WithTransform(func(bvars []*required_package.RequiredPackageVariable) map[deppy.Identifier]int { | ||
out := map[deppy.Identifier]int{} | ||
for _, variable := range bvars { | ||
out[variable.Identifier()] = len(variable.BundleEntities()) | ||
} | ||
return out | ||
}, Equal(map[deppy.Identifier]int{ | ||
deppy.IdentifierFromString("required package prometheus"): 2, | ||
deppy.IdentifierFromString("required package packageA"): 1, | ||
}))) | ||
}) | ||
|
||
It("should produce BundleVariables variables", func() { | ||
olmVariableSource := olm.NewOLMVariableSource(operator("prometheus"), operator("packageA")) | ||
cl := FakeClient(operator("prometheus"), operator("packageA")) | ||
|
||
olmVariableSource := olm.NewOLMVariableSource(cl) | ||
variables, err := olmVariableSource.GetVariables(context.Background(), testEntitySource) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
|
@@ -109,15 +130,17 @@ var _ = Describe("OLMVariableSource", func() { | |
out = append(out, variable.BundleEntity().Entity) | ||
} | ||
return out | ||
}, Equal([]*input.Entity{ | ||
}, ConsistOf([]*input.Entity{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the order of variables returned from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sounds like an important question to resolve at the public-facing level - if the order is not guaranteed, it should be noted in the API docs. If it is, a simple sort-in-place can be added. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We are not defining an API here - we are implementing a contract/interface required by Deppy. Solver will be calling IMO nether sorting variables nor documenting ordering on the operator-controller side is necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Want to clarify: there are some places where the order is very important for the resolution process. For example, we want to select latest possible version for the solution. But I think here it is not important. However thinking about debuggability - it still might be a good idea to have some stable order. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I was partially wrong here:
I looked into this a bit more. It looks like the fake client does not guarantee order (at least I do not see anything about this in docs), but de facto it does sorting (we hit this code eventually). So in the test we add Our options here:
Since we now know that fake client returns in deterministic order (not documented, but still) - I think there is little to no benefit in sorting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If sort order is immaterial except for testing, I agree that your third option is the best. |
||
entityFromCache("operatorhub/prometheus/0.47.0"), | ||
entityFromCache("operatorhub/prometheus/0.37.0"), | ||
entityFromCache("operatorhub/packageA/2.0.0"), | ||
}))) | ||
}) | ||
|
||
It("should produce version filtered BundleVariables variables", func() { | ||
olmVariableSource := olm.NewOLMVariableSource(operator("prometheus", withVersionRange(">0.40.0")), operator("packageA")) | ||
cl := FakeClient(operator("prometheus", withVersionRange(">0.40.0")), operator("packageA")) | ||
|
||
olmVariableSource := olm.NewOLMVariableSource(cl) | ||
variables, err := olmVariableSource.GetVariables(context.Background(), testEntitySource) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
|
@@ -129,7 +152,7 @@ var _ = Describe("OLMVariableSource", func() { | |
out = append(out, variable.BundleEntity().Entity) | ||
} | ||
return out | ||
}, Equal([]*input.Entity{ | ||
}, ConsistOf([]*input.Entity{ | ||
entityFromCache("operatorhub/prometheus/0.47.0"), | ||
// filtered out | ||
// entityFromCache("operatorhub/prometheus/0.37.0"), | ||
|
@@ -138,7 +161,9 @@ var _ = Describe("OLMVariableSource", func() { | |
}) | ||
|
||
It("should produce GlobalConstraints variables", func() { | ||
olmVariableSource := olm.NewOLMVariableSource(operator("prometheus"), operator("packageA")) | ||
cl := FakeClient(operator("prometheus"), operator("packageA")) | ||
|
||
olmVariableSource := olm.NewOLMVariableSource(cl) | ||
variables, err := olmVariableSource.GetVariables(context.Background(), testEntitySource) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
|
@@ -166,7 +191,9 @@ var _ = Describe("OLMVariableSource", func() { | |
}) | ||
|
||
It("should return an errors when they occur", func() { | ||
olmVariableSource := olm.NewOLMVariableSource(operator("prometheus"), operator("packageA")) | ||
cl := FakeClient(operator("prometheus"), operator("packageA")) | ||
|
||
olmVariableSource := olm.NewOLMVariableSource(cl) | ||
_, err := olmVariableSource.GetVariables(context.Background(), FailEntitySource{}) | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
|
Uh oh!
There was an error while loading. Please reload this page.