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(app): Add optional 'name' to Source object #20470

Merged
merged 2 commits into from
Nov 18, 2024

Conversation

CefBoud
Copy link
Contributor

@CefBoud CefBoud commented Oct 20, 2024

Closes #17731

Description

This PR adds an optional 'name' to the Application Source object. It can be used instead of the source position in multi-source Applications CLI.

Screenshots

image
image
image

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.
  • Optional. My organization is added to USERS.md.
  • Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

Copy link

bunnyshell bot commented Oct 20, 2024

❌ Preview Environment deleted from Bunnyshell

Available commands (reply to this comment):

  • 🚀 /bns:deploy to deploy the environment

@CefBoud CefBoud changed the title feat(app): add Name to ApplicationSource Add optional name reference to Source object Oct 20, 2024
@CefBoud CefBoud changed the title Add optional name reference to Source object Add optional 'name' to Source object Oct 20, 2024
@CefBoud CefBoud force-pushed the feat/add-name-multisource-apps branch from 220edee to b9e648b Compare October 20, 2024 17:21
@CefBoud CefBoud changed the title Add optional 'name' to Source object feat(app): Add optional 'name' to Source object Oct 20, 2024
@CefBoud CefBoud force-pushed the feat/add-name-multisource-apps branch from b9e648b to a45c12b Compare October 20, 2024 23:08
Copy link
Member

@nitishfy nitishfy left a comment

Choose a reason for hiding this comment

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

If this PR is ready for review, can you go ahead and fix the CI checks?

@CefBoud CefBoud force-pushed the feat/add-name-multisource-apps branch 3 times, most recently from d70723f to f490b1d Compare October 21, 2024 23:12
@CefBoud CefBoud marked this pull request as ready for review October 22, 2024 00:18
@CefBoud CefBoud requested review from a team as code owners October 22, 2024 00:18
@CefBoud CefBoud force-pushed the feat/add-name-multisource-apps branch from f490b1d to e2650a1 Compare October 22, 2024 00:28
@CefBoud CefBoud marked this pull request as draft October 22, 2024 13:02
@CefBoud CefBoud force-pushed the feat/add-name-multisource-apps branch 3 times, most recently from bc501b0 to ed5b9b6 Compare October 23, 2024 00:49
@CefBoud CefBoud marked this pull request as ready for review October 25, 2024 19:08
@CefBoud CefBoud force-pushed the feat/add-name-multisource-apps branch 3 times, most recently from 01ba671 to 39b0038 Compare October 26, 2024 21:42
Copy link
Member

@agaudreault agaudreault left a comment

Choose a reason for hiding this comment

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

Good work 👍 The code changes are missing unit tests and maybe e2e too on the different commands. @ishitasequeira has more knowledge on the usage of multi-source. Do you see something that has been forgotten in this PR?

cmd/util/app.go Show resolved Hide resolved
test/e2e/app_multiple_sources_test.go Show resolved Hide resolved
Copy link
Member

@ishitasequeira ishitasequeira left a comment

Choose a reason for hiding this comment

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

@CefBoud Thanks for taking this up!! Left some comments. Also, I think this change would also need to be reflected on the Application Create and AddSource UI Pages too.

@@ -381,6 +396,19 @@ func NewApplicationGetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Com
})
errors.CheckError(err)

if sourceName != "" && sourcePosition != -1 {
Copy link
Member

Choose a reason for hiding this comment

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

Since the Name parameter has been added to the ApplicationSource object, it's not exclusive to multi-source applications. This means the name field also applies to single-source apps. Therefore, in all commands where we’re adding the sourceName check, we should ensure the command supports single-source applications as well, using the sourceName field.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ishitasequeira Thank you for the review.
My reasoning was that although the field is defined in ApplicationSource, much like Ref and the implicit source-position, it only should be considered in the multi-source case. Additionally, the purpose of the proposal was to offer an alternative to source-position in the multi-source case.
What are your thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

That works for me. Although, let's update the comment on the Name field in types.go to reflect that it is mainly used for multi-source apps.

@@ -435,6 +463,7 @@ func NewApplicationGetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Com
command.Flags().BoolVar(&hardRefresh, "hard-refresh", false, "Refresh application data as well as target manifests cache")
command.Flags().StringVarP(&appNamespace, "app-namespace", "N", "", "Only get application from namespace")
command.Flags().IntVar(&sourcePosition, "source-position", -1, "Position of the source from the list of sources of the app. Counting starts at 1.")
command.Flags().StringVar(&sourceName, "source-name", "", "Name of the source from the list of sources of the app.")
Copy link
Member

Choose a reason for hiding this comment

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

Same here, considering Name is not specific to a multi-source app, the description might need an update.

@@ -751,6 +753,8 @@ func ConstructSource(source *argoappv1.ApplicationSource, appOpts AppOptions, fl
setPluginOptEnvs(source, appOpts.pluginEnvs)
case "ref":
source.Ref = appOpts.ref
case "source-name":
source.Name = appOpts.SourceName
Copy link
Member

Choose a reason for hiding this comment

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

We should be checking if the name is already assigned to some other source within the app.spec.sources before allowing to set it.

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 added the check in validateAndNormalizeApp to have a central validation for the both the UI and CLI API calls.

@CefBoud CefBoud force-pushed the feat/add-name-multisource-apps branch 2 times, most recently from 12252d8 to 0a9d9ac Compare October 31, 2024 00:38
@CefBoud CefBoud force-pushed the feat/add-name-multisource-apps branch from 0a9d9ac to 1376663 Compare October 31, 2024 01:45
Copy link

codecov bot commented Oct 31, 2024

Codecov Report

Attention: Patch coverage is 0.64516% with 154 lines in your changes missing coverage. Please review.

Project coverage is 55.01%. Comparing base (0f872f5) to head (2c069d0).
Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
cmd/argocd/commands/app.go 0.00% 145 Missing ⚠️
server/application/application.go 0.00% 6 Missing and 1 partial ⚠️
cmd/util/app.go 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #20470      +/-   ##
==========================================
- Coverage   55.17%   55.01%   -0.16%     
==========================================
  Files         324      324              
  Lines       55256    55397     +141     
==========================================
- Hits        30487    30479       -8     
- Misses      22156    22300     +144     
- Partials     2613     2618       +5     

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

@@ -191,6 +191,8 @@ type ApplicationSource struct {
Chart string `json:"chart,omitempty" protobuf:"bytes,12,opt,name=chart"`
// Ref is reference to another source within sources field. This field will not be used if used with a `source` tag.
Ref string `json:"ref,omitempty" protobuf:"bytes,13,opt,name=ref"`
// Name is used to refer to a source and is displayed in the UI.
Copy link
Member

Choose a reason for hiding this comment

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

Considering we want this to be of use only for a multi-source app, can we update the comment to reflect the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing. Updated.

@@ -381,6 +396,19 @@ func NewApplicationGetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Com
})
errors.CheckError(err)

if sourceName != "" && sourcePosition != -1 {
Copy link
Member

Choose a reason for hiding this comment

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

That works for me. Although, let's update the comment on the Name field in types.go to reflect that it is mainly used for multi-source apps.

@CefBoud CefBoud force-pushed the feat/add-name-multisource-apps branch from 1376663 to 129a95b Compare November 4, 2024 13:34
@CefBoud CefBoud force-pushed the feat/add-name-multisource-apps branch from 129a95b to b96f1db Compare November 4, 2024 14:35
Copy link
Member

@ishitasequeira ishitasequeira left a comment

Choose a reason for hiding this comment

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

The PR looks good!! Thanks @CefBoud!!

@ishitasequeira
Copy link
Member

@agaudreault do you still have any concerns on the PR?

cmd/argocd/commands/app.go Show resolved Hide resolved
if pos, ok := sourceNameToPosition[sourceName]; !ok {
log.Fatalf("Unknown source name '%s'", sourceName)
} else {
sourcePosition = int(pos)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why convert to int instead of using int in getSourceNameToPositionMap?

Copy link
Contributor Author

@CefBoud CefBoud Nov 11, 2024

Choose a reason for hiding this comment

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

int64 is already being used for sourcePosition in other places.

} else {
sourcePosition = int(pos)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Create a helper function for getting the position, since this code is copy-pasted between multiple commands.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The returned map is sometimes used in a loop rather than directly in an if statement. Its usage varies, especially when it’s reused within loops. Using a function would also require checking if the name exists, which means an additional if statement would be needed with the function. As a result, I'm not sure it would offer much more conciseness.

} else {
sourcePosition = int(pos)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a helper function.

@@ -204,6 +205,11 @@ export const SourcePanel = (props: {
</div>
</div>
</div>
<div className='row argo-form-row'>
<div className='columns small-10'>
<FormField formApi={api} label='Name' field={'spec.source.name'} component={Text}></FormField>
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we do an optional param checks, since source and name may not be present?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Their values are initialized with an empty string.

Copy link
Member

@agaudreault agaudreault left a comment

Choose a reason for hiding this comment

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

LGTM. Just missing tests on the errors cases for the new parameter

@CefBoud CefBoud force-pushed the feat/add-name-multisource-apps branch 2 times, most recently from 2301a0b to cad6a1a Compare November 12, 2024 14:06
@CefBoud CefBoud force-pushed the feat/add-name-multisource-apps branch from cad6a1a to 31c0cf8 Compare November 12, 2024 14:13
@CefBoud
Copy link
Contributor Author

CefBoud commented Nov 12, 2024

Thank you for the reviews. @agaudreault @ishitasequeira @andrii-korotkov-verkada

@agaudreault I added tests to check for param errors.

@agaudreault agaudreault enabled auto-merge (squash) November 18, 2024 20:21
@agaudreault agaudreault merged commit 83953fe into argoproj:master Nov 18, 2024
26 checks passed
dmosesson pushed a commit to dmosesson/argo-cd that referenced this pull request Nov 20, 2024
adriananeci pushed a commit to adriananeci/argo-cd that referenced this pull request Dec 4, 2024
Signed-off-by: cef <[email protected]>
Co-authored-by: Alexandre Gaudreault <[email protected]>
Signed-off-by: Adrian Aneci <[email protected]>
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.

Add optional name reference to Source object
5 participants