-
Notifications
You must be signed in to change notification settings - Fork 798
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
Fix issue in extraCommandArgs field #1541
base: master
Are you sure you want to change the base?
Conversation
c2b7eb0
to
e8ed105
Compare
e8ed105
to
06d0795
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.
I don't see any logic to address the 3rd problem reported in the Jira issue
3. Adding argument and value as a single element causes the pod to crash
Other than that, it looks good to me.
Thanks John, for 3rd point -
|
|
Re-ran the tests |
Signed-off-by: Rizwana777 <[email protected]>
All the tests are passing now |
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.
@Rizwana777 - Can we allow users to override params? There may be cases where tuning of default params could be useful.
14f8f29
to
9624248
Compare
Signed-off-by: Rizwana777 <[email protected]>
9624248
to
0079ddb
Compare
@svghadi I have updated the code which allow the users to override existing params, PTAL |
// appendUniqueArgs appends extraArgs to cmd while ignoring any duplicate flags. | ||
func appendUniqueArgs(cmd []string, extraArgs []string) []string { | ||
// Parse cmd into a map to track flags and their indices | ||
existingArgs := make(map[string]int) // Map to track index of each flag in cmd |
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.
Based on our Slack discussion, could you try using a map[string]string
to simplify the logic?
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.
@svghadi I tried updating the logic to use map[string]string but found issues as mentioned-
-
map[string]string creates a map of flags to values, meaning it's expecting each flag to be associated with a value (or an empty string if no value is provided) this approach has the risk of treating arguments like --staticassets as executable commands if there is an issue in the flag parsing. If the function expects this argument to be passed as part of a command and it's incorrectly handled (i.e., not paired with a valid value), this could lead to the error like - create failed: unable to start container process: exec: "--staticassets": executable file not found in $PATH"
-
On the other hand, map[string]int keeps track of the exact positions of flags in the original cmd array, so any updates or additions to cmd are carefully done by index. This prevents the accidental misinterpretation of arguments and ensures the correct structure for the final command.
I may be mistaken, but PTAL and let me know your thoughts. I'm open to any suggestions
Signed-off-by: Rizwana777 <[email protected]>
337c5e3
to
33b914b
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.
In addition, it appears that ExtraRepoCommandArgs
, which controls extra repo server args, is missing from this PR.
@@ -350,6 +343,59 @@ func isMergable(extraArgs []string, cmd []string) error { | |||
return nil | |||
} | |||
|
|||
// appendUniqueArgs appends extraArgs to cmd while ignoring any duplicate flags. |
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 see this PR has similar unit tests for other functions, but can we also add a unit test for this function?
The logic in this function is complex (given the large possible variation in inputs), so I'd like to ensure we have an exhaustive list of test cases that verify the possible cases we can think of that this function might be asked to handle.
JIRA - https://issues.redhat.com/browse/GITOPS-5200