Skip to content

Add support for target annotations and labels - #582

Merged
cert-manager-prow[bot] merged 1 commit into
cert-manager:mainfrom
terricain:23_label_template
Apr 22, 2025
Merged

cert-manager-prow[bot] merged 1 commit into
cert-manager:mainfrom
terricain:23_label_template

Conversation

@terricain

Copy link
Copy Markdown
Contributor

This adds template fields to specify labels and annotations for the target configmaps and secrets along with some extra validation logic to prevent clobbering trust.cert-manager.io labels and annotations.

apiVersion: trust.cert-manager.io/v1alpha1
kind: Bundle
metadata:
  name: test
spec:
  sources:
    ...
  target:
    secretTemplate:
      labels: {}
      annotations: {}
    configMapTemplate:
      labels: {}
      annotations: {}

@erikgb before I go and write some tests, do we like these field names? or would the following look better? Naming things is the worst, if someone has any better ideas then I'm all for it 😆

apiVersion: trust.cert-manager.io/v1alpha1
kind: Bundle
metadata:
  name: test
spec:
  sources:
    ...
  target:
    configMap:
      key: "root-certs.pem"
      template:
        labels: {}
        annotations: {}
    secret:
      key: "root-certs.pem"
      template:
        labels: {}
        annotations: {}

Fixes #23

@cert-manager-prow cert-manager-prow 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. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 7, 2025
@cert-manager-prow

Copy link
Copy Markdown
Contributor

Hi @terricain. Thanks for your PR.

I'm waiting for a cert-manager member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@cert-manager-prow cert-manager-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 7, 2025
@erikgb

erikgb commented Apr 8, 2025

Copy link
Copy Markdown
Member

Yeah, naming is the hardest thing we do. 🤔 And this is mixed with API design.

I am working on the next version of the bundle API: #486. It might be worth checking that this fits in there also.

Another slightly modified suggestion from me:

apiVersion: trust.cert-manager.io/v1alpha1
kind: Bundle
metadata:
  name: test
spec:
  sources:
    ...
  target:
    configMap:
      key: "root-certs.pem"
      metadata:
        labels: {}
        annotations: {}
    secret:
      key: "root-certs.pem"
      metadata:
        labels: {}
        annotations: {}
````

I'll bring this up on today's stand-up. Would you like to join? It's at 10:30 UK time. 😺 

@erikgb

erikgb commented Apr 8, 2025

Copy link
Copy Markdown
Member

@terricain, we discussed this PR in today's stand-up, and we think we prefer my suggestion in #582 (comment). Do you want to become a member of our organization? This will, among others, allow your PRs to be enabled for CI without approval from other members. How to become a member is described here: https://github.com/cert-manager/community/blob/main/GOVERNANCE.md#becoming-a-github-member. I would be happy to sponsor your membership!

@terricain

Copy link
Copy Markdown
Contributor Author

I'd have joined the standup if I had read this in time 😄 (also how does one join the standup? I've only found links to a biweekly zoom meeting)

Yep I'll raise an issue to become an org member once I find a 2nd to sponsor it, I think you've got to all my PR's so far so haven't interacted with anyone else yet.

#582 (comment) agreed, this looks much better than what I initially came up with, and should transfer nicely to the proposed API version in #486 (+1 for renaming it to ClusterBundle, makes the fact its not a namespaced resource much more obvious)

Is it worth fixing up this PR and getting it merged or waiting till the new API is merged?

@erikgb

erikgb commented Apr 9, 2025

Copy link
Copy Markdown
Member

I'd have joined the standup if I had read this in time 😄 (also how does one join the standup? I've only found links to a biweekly zoom meeting)

I have done this only once, but I think you will get invites to all meetings by joining our mailing lists, ref. https://cert-manager.io/docs/contributing/#meetings.

Yep I'll raise an issue to become an org member once I find a 2nd to sponsor it, I think you've got to all my PR's so far so haven't interacted with anyone else yet.

I am pretty sure we should be able to find another sponsor. Didn't you talk with @maelvls at KubeCon ContribFest?

Is it worth fixing up this PR and getting it merged or waiting till the new API is merged?

Please finish this PR! The new API is still far from finalized, and this PR will fix a requested feature.

@cert-manager-prow cert-manager-prow Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 12, 2025
@terricain

Copy link
Copy Markdown
Contributor Author

Updated API to use:

apiVersion: trust.cert-manager.io/v1alpha1
kind: Bundle
metadata:
  name: test
spec:
  sources:
    ...
  target:
    configMap:
      key: "root-certs.pem"
      metadata:
        labels: {}
        annotations: {}
    secret:
      key: "root-certs.pem"
      metadata:
        labels: {}
        annotations: {}

Tried adding some CEL expressions to validate that the annotations and labels didn't start with prefixes we care about but couldn't seem to get it to work without it looking ugly so have left the regular webhook validations in.

The KeySelector struct was used for the JKS and PKCS12 parts of the API as well as the target ConfigMap/Secret, it didn't make sense for the JKS/PKCS12 fields to have a metadata field so moved them to use a different struct with just Key. That and there were less occurrences of that to change than if I changed KeySelector for the ConfigMap/Secret. If there is a nicer way to achieve this let me know 😄.

The changes might be easier to look at commit-by-commit


Was getting some inconsistent connection refused errors with the ciphers test so added in a small loop there to wait for the webhook server to start.

@terricain
terricain marked this pull request as ready for review April 12, 2025 21:44
@cert-manager-prow cert-manager-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 12, 2025
@erikgb

erikgb commented Apr 12, 2025

Copy link
Copy Markdown
Member

/ok-to-test

@cert-manager-prow cert-manager-prow Bot added ok-to-test and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 12, 2025
@erikgb

erikgb commented Apr 12, 2025

Copy link
Copy Markdown
Member

Was getting some inconsistent connection refused errors with the ciphers test so added in a small loop there to wait for the webhook server to start.

Yeah, I was also struggling with those errors yesterday. I will see if I can reproduce it now and create an issue for it. It should probably be fixed in a separate PR.

I will also try to review your PR tomorrow! Thanks!

@terricain

Copy link
Copy Markdown
Contributor Author

Thanks. Sure happy to pull it out and spin up another PR if you can reproduce it

@erikgb erikgb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for working on this @terricain! ❤️ I did an initial review pass and added a few comments/suggestions.

The most delicate part remaining is probably the "needsUpdate" logic. trust-manager is using server-side apply (SSA), and I have suggested unconditional patching of resources many times to avoid this complex and error-prone logic. But it's still there, so we need to find a good way of determining if target labels/annotations are up-to-date or not.

Comment thread pkg/apis/trust/v1alpha1/types_bundle.go Resolved
Comment thread pkg/apis/trust/v1alpha1/types_bundle.go Resolved
Comment thread pkg/bundle/internal/target/target.go Resolved
Comment thread pkg/bundle/internal/target/target.go Resolved
Comment thread pkg/bundle/internal/target/target.go Resolved
Comment thread pkg/bundle/internal/target/target.go Resolved
Comment thread pkg/bundle/internal/target/target.go Resolved
@cert-manager-prow cert-manager-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 16, 2025
@cert-manager-prow cert-manager-prow Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Apr 20, 2025
@terricain

Copy link
Copy Markdown
Contributor Author

Thanks for the review @erikgb, tons of good suggestions 🙂.

I updated the v1alpha2 ClusterBundle with what I added to v1alpha1 Bundle as it looks like for now its just a copy that isn't really uesd?

I think I've addressed all the comments, I resolved a few that were outdated/easy fixes.

@erikgb

erikgb commented Apr 20, 2025

Copy link
Copy Markdown
Member

I updated the v1alpha2 ClusterBundle with what I added to v1alpha1 Bundle as it looks like for now its just a copy that isn't really used?

