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

Fix issue in extraCommandArgs field #1541

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Rizwana777
Copy link
Contributor

@Rizwana777 Rizwana777 commented Sep 9, 2024

@Rizwana777 Rizwana777 force-pushed the issue-5200 branch 6 times, most recently from c2b7eb0 to e8ed105 Compare September 9, 2024 14:20
Copy link
Collaborator

@jopit jopit left a 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.

@Rizwana777
Copy link
Contributor Author

Rizwana777 commented Sep 23, 2024

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 -

Pod crashes as mentioned in description because ,

'{.spec.server.extraCommandArgs}' ["foo bar"] , here extraCommandArgs is of type []string and we need to pass the flag value i.e, foo as --foo and bar as value like this ["--foo" "bar"] , if we pass values as mentioned pod will not crash, 
and pod crashes as mentioned in description is :
error : Error: unknown flag: --foo
Usage:
argocd-server [flags]
argocd-server [command], as --foo is a flag and we can use available flags

@Rizwana777
Copy link
Contributor Author

FAIL: kuttl/harness/1-036_validate_role_rolebinding_for_source_namespace this e2e test is failing in other PRs as well

@saumeya
Copy link
Collaborator

saumeya commented Sep 24, 2024

Re-ran the tests

@Rizwana777
Copy link
Contributor Author

FAIL: kuttl/harness/1-036_validate_role_rolebinding_for_source_namespace this e2e test is failing in other PRs as well

All the tests are passing now

Copy link
Collaborator

@svghadi svghadi left a 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.

@Rizwana777 Rizwana777 force-pushed the issue-5200 branch 2 times, most recently from 14f8f29 to 9624248 Compare November 8, 2024 12:39
@Rizwana777
Copy link
Contributor Author

@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
Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Member

@jgwest jgwest left a 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.
Copy link
Member

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.

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.

5 participants