Skip to content
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

(refactor) Move csv set and replace to a package #860

Merged
merged 1 commit into from
May 21, 2019

Conversation

tkashem
Copy link
Collaborator

@tkashem tkashem commented May 15, 2019

Promote csv set and replace logic within olm operator to a reusable
package in lib so that it can be reused by other units.

Note:

  • No behavior of the operator has changed as part of this refactor.

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 15, 2019
@tkashem
Copy link
Collaborator Author

tkashem commented May 15, 2019

/test unit

2 similar comments
@tkashem
Copy link
Collaborator Author

tkashem commented May 15, 2019

/test unit

@tkashem
Copy link
Collaborator Author

tkashem commented May 15, 2019

/test unit

@tkashem
Copy link
Collaborator Author

tkashem commented May 15, 2019

/retest

1 similar comment
@tkashem
Copy link
Collaborator Author

tkashem commented May 15, 2019

/retest

Copy link
Member

@ecordell ecordell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

I keep trying to think of a better name than "ReplaceFinder", but I can't 😛

@openshift-ci-robot openshift-ci-robot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels May 15, 2019
@ecordell
Copy link
Member

/retest

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label May 15, 2019
@tkashem
Copy link
Collaborator Author

tkashem commented May 15, 2019

I forgot to change NewFakeOperator and default &Operator{} instances in olm/operator_test.go. Fixed it now. Can you check again when you have some time @ecordell

@tkashem
Copy link
Collaborator Author

tkashem commented May 15, 2019

keep trying to think of a better name than "ReplaceFinder"

Yeah, I could not find a better name either. :)

@tkashem
Copy link
Collaborator Author

tkashem commented May 16, 2019

/retest


// NewSetGenerator returns a new instance of SetGenerator.
func NewSetGenerator(logger *logrus.Logger, lister operatorlister.OperatorLister) SetGenerator {
return &csvSet{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to make this an exported type

// is replacing the given CSV specified.
//
// If the corresponding ClusterServiceVersion is not found nil is returned.
func (r *replace) IsBeingReplaced(in *v1alpha1.ClusterServiceVersion, csvsInNamespace map[string]*v1alpha1.ClusterServiceVersion) (replacedBy *v1alpha1.ClusterServiceVersion) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the CSVSet type were exported, could just reference it here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean, instead of passing the map csvsInNamespace map[string]*v1alpha1.ClusterServiceVersion, call csvSet.WithNamespace from within the function to get the list of namespaces?

I thought that the original intention was to pass the map as a parameter so that it does not need to know how to get it, and I wanted to keep that loose coupling.

I also was thinking of the following use case for my next PR on cluster operator

selector := labels.SelectorFromSet(labels.Set{
  "olm.clusteroperator.name": "packageserver",
})
related := csvSet.WithNamespaceAndLabels(in.GetNamespace(), v1alpha1.CSVPhaseAny, selector)
replacedBy := replaceFinder.IsBeingReplaced(in, related)

Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -163,15 +164,22 @@ func NewFakeOperator(clientObjs []runtime.Object, k8sObjs []runtime.Object, extO

// Create the new operator
queueOperator, err := queueinformer.NewOperatorFromClient(opClientFake, logrus.StandardLogger())

lister := operatorlister.NewLister()
csvSetGenerator := csvutility.NewSetGenerator(logrus.StandardLogger(), lister)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're passing in the logger here, you should construct it ahead of time and pass the same instance to NewOperator, NewSetGenerator, and NewReplaceFinder so that when we pass in configuration (i.e. in the e2e tests) it gets distributed everywhere

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, I will make the change. I noticed that logrus.StandardLogger() was being called every time for a logger inside the function so went ahead with that.

r.logger.Infof("checking %s", csv.GetName())
if csv.Spec.Replaces == in.GetName() {
r.logger.Infof("%s replaced by %s", in.GetName(), csv.GetName())
replacedBy = csv.DeepCopy()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to review where we're calling this and see if the copy is really necessary. This can be quite a lot of objects in a larger cluster.

Another thought: we might want to filter out Copied CSVs here - but again that will require a review of where we call this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking whether deep copy was necessary for this but didn't spend time since I thought it would be outside the scope of this PR.
But I am happy to do the search and see whether we can filter out copied CSVs and not deep copy.

@tkashem
Copy link
Collaborator Author

tkashem commented May 16, 2019

@ecordell please review my comments when you have time.

// If the corresponding ClusterServiceVersion is not found nil is returned.
func (r *replace) IsBeingReplaced(in *v1alpha1.ClusterServiceVersion, csvsInNamespace map[string]*v1alpha1.ClusterServiceVersion) (replacedBy *v1alpha1.ClusterServiceVersion) {
for _, csv := range csvsInNamespace {
if csv.IsCopied() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the call sites of this function, it just requeues both the given CSV and the one replacing it old -> next if next.Status.Phase ~= v1alpha1.CSVPhaseSucceeded. Let me know if we don't need to requeue copied CSV here.

https://github.com/operator-framework/operator-lifecycle-manager/blob/master/pkg/controller/operators/olm/operator.go#L1094


if csv.Spec.Replaces == in.GetName() {
r.logger.Infof("%s replaced by %s", in.GetName(), csv.GetName())
replacedBy = csv
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more deep copying - I removed replacedBy = csv.DeepCopy(). The call sites do not modify the next CSV.

@tkashem
Copy link
Collaborator Author

tkashem commented May 17, 2019

/retest

@tkashem
Copy link
Collaborator Author

tkashem commented May 17, 2019

/test e2e-aws-console-olm

Copy link
Member

@ecordell ecordell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label May 20, 2019
@ecordell
Copy link
Member

/retest

1 similar comment
@ecordell
Copy link
Member

/retest

Promote csv set and replace logic within olm operator to a reusable
package in lib so that it can be reused by other units.

Note:
- No behavior of the operator has changed as part of this refactor.
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label May 21, 2019
@ecordell
Copy link
Member

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label May 21, 2019
@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ecordell, tkashem

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tkashem
Copy link
Collaborator Author

tkashem commented May 21, 2019

/retest

@openshift-merge-robot openshift-merge-robot merged commit 6988cbe into operator-framework:master May 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants