diff --git a/controllers/gitrepository_controller_test.go b/controllers/gitrepository_controller_test.go index 4de5e2676..5be6c2ffd 100644 --- a/controllers/gitrepository_controller_test.go +++ b/controllers/gitrepository_controller_test.go @@ -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", diff --git a/controllers/storage.go b/controllers/storage.go index ce3b959da..09b3b760a 100644 --- a/controllers/storage.go +++ b/controllers/storage.go @@ -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 diff --git a/docs/spec/v1beta1/gitrepositories.md b/docs/spec/v1beta1/gitrepositories.md index d06f9b3de..c302c07a0 100644 --- a/docs/spec/v1beta1/gitrepositories.md +++ b/docs/spec/v1beta1/gitrepositories.md @@ -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: ``` -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