-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
feat(app): Add optional 'name' to Source object #20470
Conversation
❌ Preview Environment deleted from BunnyshellAvailable commands (reply to this comment):
|
name
reference to Source object
name
reference to Source object220edee
to
b9e648b
Compare
b9e648b
to
a45c12b
Compare
There was a problem hiding this 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?
d70723f
to
f490b1d
Compare
f490b1d
to
e2650a1
Compare
bc501b0
to
ed5b9b6
Compare
01ba671
to
39b0038
Compare
There was a problem hiding this 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?
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.") |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
12252d8
to
0a9d9ac
Compare
0a9d9ac
to
1376663
Compare
Codecov ReportAttention: Patch coverage is
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. |
@@ -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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
1376663
to
129a95b
Compare
129a95b
to
b96f1db
Compare
There was a problem hiding this 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!!
@agaudreault do you still have any concerns on the PR? |
if pos, ok := sourceNameToPosition[sourceName]; !ok { | ||
log.Fatalf("Unknown source name '%s'", sourceName) | ||
} else { | ||
sourcePosition = int(pos) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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) | ||
} | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) | ||
} | ||
} |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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
2301a0b
to
cad6a1a
Compare
Signed-off-by: cef <[email protected]>
cad6a1a
to
31c0cf8
Compare
Thank you for the reviews. @agaudreault @ishitasequeira @andrii-korotkov-verkada @agaudreault I added tests to check for param errors. |
Signed-off-by: cef <[email protected]> Co-authored-by: Alexandre Gaudreault <[email protected]>
Signed-off-by: cef <[email protected]> Co-authored-by: Alexandre Gaudreault <[email protected]> Signed-off-by: Adrian Aneci <[email protected]>
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
Checklist: