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

refactor: simplify getPodName and make consistent with back-end #12964

Merged
merged 8 commits into from
Apr 23, 2024

Conversation

agilgur5
Copy link
Member

@agilgur5 agilgur5 commented Apr 22, 2024

Fixes #6982 (comment), Fixes #9168 (comment)

Motivation

Simplify getPodName as it required lots of args that could be retrieved from the existing Workflow and Node. Simplify surrounding code as well

Make it more consistent to the back-end as well, particularly after #12928.

Modifications

  • simplify calls to getPodName to only require the Workflow and Node as args

    • the rest can be derived from them, so we can remove all the duplicate, extraneous logic from all callers
      • workflow-details.tsx was particularly simplified as a result, a whole function was replaced with a one-liner
    • also make getPodName in the UI more closely match GeneratePodName on the back-end
  • adjust pod-name.test.ts to match the modified args

    • also heavily simplify one of the test suites to cast some types instead of creating an unnecessary structure
  • simplify other parts of pod-name.ts
    • simplify getTemplateNameFromNode to a one-liner that's easier to read and reads like the comment too

    • slightly optimize ensurePodNamePrefixLength by moving the static calculation of maxPrefixLength into the module scope and outside the function scope

      • it does not change per function invocation
      • do the same on the back-end too in pod_name.go
    • use named functions for better tracing compared to const variables assigned to anonymous functions, same as refactor(ui): use named functions for better tracing #12062 et al

Verification

Existing tests pass

Also tested manually with the Workflow from #12895.

Screenshot:

Screenshot 2024-04-22 at 12 17 24 PM

Notes to Reviewers

It's easier to read each commit independently than it is to read the PR as a whole, that's why I split them that way

Future Work

  1. pod-name.ts should only be exporting getPodName. the rest is not used anywhere except for the tests
    • The tests need a good bit of adjustment for this though, so for now, I left them as-is to show they still pass
  2. The back-end's GeneratePodName can similarly be simplified, but it requires a lot more refactoring of functions of up the chain
    • partial workflow information, partial node information, etc gets passed down through a few layers of the call stack

Signed-off-by: Anton Gilgur <agilgur5@gmail.com>
Signed-off-by: Anton Gilgur <agilgur5@gmail.com>
…ion call

Signed-off-by: Anton Gilgur <agilgur5@gmail.com>
- cast the `NodeStatus` instead of filling it all out with unused fields

Signed-off-by: Anton Gilgur <agilgur5@gmail.com>
these seemed to have accidentally diverged in 1e87159

Signed-off-by: Anton Gilgur <agilgur5@gmail.com>
Signed-off-by: Anton Gilgur <agilgur5@gmail.com>
…'t been selected

Signed-off-by: Anton Gilgur <agilgur5@gmail.com>
Signed-off-by: Anton Gilgur <agilgur5@gmail.com>
Copy link
Member

@tczhao tczhao left a comment

Choose a reason for hiding this comment

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

It's easier to read each commit independently than it is to read the PR as a whole, that's why I split them that way

This is gold

@isubasinghe isubasinghe merged commit 671320d into argoproj:main Apr 23, 2024
30 checks passed
@agilgur5 agilgur5 deleted the refactor-simplify-getPodName branch April 23, 2024 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants