Fix GitRepository include for nested paths
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
parent
fd636d6c39
commit
add5444f16
|
@ -756,6 +756,12 @@ var _ = Describe("GitRepositoryReconciler", func() {
|
|||
createFiles: []string{"dir1", "dir2"},
|
||||
checkFiles: []string{"sub/dir1", "sub/dir2"},
|
||||
}),
|
||||
Entry("to nested path", includeTestCase{
|
||||
fromPath: "",
|
||||
toPath: "sub/nested",
|
||||
createFiles: []string{"dir1", "dir2"},
|
||||
checkFiles: []string{"sub/nested/dir1", "sub/nested/dir2"},
|
||||
}),
|
||||
Entry("from and to path", includeTestCase{
|
||||
fromPath: "nested",
|
||||
toPath: "sub",
|
||||
|
|
|
@ -354,27 +354,35 @@ func (s *Storage) CopyFromPath(artifact *sourcev1.Artifact, path string) (err er
|
|||
return s.Copy(artifact, f)
|
||||
}
|
||||
|
||||
// CopyToPath copies the contents of the given atrifact to the path.
|
||||
func (s *Storage) CopyToPath(atrifact *sourcev1.Artifact, subPath, toPath string) error {
|
||||
// CopyToPath copies the contents of the given artifact to the path.
|
||||
func (s *Storage) CopyToPath(artifact *sourcev1.Artifact, subPath, toPath string) error {
|
||||
// create a tmp directory to store artifact
|
||||
tmp, err := ioutil.TempDir("", "flux-include")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.RemoveAll(tmp)
|
||||
|
||||
// read artifact file content
|
||||
localPath := s.LocalPath(*atrifact)
|
||||
localPath := s.LocalPath(*artifact)
|
||||
f, err := os.Open(localPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// untar the artifact
|
||||
untarPath := filepath.Join(tmp, "tar")
|
||||
if _, err = untar.Untar(f, untarPath); err != nil {
|
||||
return err
|
||||
}
|
||||
// copy the folder to the path
|
||||
|
||||
// create the destination parent dir
|
||||
if err = os.MkdirAll(filepath.Dir(toPath), os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// copy the artifact content to the destination dir
|
||||
fromPath := filepath.Join(untarPath, subPath)
|
||||
if err := fs.RenameWithFallback(fromPath, toPath); err != nil {
|
||||
return err
|
||||
|
|
|
@ -62,6 +62,9 @@ type GitRepositorySpec struct {
|
|||
// This option is available only when using the 'go-git' GitImplementation.
|
||||
// +optional
|
||||
RecurseSubmodules bool `json:"recurseSubmodules,omitempty"`
|
||||
|
||||
// Extra git repositories to map into the repository
|
||||
Include []GitRepositoryInclude `json:"include,omitempty"`
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -529,8 +532,8 @@ spec:
|
|||
include:
|
||||
- repository:
|
||||
name: app-repo
|
||||
from: deploy/kubernetes
|
||||
to: base/app
|
||||
fromPath: deploy/kubernetes
|
||||
toPath: base/app
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
|
@ -543,9 +546,9 @@ data:
|
|||
password: <GitHub Token>
|
||||
```
|
||||
|
||||
The `from` and `to` parameters allows you to limit the files included and where they will be
|
||||
copied to in the main repository. If you do not specify a value for `from` all files in the
|
||||
repository will be included. The `to` value will default to the name of the repository.
|
||||
The `fromPath` and `toPath` parameters allows you to limit the files included and where they will be
|
||||
copied to in the main repository. If you do not specify a value for `fromPath` all files in the
|
||||
repository will be included. The `toPath` value will default to the name of the repository.
|
||||
|
||||
## Status examples
|
||||
|
||||
|
|
Loading…
Reference in New Issue