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: allow resolving repo root as jsonnt lib path #11119

Merged

Conversation

shuai-zh
Copy link
Contributor

@shuai-zh shuai-zh commented Oct 31, 2022

When testing with the below app setup, rpc error: code = Unknown desc = value file '.' resolved to outside repository root error was thrown unexpectedly (if not by design) during the sync process.

Setup

Folder structure

repo-root
|--app
|----main.jsonnet
|--vendor
|----lib.libsonnet

main.jsonnet

local lib = import 'vendor/lib.libsonnet' # import path not allowed to change for some reason
#...

ArgoCD Application

spec:
  #...
  source:
    #...
    path: app
    directory:
      jsonnet:
        libs:
          - . # <- intended to point to repo-root

Simulated jsonnet command

The following command work well locally:

jsonnet -J . app/main.jsonnet

Troubleshoot

Looking through the code and it seems the related code block is https://github.com/argoproj/argo-cd/blob/master/util/io/path/resolved.go#L146-L156 where the value file '.' resolved to outside repository root error was thrown.

The path assigned by the above filepath.Abs(path) only ends in a slash only if it represents a root directory, such as "/" on Unix or C:\ on Windows.

When . is provided as the valueFile, the check at https://github.com/argoproj/argo-cd/blob/master/util/io/path/resolved.go#L154 effectively compares if /github/repo-root has /github/repo-root/ as a prefix which apparently is not the case.

Proposed fix

Add an additional condition to allow this case.

Note on DCO:

If the DCO action in the integration test fails, one or more of your commits are not signed off. Please click on the Details link next to the DCO action for instructions on how to resolve this.

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • Optional. My organization is added to USERS.md.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).

@shuai-zh shuai-zh force-pushed the allow-resolving-repo-root-as-jsonnt-lib-path branch 2 times, most recently from 5a65e06 to 71df2e8 Compare October 31, 2022 04:19
shuai-zh and others added 3 commits October 31, 2022 10:56
Signed-off-by: shuai-zh <shuaiz8023@gmail.com>
Signed-off-by: CI <ci@argoproj.com>

Signed-off-by: CI <ci@argoproj.com>
Co-authored-by: CI <ci@argoproj.com>
Signed-off-by: shuai-zh <shuaiz8023@gmail.com>
Signed-off-by: shuai-zh <shuaiz8023@gmail.com>
@shuai-zh shuai-zh force-pushed the allow-resolving-repo-root-as-jsonnt-lib-path branch from 186928c to 203d3e2 Compare October 31, 2022 17:56
@codecov
Copy link

codecov bot commented Oct 31, 2022

Codecov Report

Base: 45.64% // Head: 45.65% // Increases project coverage by +0.01% 🎉

Coverage data is based on head (2d0533f) compared to base (b0dab38).
Patch coverage: 65.51% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11119      +/-   ##
==========================================
+ Coverage   45.64%   45.65%   +0.01%     
==========================================
  Files         239      239              
  Lines       28991    29003      +12     
==========================================
+ Hits        13233    13242       +9     
- Misses      13939    13941       +2     
- Partials     1819     1820       +1     
Impacted Files Coverage Δ
util/io/path/resolved.go 76.56% <56.52%> (-0.37%) ⬇️
reposerver/repository/repository.go 60.88% <100.00%> (ø)
util/helm/helm.go 42.30% <100.00%> (ø)
util/settings/settings.go 51.25% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Collaborator

@crenshaw-dev crenshaw-dev left a comment

Choose a reason for hiding this comment

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

LGTM!

@jessesuen can you take a look as well?

@crenshaw-dev crenshaw-dev added cherry-pick/2.3 Candidate for cherry picking into the 2.3 release branch cherry-pick/2.4 Candidate for cherry picking into the 2.4 release branch cherry-pick/2.5 labels Nov 9, 2022
Copy link
Member

@jessesuen jessesuen left a comment

Choose a reason for hiding this comment

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

LGTM, great refactoring work which addressed our concerns about jsonnet requirements leaking into the helm code path.

@jessesuen jessesuen merged commit 4328bfc into argoproj:master Nov 15, 2022
crenshaw-dev added a commit that referenced this pull request Nov 15, 2022
Signed-off-by: shuai-zh <shuaiz8023@gmail.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
crenshaw-dev added a commit that referenced this pull request Nov 15, 2022
Signed-off-by: shuai-zh <shuaiz8023@gmail.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
crenshaw-dev added a commit that referenced this pull request Nov 15, 2022
Signed-off-by: shuai-zh <shuaiz8023@gmail.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
@crenshaw-dev
Copy link
Collaborator

Cherry-picked onto release-2.5 for 2.5.3, release-2.4 for 2.4.18, and release-2.3 for 2.3.12.

ashutosh16 pushed a commit to ashutosh16/argo-cd that referenced this pull request Nov 23, 2022
Signed-off-by: shuai-zh <shuaiz8023@gmail.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
emirot pushed a commit to emirot/argo-cd that referenced this pull request Jan 27, 2023
Signed-off-by: shuai-zh <shuaiz8023@gmail.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick/2.3 Candidate for cherry picking into the 2.3 release branch cherry-pick/2.4 Candidate for cherry picking into the 2.4 release branch cherry-pick/2.5
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants