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

Allow OperatorPolicy to create OLM subscriptions #162

Merged

Conversation

zyjjay
Copy link
Contributor

@zyjjay zyjjay commented Sep 5, 2023

Modified the controller logic such that the OperatorPolicy controller can create OLM subscriptions based on the policy spec. Currently, an OperatorGroup is created for each Subscription. Future implementation will support creating OperatorGroups based on installModes supported by the generated CSVs.

ref: https://issues.redhat.com/browse/ACM-6597

Comment on lines 130 to 133
subscriptionSpec := r.buildSubscription(policy)
err := r.Get(context.TODO(),
types.NamespacedName{Namespace: subscriptionSpec.Namespace, Name: subscriptionSpec.Name},
subscriptionSpec)
Copy link
Member

Choose a reason for hiding this comment

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

For the Get, I think it's better to pass in an empty subscription, since that will be overwritten with what was found on the cluster.

controllers/operatorpolicy_controller.go Outdated Show resolved Hide resolved
controllers/operatorpolicy_controller.go Show resolved Hide resolved
Comment on lines 150 to 157
operatorGroup := r.buildOperatorGroup(policy)
err = r.Create(context.TODO(), operatorGroup)
Copy link
Member

Choose a reason for hiding this comment

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

This is fine for the initial prototype, but eventually it will need to consider what to do when there is already an operator group in the namespace. Just a comment here so we don't forget 😀


// buildSubscription bootstraps the subscription spec defined in the operator policy
// with the apiversion and kind in preparation for resource creation
func (r *OperatorPolicyReconciler) buildSubscription(
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this will ever need anything from the Reconciler object, so this could be changed to just a function, as opposed to a method. The advantage to that is that it is then a bit easier to test in a unit test, because it's obvious that you don't need to instantiate a client or anything.

The CI is currently failing for the PR, because it is just barely missing the test coverage goal. I think adjusting this and buildOperatorGroup to be regular functions, and adding a unit test for each, would solve this nicely. Eventually of course we'll want e2e tests for OperatorPolicies.

test/resources/operatorplc.yaml Outdated Show resolved Hide resolved
Modified the controller logic such that the OperatorPolicy
controller can create OLM subscriptions based on the
policy spec. Currently, an OperatorGroup is created
for each Subscription. Future implementation will support creating
OperatorGroups based on installModes supported by the generated CSVs.

ref: https://issues.redhat.com/browse/ACM-6597
Signed-off-by: Jason Zhang <jaszhang@redhat.com>
Copy link
Member

@JustinKuli JustinKuli left a comment

Choose a reason for hiding this comment

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

Thanks!

@openshift-ci openshift-ci bot added the lgtm label Sep 12, 2023
@openshift-ci
Copy link

openshift-ci bot commented Sep 12, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JustinKuli, zyjjay

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

@openshift-merge-robot openshift-merge-robot merged commit de86a78 into open-cluster-management-io:main Sep 12, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants