Skip to content

fix: better management of relative paths#608

Merged
ralgozino merged 14 commits intomainfrom
feat/relative-paths-code-reuse
Jun 6, 2025
Merged

fix: better management of relative paths#608
ralgozino merged 14 commits intomainfrom
feat/relative-paths-code-reuse

Conversation

@ralgozino
Copy link
Copy Markdown
Member

@ralgozino ralgozino commented May 12, 2025

Summary 💡

  • Improve management of relative paths, calculating them once.
  • Set outdir globally and reuse it instead of recalculating it on each command.
  • Reduce code duplication (still lots to improve)
  • Move flags processing to helper func when present
  • Improve UX on some error messages, help messages and debug messages
  • Normalise wording in help messages

Fixes #508

Description 📝

The main goal of this PR is to fix an issue when setting outdir to a relative path (like .) resulted in an error on the apply command (and others).

The issue was caused by several problems, but mainly:

  1. outdir was calculated as a permanent pre-run of the root command, but overwritten later
  2. using relative paths without calculating the absolute path at the right moment, the workdir could change, specially for tools that are run by shelling out (like kubectl, kapp, etc.)
  3. the code that was calculating this paths is repeated in several places, sometimes not even aligned.

In this PR I tried to fix these 3 issues, by having the root command update the flags with the right values and reusing them when possible. Also, in each command I moved the logic that handles the flags parsing to the dedicated function (if it was present).

I also took the chance to improve the UX, by adding some details to the messages that we show the user, adding some more debug logs, and unifying the style of the help messages.

I tried to not do a complete overhaul of the code to avoid breaking stuff and making this PR self-contained. We should make more of this iterative improvements. I think that this PR is a step in the right direction.

Breaking Changes 💔

None

Tests performed 🧪

  • Tested that all the modified commands still work as expected:
    • Create PKI
    • Create config
    • Validate config
    • On-prem cluster creation
    • Download dependencies
    • Validate dependencies
    • Dump templates
    • Diff
    • Get kubeconfig
    • Get supported-version
    • Get upgrade-paths
    • Renew certificates
    • Delete cluster

Future work 🔧

There's still a lot of code duplication, the flags processing can probably be improved and there should be a way to handle them more smartly. We use almost the same flags on several commands.

@ralgozino ralgozino self-assigned this May 12, 2025
@ralgozino ralgozino added bug Something isn't working enhancement New feature or request labels May 12, 2025
@ralgozino ralgozino requested review from Filo01, kriive, nutellinoit and stefanoghinelli and removed request for kriive May 12, 2025 16:47
@ralgozino ralgozino marked this pull request as ready for review May 12, 2025 16:48
@ralgozino ralgozino force-pushed the feat/relative-paths-code-reuse branch from d972d00 to 45b01a7 Compare May 16, 2025 09:50
ralgozino added 8 commits May 22, 2025 16:12
- Improve management of relative paths, calculating them once.
- Set outdir globally and reuse.
- Reduce code duplication (still lots to improve)
- Move flags processing to helper func when present
- Improve UX on some error messages, help messages and debug messages
- Normalize words in help messages
Fixes #508
- Fix logic on some commands now that we have outdir always set to an absolute path
- Fix some UX messages
Put var name between qoutes in the error message to make evident if there is a space in the
env var name, for exmaple.
mention that the changes are not potentially safe, the user already knows
they are applying new configuration.
@ralgozino ralgozino force-pushed the feat/relative-paths-code-reuse branch from 45b01a7 to ea469c0 Compare May 22, 2025 14:29
Copy link
Copy Markdown
Contributor

@kriive kriive left a comment

Choose a reason for hiding this comment

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

some nitpicks but overall LGTM!

Comment thread cmd/root.go
Comment thread cmd/root.go Outdated
Comment thread cmd/root.go
Comment thread cmd/root.go Outdated
Comment thread cmd/root.go Outdated
Comment thread cmd/dump/template.go
Comment thread cmd/get/kubeconfig.go
Comment thread cmd/get/kubeconfig.go
Comment thread cmd/validate/dependencies.go
Comment thread cmd/validate/dependencies.go
ralgozino and others added 2 commits May 30, 2025 18:58
define `err` variable in func output instead of standalone

Co-authored-by: Manuel Romei <manuel.romei@reevo.it>
kriive
kriive previously approved these changes May 30, 2025
Copy link
Copy Markdown
Contributor

@kriive kriive left a comment

Choose a reason for hiding this comment

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

Linter's failing on my idiomatic suggestions ¯_(ツ)_/¯ let's revert my code suggestions and follow the linter (which I do not agree with btw lol)

This reverts commit a9be1df.

The change did not pass the linting checks.
ralgozino and others added 3 commits June 3, 2025 10:17
Co-authored-by: Manuel Romei <manuel.romei@reevo.it>
Error out when phase and post-apply-phases are set, post-apply-phases will be ignored when phase is set.

We should probably support both flags simultaneously in the future, but now at least we error out instead of ignoring the post-apply-phases flag.

Relates: #602
@ralgozino
Copy link
Copy Markdown
Member Author

ralgozino commented Jun 3, 2025

Linter's failing on my idiomatic suggestions ¯_(ツ)_/¯ let's revert my code suggestions and follow the linter (which I do not agree with btw lol)

Yeah, I liked your suggestions. It looked cleaner, but the linter has a point: https://github.com/FireFart/nonamedreturns

I also added a check for when --phase and --post-apply-phases are simultaneously defined, erroring out with a message until we decide what to do (see #602 and #600). Until now the --post-apply-phases flag was being silently ignored if --phase was also specified.

@ralgozino ralgozino requested a review from kriive June 3, 2025 11:00
Copy link
Copy Markdown
Contributor

@kriive kriive left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@ralgozino ralgozino merged commit d472ac3 into main Jun 6, 2025
1 check passed
@ralgozino ralgozino deleted the feat/relative-paths-code-reuse branch June 6, 2025 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--outdir . flag value makes furyctl not working correctly

2 participants