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 label selector option for Secret and ConfigMap sources #258

Merged
merged 16 commits into from
Jan 15, 2024

Conversation

ocampeau
Copy link
Contributor

@ocampeau ocampeau commented Dec 21, 2023

This PR adds support to use label selector for Secret and ConfigMap sources.

Given a Bundle that looks like this:

apiVersion: trust.cert-manager.io/v1alpha1
kind: Bundle
metadata:
  name: some-bundle
spec:
  sources:
  - useDefaultCAs: true
  - configMapLabelSelector:
      key: ca.crt
      selector:
        matchLabels:
          fruit: apple
  - secretMapLabelSelector:
      key: ca.crt
      selector:
        matchLabels:
          fruit: banana
  target:
    configMap:
      key: ca.crt

this behavior will happen:

  • all Secret that has label fruit: banana and a key ca.crt will have the value of ca.crt included in the Bundle
  • all ConfigMap that has label fruit: apple and a key ca.crt will have the value of ca.crt included in the Bundle

Multiple configMapLabelSelector and secretMapLabelSelector are supported.

In a case like this:

apiVersion: trust.cert-manager.io/v1alpha1
kind: Bundle
metadata:
  name: some-bundle
spec:
  sources:
  - useDefaultCAs: true
  - configMapLabelSelector:
      key: ca.crt
      selector:
        matchLabels:
          fruit: apple
  - configMapLabelSelector:
      key: ca.crt
      selector:
        matchLabels:
          fruit: banana
  target:
    configMap:
      key: ca.crt

then:

  • all ConfigMap that has label fruit: banana and a key ca.crt will have the value of ca.crt included in the Bundle
  • all ConfigMap that has label fruit: apple and a key ca.crt will have the value of ca.crt included in the Bundle

fixes #256

@jetstack-bot jetstack-bot added 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 Dec 21, 2023
@jetstack-bot
Copy link
Contributor

Hi @ocampeau. 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.

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/test-infra repository.

@jetstack-bot jetstack-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. dco-signoff: no Indicates that at least one commit in this pull request is missing the DCO sign-off message. and removed dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. labels Dec 21, 2023
Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>

chore(apis): add comments to new types

Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>

chore(lint): undo remove whiteline

chore(lint): undo remove whiteline

chore(lint): undo remove whiteline

Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>

chore(lint): undo remove whiteline

Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>
@jetstack-bot jetstack-bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. and removed dco-signoff: no Indicates that at least one commit in this pull request is missing the DCO sign-off message. labels Dec 21, 2023
@erikgb
Copy link
Contributor

erikgb commented Dec 25, 2023

I wonder if we need to extend the API with "new source types"; could we instead just extend the existing source configMap and secret types to allow either name or selector? Making the following bundle valid:

apiVersion: trust.cert-manager.io/v1alpha1
kind: Bundle
metadata:
  name: some-bundle
spec:
  sources:
  - useDefaultCAs: true
  - configMap:
      key: ca.crt
      name: my-configmap
  - configMap:
      key: ca.crt
      selector:
        matchLabels:
          fruit: apple
  - secret:
      key: ca.crt
      name: my-secret
  - secret:
      key: ca.crt
      selector:
        matchLabels:
          fruit: banana
  target:
    configMap:
      key: ca.crt

@ocampeau
Copy link
Contributor Author

Yeah definitely! I will update my PR to reuse the existing source type like you mention. It's much better like that.

Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>
Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>

improve readability

Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>

improve readability

Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>

improve readability

Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>

improve readability

Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>

update comments

Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>

update comment
@ocampeau
Copy link
Contributor Author

It's done. Let me know what you think.

@SgtCoDFish
Copy link
Member

/ok-to-test

@jetstack-bot jetstack-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 Jan 2, 2024
Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>
Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>
Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>
Copy link
Contributor

@erikgb erikgb left a comment

Choose a reason for hiding this comment

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

Added some review comments, but mostly nits. I am prepared to move forward with this PR when the code looks good. Well done @ocampeau! 😍

pkg/apis/trust/v1alpha1/types_bundle.go Outdated Show resolved Hide resolved
pkg/apis/trust/v1alpha1/types_bundle.go Outdated Show resolved Hide resolved
pkg/apis/trust/v1alpha1/types_bundle.go Outdated Show resolved Hide resolved
pkg/bundle/sync.go Outdated Show resolved Hide resolved
pkg/apis/trust/v1alpha1/types_bundle.go Show resolved Hide resolved
pkg/bundle/sync.go Outdated Show resolved Hide resolved
pkg/webhook/validation.go Outdated Show resolved Hide resolved
pkg/webhook/validation.go Show resolved Hide resolved
ocampeau and others added 5 commits January 7, 2024 21:01
Co-authored-by: Erik Godding Boye <egboye@gmail.com>
Signed-off-by: Olivier Campeau <40877483+ocampeau@users.noreply.github.com>
Co-authored-by: Erik Godding Boye <egboye@gmail.com>
Signed-off-by: Olivier Campeau <40877483+ocampeau@users.noreply.github.com>
Co-authored-by: Erik Godding Boye <egboye@gmail.com>
Signed-off-by: Olivier Campeau <40877483+ocampeau@users.noreply.github.com>
Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>
Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>
Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>
@ocampeau
Copy link
Contributor Author

ocampeau commented Jan 8, 2024

/retest-required

Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>
pkg/bundle/controller.go Outdated Show resolved Hide resolved
pkg/bundle/controller.go Outdated Show resolved Hide resolved
@inteon inteon changed the title add label selector for secret and config map sources Add label selector option for Secret and ConfigMap sources Jan 9, 2024
@inteon
Copy link
Member

inteon commented Jan 9, 2024

@ocampeau This is an awesome new feature❤️!
Thanks a lot for contributing this.
/approve
Can be LGTM'd once the two comments above have been resolved ^^

@jetstack-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: inteon

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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 9, 2024
@ocampeau
Copy link
Contributor Author

ocampeau commented Jan 9, 2024

I have resolved all conversation except this one: #258 (comment)

Let me know if this is acceptable or not.

Thanks a lot for accepting this PR by the way, it will really help us. It was a pleasure to contribute to this project.

Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>

small nits

Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>

remove file

Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>
@ocampeau
Copy link
Contributor Author

Any ETA on when this could potentially be merged? Do you have documentation on the release velocity of this project?

@erikgb
Copy link
Contributor

erikgb commented Jan 11, 2024

Any ETA on when this could potentially be merged? Do you have documentation on the release velocity of this project?

Sorry, I have been very busy lately. Will try to review this weekend if @inteon hasn't reviewed and merged it before.

We have a couple of unreleased changes already, so I would suggest considering releasing 0.8.0 after this PR is merged. WDYT, @inteon? Sorry for the delay, @ocampeau!

Copy link
Contributor

@erikgb erikgb left a comment

Choose a reason for hiding this comment

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

Some minor nits left, but this is close to a LGTM from me!

pkg/bundle/controller.go Outdated Show resolved Hide resolved
pkg/bundle/controller.go Outdated Show resolved Hide resolved
el = append(el, field.Invalid(path, "name: ' ', selector: nil", "must validate one and only one schema (oneOf): [name, selector]. Found none valid"))
}
if len(configMap.Name) > 0 && configMap.Selector != nil {
el = append(el, field.Invalid(path, fmt.Sprintf("name: %s, selector: {}", configMap.Name), "must validate one and only one schema (oneOf): [name, selector]. Found none valid"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
el = append(el, field.Invalid(path, fmt.Sprintf("name: %s, selector: {}", configMap.Name), "must validate one and only one schema (oneOf): [name, selector]. Found none valid"))
el = append(el, field.Invalid(path, fmt.Sprintf("name: %s, selector: {}", configMap.Name), "must validate one and only one schema (oneOf): [name, selector]. Found both set"))

I am not sure about the error message here, but it should indicate that we detected both set - which is invalid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think Found both set is good. It makes sens to me at least.

Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>
Signed-off-by: Olivier Campeau <oli.campeau@gmail.com>
@inteon
Copy link
Member

inteon commented Jan 15, 2024

/lgtm
Thanks a lot for the feature.
After this gets merged, we can do the v0.8.0 release. Also, @ocampeau could you create a documentation PR on the website to document this new feature?

@jetstack-bot jetstack-bot added the lgtm Indicates that a PR is ready to be merged. label Jan 15, 2024
@jetstack-bot jetstack-bot merged commit aa51909 into cert-manager:main Jan 15, 2024
3 of 4 checks passed
@ocampeau
Copy link
Contributor Author

Sure I can add documentation. I'll take a look into it

@ocampeau
Copy link
Contributor Author

Documentation added with this PR: cert-manager/website#1391

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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use label selector to add sources to a bundle
5 participants