Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

refactor controllers #48

Merged

Conversation

everettraven
Copy link
Collaborator

Description of the change

  • Refactoring of both controllers/scopeinstance_controller.go and controllers/scopetemplate_controller.go to align more with the implementation that rukpak has.

Motivation for the change

Signed-off-by: Bryce Palmer <[email protected]>
Signed-off-by: Bryce Palmer <[email protected]>
Copy link
Member

@jmrodri jmrodri left a comment

Choose a reason for hiding this comment

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

/lgtm

The scopeinstance controller looks good. The patching config seems weird but it seems to be what's needed for the patch to work.

The scopetemplate_controller looks very similar I didn't see anything that really stuck out to me.

controllers/scopeinstance_controller.go Show resolved Hide resolved
controllers/scopeinstance_controller.go Show resolved Hide resolved
controllers/scopeinstance_controller.go Outdated Show resolved Hide resolved
controllers/scopeinstance_controller.go Show resolved Hide resolved
controllers/scopeinstance_controller.go Outdated Show resolved Hide resolved
return &unstructured.Unstructured{Object: uMap}, nil
}

func (r *ScopeInstanceReconciler) patchBinding(ctx context.Context, binding client.Object) error {
Copy link
Member

Choose a reason for hiding this comment

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

patchBinding seems good as well.

binding,
client.Apply,
client.FieldOwner(siCtrlFieldOwner),
client.ForceOwnership)
}
Copy link
Member

Choose a reason for hiding this comment

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

deleteBindings seems like it might fail between the list and delete.

Copy link
Member

Choose a reason for hiding this comment

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

sigh, the comment says just that. And um it's not even part of this PR.

controllers/scopeinstance_controller.go Outdated Show resolved Hide resolved
requests = append(requests, request)
}

return
}

// getClusterRoleBindingForClusterRoleTemplate will create a ClusterRoleBinding from a ClusterRoleTemplate, ScopeInstance, and ScopeTemplate
func (r *ScopeInstanceReconciler) getClusterRoleBinding(cr *operatorsv1.ClusterRoleTemplate, in *operatorsv1.ScopeInstance, st *operatorsv1.ScopeTemplate) *rbacv1.ClusterRoleBinding {
Copy link
Member

Choose a reason for hiding this comment

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

getClusterRoleBinding looks good, cleans up the rest of the code a lot.

}

// getRoleBindingForClusterRoleTemplate will create a ClusterRoleBinding from a ClusterRoleTemplate
func (r *ScopeInstanceReconciler) getRoleBinding(cr *operatorsv1.ClusterRoleTemplate, in *operatorsv1.ScopeInstance, st *operatorsv1.ScopeTemplate, namespace string) *rbacv1.RoleBinding {
Copy link
Member

Choose a reason for hiding this comment

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

getRoleBinding looks good too. Also cleans up the rest of the code.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 19, 2022
@everettraven everettraven changed the title refactor controllers to align more with rukpak implementations refactor controllers Sep 19, 2022
Signed-off-by: Bryce Palmer <[email protected]>
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Sep 20, 2022
@jmrodri
Copy link
Member

jmrodri commented Sep 20, 2022

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 20, 2022
@everettraven
Copy link
Collaborator Author

/hold

There are still a few things I want to look into changing and seeing if it will work and make the code look cleaner

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 20, 2022
to just return unstructured.Unstructured instead of dealing with applyconfigurations

Signed-off-by: Bryce Palmer <[email protected]>
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Sep 20, 2022
@everettraven
Copy link
Collaborator Author

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 21, 2022
@jmrodri
Copy link
Member

jmrodri commented Sep 26, 2022

Created an issue to update the reconcile comment. #60

Copy link
Member

@awgreene awgreene left a comment

Choose a reason for hiding this comment

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

Happy with the overall direction of the PR, primarily left nits. Nice work!

controllers/scopeinstance_controller.go Outdated Show resolved Hide resolved
controllers/scopeinstance_controller.go Outdated Show resolved Hide resolved
controllers/scopeinstance_controller.go Outdated Show resolved Hide resolved
controllers/scopeinstance_controller.go Show resolved Hide resolved
controllers/scopeinstance_controller.go Outdated Show resolved Hide resolved
controllers/scopeinstance_controller.go Outdated Show resolved Hide resolved
controllers/scopeinstance_controller.go Outdated Show resolved Hide resolved
controllers/scopetemplate_controller.go Outdated Show resolved Hide resolved
controllers/scopetemplate_controller.go Show resolved Hide resolved
controllers/scopetemplate_controller.go Outdated Show resolved Hide resolved
Copy link
Member

@jmrodri jmrodri left a comment

Choose a reason for hiding this comment

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

Okay really great work. Some minor tweaks. Some of the comments are really long, let's narrow those to about 80 characters to make them easier to read. I supplied suggestions in the PR to help with that.

I left comments about the 2 patchConfig....

There might be some other comments that I forgot to summarize in this comment.

controllers/scopeinstance_controller.go Show resolved Hide resolved
controllers/scopeinstance_controller.go Show resolved Hide resolved
controllers/scopeinstance_controller.go Show resolved Hide resolved
controllers/scopeinstance_controller.go Outdated Show resolved Hide resolved
controllers/scopeinstance_controller.go Outdated Show resolved Hide resolved
controllers/scopeinstance_controller.go Outdated Show resolved Hide resolved
controllers/scopeinstance_controller.go Outdated Show resolved Hide resolved
controllers/scopeinstance_controller.go Outdated Show resolved Hide resolved
controllers/scopeinstance_controller.go Outdated Show resolved Hide resolved
controllers/scopetemplate_controller.go Outdated Show resolved Hide resolved
@jmrodri
Copy link
Member

jmrodri commented Sep 26, 2022

The one bigger nit I have is that we keep passing ScopeTemplate and ScopeInstances all the way down through all of the methods. This makes the methods harder to understand IMO.

For example, in ensureBindings you only need the Namespaces from the ScopeInstance and the ClusterRoles from the the ScopeTemplate.

func (r *ScopeInstanceReconciler) ensureBindings(ctx context.Context, namespaces []string, templates []*operatorsv1.ClusterRoleTemplate) error {

But this isn't really doable because the embedded methods called from ensureBindings might need something else.

So there's no action needed on this nit, but it feels like we should be able to tighten our method signatures to only use what they need and not have to pass entire objects all the way down the stack. Maybe there isn't an efficient way to do it. But my spidey senses are tingly.

Copy link
Member

@laxmikantbpandhare laxmikantbpandhare 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 openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 27, 2022
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Sep 27, 2022
@everettraven everettraven linked an issue Sep 27, 2022 that may be closed by this pull request
Signed-off-by: Bryce Palmer <[email protected]>
@jmrodri
Copy link
Member

jmrodri commented Sep 28, 2022

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 28, 2022
Copy link
Member

@awgreene awgreene left a comment

Choose a reason for hiding this comment

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

/approve

controllers/scopeinstance_controller.go Show resolved Hide resolved
controllers/scopeinstance_controller.go Outdated Show resolved Hide resolved
controllers/scopeinstance_controller.go Outdated Show resolved Hide resolved
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Sep 28, 2022
everettraven and others added 2 commits September 28, 2022 17:41
Signed-off-by: Bryce Palmer <[email protected]>
Copy link
Member

@laxmikantbpandhare laxmikantbpandhare 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 openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Oct 3, 2022
@everettraven everettraven merged commit a77f66f into operator-framework:main Oct 3, 2022
@everettraven everettraven deleted the chore/refactor-controllers branch October 3, 2022 14:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm Indicates that a PR is ready to be merged.
Projects
None yet
5 participants