Yes, that's correct. ClusterBundle is now just a copy of Bundle, and the API generation is disabled. I have #486 in progress, but I will take this new feature into consideration when merged.

I think I've addressed all the comments, I resolved a few that were outdated/easy fixes.

Cool, thanks! I will make another review pass soon.

@erikgb erikgb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Excellent work, @terricain! 🚀 This PR is pretty close to being mergeable. I have added a few comments/suggestions, but mostly nits.

Comment thread pkg/apis/trust/v1alpha1/types_bundle.go Resolved
Comment thread pkg/apis/trust/v1alpha1/types_bundle.go Resolved
Comment thread pkg/bundle/internal/target/target.go Resolved
Comment thread pkg/bundle/internal/target/target.go Resolved
Comment thread pkg/webhook/validation.go Resolved
Comment thread pkg/webhook/validation.go Resolved
Comment thread pkg/webhook/validation.go Resolved
@terricain

Copy link
Copy Markdown
Contributor Author

Thanks again for the review 🙂, I've fixed the nits, also made the TrustTemplate getters nil-safe which makes things look cleaner.

Whats the procedure for the diff conversations, does the author or reviewer resolve them?

@erikgb

erikgb commented Apr 22, 2025

Copy link
Copy Markdown
Member

Thanks again for the review 🙂, I've fixed the nits, also made the TrustTemplate getters nil-safe which makes things look cleaner.

Nice, thanks!

Whats the procedure for the diff conversations, does the author or reviewer resolve them?

Not sure if we have a practice around this. Either works.

@erikgb erikgb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the stamina on this. A couple of tiny nits I missed the last time.

Could you also please rebase and squash commits to make the commit history a bit cleaner?

/lgtm
/approve
/hold

Comment thread pkg/apis/trust/v1alpha1/types_bundle.go Resolved
Comment thread pkg/apis/trust/v1alpha1/types_bundle.go Resolved
Comment thread pkg/bundle/internal/target/target.go Resolved
@cert-manager-prow cert-manager-prow Bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. labels Apr 22, 2025
@cert-manager-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: erikgb

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

The pull request process is described here

Details 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

@cert-manager-prow cert-manager-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 22, 2025
@cert-manager-prow cert-manager-prow Bot removed the lgtm Indicates that a PR is ready to be merged. label Apr 22, 2025
@terricain

Copy link
Copy Markdown
Contributor Author

Have squashed the commits down to 2, mainly as one of the commits was authored by you, let me know if you want that squashed too.

Fixed the nits 😄

@erikgb

erikgb commented Apr 22, 2025

Copy link
Copy Markdown
Member

Have squashed the commits down to 2, mainly as one of the commits was authored by you, let me know if you want that squashed too.

Please squash everything into a single commit! I don't need credits for this work. You did most of the job!

* Added target metadata to v1alpha2.ClusterBundle
* Added metadata unit tests & integration test
* Added validation rules to prevent target annotations/labels overwriting trust-manager ones

Signed-off-by: Terri Cain <[email protected]>
@terricain

Copy link
Copy Markdown
Contributor Author

Ah you helped a fair bit 😄. Done.

@erikgb erikgb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great work! Thanks a lot for adding this new feature! 🚀
Hoping for more nice contributions from you, @terricain!

/lgtm
/unhold

@cert-manager-prow cert-manager-prow Bot added lgtm Indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Apr 22, 2025
@cert-manager-prow
cert-manager-prow Bot merged commit 3036763 into cert-manager:main Apr 22, 2025
@erikgb

erikgb commented Apr 22, 2025 •

Copy link
Copy Markdown
Member

Do you mind creating a PR to update the website docs, @terricain? 🙏

@terricain
terricain deleted the 23_label_template branch April 22, 2025 20:48
@terricain

Copy link
Copy Markdown
Contributor Author

Yep, that is next on my todo list 😄

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. ok-to-test size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow templating of labels/annotations on target configmaps/secrets

2 participants