carvel-dev / vendir

Easy way to vendor portions of git repos, github releases, helm charts, docker image contents, etc. declaratively
https://carvel.dev/vendir
Apache License 2.0
281 stars 50 forks source link

fix: check overlapping paths separately for directories and contents #343

Closed Zebradil closed 7 months ago

Zebradil commented 9 months ago

This PR fixes the logic of the overlapping paths check. In the original versions, paths of directories were joined with paths of their contents before the check. This allowed the following configuration to be accepted:

apiVersion: vendir.k14s.io/v1alpha1
kind: Config
directories:
  - path: charts
    contents:
      - path: foo
        inline:
          paths:
            foo.txt: file-content
  - path: charts
    contents:
      - path: bar
        inline:
          paths:
            bar.txt: file-content

The result of vendir sync would be:

❯ vendir sync
Fetching: charts + foo (inline)

Fetching: charts + bar (inline)

Lock config

apiVersion: vendir.k14s.io/v1alpha1
directories:
- contents:
  - inline: {}
    path: foo
  path: charts
- contents:
  - inline: {}
    path: bar
  path: charts
kind: LockConfig

Succeeded

❯ exa -T
.
├── charts
│  └── bar
│     └── bar.txt
├── vendir.lock.yml
└── vendir.yml

One of the contents is overwritten by the other.

With this PR, having the same paths for two directories will result in an error.

kumaritanushree commented 9 months ago

@Zebradil I think you are trying to do the same thing what @fritzduchardt has done in this PR https://github.com/carvel-dev/vendir/pull/325

I have added a solution as well there if that fulfil your requirements. Else we will have more discussion on this in next community meeting to have a final decision wether we want this change or not. Thanks

Zebradil commented 9 months ago

Hi @kumaritanushree, thank you for looking into this.

I saw #325 before creating this PR, but my proposal differs. The PR from @fritzduchardt proposes to allow the same paths to be managed by different directory entities in the vendir configuration. My PR proposes to disallow duplicated paths.

I've been using vendir for more than three years and I always was sure that one path could be managed only by one directory. I can be wrong about that. Maybe @cppforlife can share the initial idea behind this.

joaopapereira commented 8 months ago

Let us talk about this in tomorrow's community meeting @fritzduchardt @Zebradil if yll can attend

Zebradil commented 8 months ago

@joaopapereira as we agreed in the community meeting, I went ahead and:

I'm unsure about the last point, but I don't see much value in having an example of incorrect configuration (I bet, code copilots learn from it 😄).

kumaritanushree commented 7 months ago

Changes looks good to me. Tested, error message also looks good.