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

Add functions to ignore certain issuers and/or CertificateRequests, Kubernetes CSRs #37

Merged
merged 3 commits into from
Aug 1, 2023

Conversation

inteon
Copy link
Member

@inteon inteon commented Jul 24, 2023

This new options allows implementers to ignore certain issuers (eg. only reconcile all issuers that live in a specific namespace or only reconcile issuers that have a name starting with a certain prefix).
Also, we can ignore the certificate requests that refer to these issuers.

This is useful when you are partitioning issuers (eg. one instance reconciles all issuers with a certain name prefix, while another issuer instance reconciles the other issuers).

@jetstack-bot jetstack-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 24, 2023
@inteon inteon marked this pull request as ready for review August 1, 2023 07:35
@jetstack-bot jetstack-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 1, 2023
Copy link
Member

@SgtCoDFish SgtCoDFish left a comment

Choose a reason for hiding this comment

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

Got a few comments on this one - what do you think?

Comment on lines 55 to 71
// IgnoreIssuer is an optional function that can prevent the issuer controllers from
// reconciling an issuer resource. By default, the controllers will reconcile all
// issuer resources that match the owned types.
type IgnoreIssuer func(
ctx context.Context,
issuerObject v1alpha1.Issuer,
) (bool, error)

// IgnoreCertificateRequest is an optional function that can prevent the CertificateRequest
// and Kubernetes CSR controllers from reconciling a CertificateRequest resource. By default,
// the controllers will reconcile all CertificateRequest resources that match the issuerRef type.
type IgnoreCertificateRequest func(
ctx context.Context,
cr CertificateRequestObject,
issuerGvk schema.GroupVersionKind,
issuerName types.NamespacedName,
) (bool, error)
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: My understanding of these functions is that someone implementing an issuer using issuer-lib may want to define them for their issuer.

If that's correct, would it be useful in the comments for these functions to describe when and how they're called? At the moment I can understand that these functions can prevent reconciliation but I don't know how or when they do!

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to improve the comments PTAL.

return result, nil, fmt.Errorf("failed to check if issuer should be ignored: %v", err) // retry
}
if ignore {
logger.V(1).Info("Ignoring issuer")
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: I think in Reconcile we log "Starting reconcile loop" with the issuer name at V(2) but here we're logging at V(1).

That means that if the user chose to log at level V(1) they'll see a lot of "Ignoring issuer" messages but they won't see which issuer is being ignored.

Would it make sense to make these log levels match? If I log at V(1) and see tonnes of "ignoring issuer" log lines with no further context I'm not sure that my experience is being improved!

Alternatively, if this log level has to be V(1) then might it be worthwhile adding the namespace + name to the "ignoring issuer" log line?

Copy link
Member Author

Choose a reason for hiding this comment

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

controller-runtime already adds the resource name & namespace as fields in its log messages, that is why the log messages above also use V(1)

Copy link
Member Author

Choose a reason for hiding this comment

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

Starting reconcile loop should not additionally log those fields, that seems like a bug.

Copy link
Member Author

Choose a reason for hiding this comment

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

e.g. this is what the Starting reconcile loop message looks like now:

{
  "level": "Level(-2)",
  "ts": "2023-08-01T14:33:12Z",
  "logger": "SI.Reconcile",
  "msg": "Starting reconcile loop",
  "controller": "certificaterequest",
  "controllerGroup": "cert-manager.io",
  "controllerKind": "CertificateRequest",
  "CertificateRequest": {
    "name": "test-cert-6krjb",
    "namespace": "wvqzpspdtvfsshq"
  },
  "namespace": "wvqzpspdtvfsshq",
  "name": "test-cert-6krjb",
  "reconcileID": "a32cdd0b-7968-41a3-b643-41ebf6e03470"
}

Copy link
Member Author

Choose a reason for hiding this comment

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

for some reason, other log messages also contain both a CertificateRequest and namespace and name field:

{
  "level": "debug",
  "ts": "2023-08-01T14:32:51Z",
  "logger": "SI.Reconcile",
  "msg": "Issuer not found. Waiting for it to be created",
  "controller": "certificaterequest",
  "controllerGroup": "cert-manager.io",
  "controllerKind": "CertificateRequest",
  "CertificateRequest": {
    "name": "test-cert-6krjb",
    "namespace": "wvqzpspdtvfsshq"
  },
  "namespace": "wvqzpspdtvfsshq",
  "name": "test-cert-6krjb",
  "reconcileID": "28baff62-8b42-4a67-a89a-d25a302f7eec"
}

Copy link
Member Author

@inteon inteon Aug 1, 2023

Choose a reason for hiding this comment

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

So, I think there is enough information. But in the future we should revise the logging (possibly improve upstream controller-runtime) & remove the duplicate fields.

@inteon inteon requested a review from SgtCoDFish August 1, 2023 14:45
Copy link
Member

@SgtCoDFish SgtCoDFish left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

Looks great and the comments look easy to follow! Thanks 🚀

@jetstack-bot jetstack-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 1, 2023
@jetstack-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: inteon, SgtCoDFish

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

@jetstack-bot jetstack-bot merged commit 2a7fde6 into main Aug 1, 2023
@SgtCoDFish SgtCoDFish deleted the add_ignore_options branch August 1, 2023 14:50
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. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants