Skip to content

Commit 48efbd1

Browse files
authored
Merge pull request #367 from fluxcd/fix-include
Fix GitRepository include for nested paths
2 parents fd636d6 + add5444 commit 48efbd1

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

controllers/gitrepository_controller_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,12 @@ var _ = Describe("GitRepositoryReconciler", func() {
756756
createFiles: []string{"dir1", "dir2"},
757757
checkFiles: []string{"sub/dir1", "sub/dir2"},
758758
}),
759+
Entry("to nested path", includeTestCase{
760+
fromPath: "",
761+
toPath: "sub/nested",
762+
createFiles: []string{"dir1", "dir2"},
763+
checkFiles: []string{"sub/nested/dir1", "sub/nested/dir2"},
764+
}),
759765
Entry("from and to path", includeTestCase{
760766
fromPath: "nested",
761767
toPath: "sub",

controllers/storage.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,27 +354,35 @@ func (s *Storage) CopyFromPath(artifact *sourcev1.Artifact, path string) (err er
354354
return s.Copy(artifact, f)
355355
}
356356

357-
// CopyToPath copies the contents of the given atrifact to the path.
358-
func (s *Storage) CopyToPath(atrifact *sourcev1.Artifact, subPath, toPath string) error {
357+
// CopyToPath copies the contents of the given artifact to the path.
358+
func (s *Storage) CopyToPath(artifact *sourcev1.Artifact, subPath, toPath string) error {
359359
// create a tmp directory to store artifact
360360
tmp, err := ioutil.TempDir("", "flux-include")
361361
if err != nil {
362362
return err
363363
}
364364
defer os.RemoveAll(tmp)
365+
365366
// read artifact file content
366-
localPath := s.LocalPath(*atrifact)
367+
localPath := s.LocalPath(*artifact)
367368
f, err := os.Open(localPath)
368369
if err != nil {
369370
return err
370371
}
371372
defer f.Close()
373+
372374
// untar the artifact
373375
untarPath := filepath.Join(tmp, "tar")
374376
if _, err = untar.Untar(f, untarPath); err != nil {
375377
return err
376378
}
377-
// copy the folder to the path
379+
380+
// create the destination parent dir
381+
if err = os.MkdirAll(filepath.Dir(toPath), os.ModePerm); err != nil {
382+
return err
383+
}
384+
385+
// copy the artifact content to the destination dir
378386
fromPath := filepath.Join(untarPath, subPath)
379387
if err := fs.RenameWithFallback(fromPath, toPath); err != nil {
380388
return err

docs/spec/v1beta1/gitrepositories.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ type GitRepositorySpec struct {
6262
// This option is available only when using the 'go-git' GitImplementation.
6363
// +optional
6464
RecurseSubmodules bool `json:"recurseSubmodules,omitempty"`
65+
66+
// Extra git repositories to map into the repository
67+
Include []GitRepositoryInclude `json:"include,omitempty"`
6568
}
6669
```
6770

@@ -529,8 +532,8 @@ spec:
529532
include:
530533
- repository:
531534
name: app-repo
532-
from: deploy/kubernetes
533-
to: base/app
535+
fromPath: deploy/kubernetes
536+
toPath: base/app
534537
---
535538
apiVersion: v1
536539
kind: Secret
@@ -543,9 +546,9 @@ data:
543546
password: <GitHub Token>
544547
```
545548

546-
The `from` and `to` parameters allows you to limit the files included and where they will be
547-
copied to in the main repository. If you do not specify a value for `from` all files in the
548-
repository will be included. The `to` value will default to the name of the repository.
549+
The `fromPath` and `toPath` parameters allows you to limit the files included and where they will be
550+
copied to in the main repository. If you do not specify a value for `fromPath` all files in the
551+
repository will be included. The `toPath` value will default to the name of the repository.
549552

550553
## Status examples
551554

0 commit comments

Comments
 (0)