vendir icon indicating copy to clipboard operation
vendir copied to clipboard

Feature request: support file relocation/rename

Open jorgemoralespou opened this issue 5 years ago • 6 comments

I would like vendir to strip/rename paths

- path: vendor/k8s
  contents:
  - path: eduk8s
    git:
      url: https://github.com/eduk8s/eduk8s
      ref: 20.08.04.1
    includePaths:
    - resources/crds-v1/**/*
    - resources/operator/**/*

and this ends up creating:

vendor/k8s/eduk8s/resources/crds-v1
vendor/k8s/eduk8s/resources/operator

but I would want:

vendor/k8s/eduk8s/resources/ 

everything just in this dir.

The use case is:

I’m collecting the k8s resource definitions from multiple sources to then process them with ytt and apply them with kapp, and have a consistent directory structure. When I get stuff from github releases I just get the files I need in the root of the path, when I get it this other way it ends in subdirectories, and hence dir layout is not really consistent

jorgemoralespou avatar Aug 11 '20 18:08 jorgemoralespou

one of the reasons why its is like that at this moment is because its not clear what should happen when there are conflicts between file names, directory name vs file name, etc. any suggestions?

cppforlife avatar Aug 12 '20 14:08 cppforlife

It would maybe make sense to add a relocation/fail strategy. An example would be:

- path: vendor/k8s
  contents:
  - path: eduk8s
    git:
      url: https://github.com/eduk8s/eduk8s
      ref: 20.08.04.1
    includePaths:
    - resources/crds-v1/**/*
    - resources/crds-v1alpha1/**/*
    - resources/operator/**/*
    relocatePath:  # Apply this relocation rules in order, fail if one don't succeed
    - resources/crds-v1/**/*=/**/*                          # To strip path
    - resources/crds-v1alpha1/=/                            # To strip path (as it ends with / is a dir. Fail if a file)
    - resources/operator/**/*=resources/**/*       # To relocate everything under resources folder (rename folder)
    - resources/operator/example.yaml=resources/my-example.yaml   # rename file

jorgemoralespou avatar Aug 17 '20 16:08 jorgemoralespou

We can definitely see how this need is really valid!

For further discussion, what aspects of directory shaping fit within vendir's responsibilities? How much of that is intrinsic to vendoring in software?

StevenLocke avatar Sep 02 '20 00:09 StevenLocke

https://github.com/k14s/vendir/releases/tag/v0.11.0 includes newRootPath configuration that changes "root" directory for the source.

cppforlife avatar Oct 16 '20 23:10 cppforlife

Example (and discussion) demonstrating why this could be helpful: https://kubernetes.slack.com/archives/CH8KCCKA5/p1625843954329600?thread_ts=1625811418.324700&cid=CH8KCCKA5

jorgemoralespou avatar Jul 09 '21 15:07 jorgemoralespou

I was looking into this issue and I was a little bit confused by the names. My suggestion of a possible UX is:

renamePath:
  - origin: resources/crds-v1/ # all files under resources/crds-v1/ will be flattened, removing all the folder structure
    flatten: true
  - origin: resources/crds-v1alpha1/ # Move all files and folders from resources/crds-v1alpha1 to the "root" directory
    destination: /   
  - origin: resources/operator
    destination: resources       # To relocate everything under resources folder (rename folder)
  - origin: resources/operator/example.yaml
    destination: resources/my-example.yaml   # rename file

I feel like giving a little bit more structure to the configuration, at least to me, helped better understand what each option was. What do yll think?

joaopapereira avatar Sep 01 '22 15:09 joaopapereira