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 common functions out of csr controller, into constants or helpers. #428

Conversation

xuezhaojun
Copy link
Contributor

@xuezhaojun xuezhaojun commented Nov 22, 2024

There are mainly 2 changes in this PR:

First, the GetClusterName is moved from csr-controller to helpers pkg, along with some const values move to constant pkg.

Second, the Add function added a extraApprovalConditions array, to allow the csr controller to accept and use customized approval conditions.


What I want to achieve, is in the future, we can have more approvalConditions defined and implementated in their our pkg(for example, flightctl approve stays in the flightctl pkg with other flight logic code), when we add new approval condition, the csr controller don't need to change much.

Choose a reason for hiding this comment

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

Copilot reviewed 5 out of 7 changed files in this pull request and generated no suggestions.

Files not reviewed (2)
  • pkg/controller/csr/csr_controller.go: Evaluated as low risk
  • pkg/controller/csr/csr_controller_test.go: Evaluated as low risk
Comments skipped due to low confidence (1)

pkg/controller/controller.go:49

  • Ensure that the new behavior introduced by extraApprovalConditions in csr.Add is covered by tests.
[]func(ctx context.Context, csr *certificatesv1.CertificateSigningRequest) (bool, error){})
@xuezhaojun
Copy link
Contributor Author

/assign @zhujian7

)

var log = logf.Log.WithName("controller_csr")

func getClusterName(csr *certificatesv1.CertificateSigningRequest) (clusterName string) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the first change, move to helpers pkg

)

// Add creates a new CSR Controller and adds it to the Manager. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
func Add(ctx context.Context,
mgr manager.Manager,
clientHolder *helpers.ClientHolder) error {
clientHolder *helpers.ClientHolder,
extraApprovalConditions []func(ctx context.Context, csr *certificatesv1.CertificateSigningRequest) (bool, error)) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the second change, now the Add function accept extraApprovalConditions.

@zhujian7
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Nov 23, 2024
@zhujian7
Copy link
Contributor

/approve

Copy link

openshift-ci bot commented Nov 23, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: xuezhaojun, zhujian7

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

Copy link

openshift-ci bot commented Nov 23, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: xuezhaojun, zhujian7

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-bot openshift-merge-bot bot merged commit 0f1f6b3 into stolostron:main Nov 23, 2024
10 checks passed
@xuezhaojun xuezhaojun deleted the move-common-functions-outof-csr-controller branch November 25, 2024 01:45
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.

2 participants