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

feat: Support a list of values as string in the generators selectors #20972

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

damsien
Copy link

@damsien damsien commented Nov 27, 2024

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Toolchain Guide
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.

Description

Closes #20943. Add a new valuesString field in the ApplicationSet object. A validation is done using the kubebuilder marker +kubebuilder:validation:XValidation:rule ensuring that either values or valuesString are specified but not both at the same time. The corresponding test have been added as well.

@damsien damsien requested a review from a team as a code owner November 27, 2024 10:02
Copy link

bunnyshell bot commented Nov 27, 2024

🔴 Preview Environment stopped on Bunnyshell

See: Environment Details | Pipeline Logs

Available commands (reply to this comment):

  • 🔵 /bns:start to start the environment
  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

Copy link

codecov bot commented Nov 27, 2024

Codecov Report

Attention: Patch coverage is 69.56522% with 14 lines in your changes missing coverage. Please review.

Please upload report for BASE (master@522d07a). Learn more about missing BASE report.

Files with missing lines Patch % Lines
applicationset/utils/selector.go 73.17% 9 Missing and 2 partials ⚠️
applicationset/generators/cluster.go 40.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master   #20972   +/-   ##
=========================================
  Coverage          ?   55.19%           
=========================================
  Files             ?      324           
  Lines             ?    55615           
  Branches          ?        0           
=========================================
  Hits              ?    30695           
  Misses            ?    22293           
  Partials          ?     2627           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@damsien
Copy link
Author

damsien commented Nov 27, 2024

Hello @OpenGuidou, do you think that this implementation is okay?

@damsien damsien force-pushed the master branch 3 times, most recently from 040acf5 to 8f2fa81 Compare December 4, 2024 15:12
Copy link
Contributor

@OpenGuidou OpenGuidou left a comment

Choose a reason for hiding this comment

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

Can you add new tests to cover the cluster generator and general post selector use cases ?

pkg/apis/application/v1alpha1/applicationset_types.go Outdated Show resolved Hide resolved
pkg/apis/application/v1alpha1/applicationset_types.go Outdated Show resolved Hide resolved
@damsien damsien force-pushed the master branch 2 times, most recently from 28dad89 to 30d9409 Compare December 4, 2024 19:58
@damsien
Copy link
Author

damsien commented Dec 4, 2024

I created these 2 functions:

func ApplicationMatchExpressionToMetaMatchExpression(me argov1alpha1.ApplicationMatchExpression) (*metav1.LabelSelectorRequirement, error) {

func CustomSelectorToMetaSelector(selector argov1alpha1.LabelSelector) (*metav1.LabelSelector, error) {

in order to facilitate the conversion between the custom LabelSelector and the one from k8s metav1.LabelSelector.

One example of why it was necessary can be found in this function:

func (g *ClusterGenerator) getSecretsByClusterName(appSetGenerator *argoappsetv1alpha1.ApplicationSetGenerator) (map[string]corev1.Secret, error) {
// List all Clusters:
clusterSecretList := &corev1.SecretList{}
metaSelector, err := utils.CustomSelectorToMetaSelector(appSetGenerator.Clusters.Selector)
if err != nil {
return nil, err
}
selector := metav1.AddLabelToSelector(metaSelector, common.LabelKeySecretType, common.LabelValueSecretTypeCluster)
secretSelector, err := metav1.LabelSelectorAsSelector(selector)

It uses the metav1.AddLabelToSelector() function. If we don't add a conversion function, then it means that we have to rewrite the exact same AddLabelToSelector() function. I think that it is better to do the conversion as soon as possible in order to have less duplicate code from the metav1 package.

Copy link
Contributor

@OpenGuidou OpenGuidou left a comment

Choose a reason for hiding this comment

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

Great work, LGTM !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support a list of values as string in the generators selectors
2 participants