diff --git a/x-pack/functionbeat/manager/core/bundle/bundle.go b/x-pack/functionbeat/manager/core/bundle/bundle.go index 5b9ccc70000..2e6a7bd52d0 100644 --- a/x-pack/functionbeat/manager/core/bundle/bundle.go +++ b/x-pack/functionbeat/manager/core/bundle/bundle.go @@ -54,7 +54,7 @@ type Resource interface { } // Folder returns a list of files in a folder. -func Folder(folder string, filemode os.FileMode) []Resource { +func Folder(folder, root string, filemode os.FileMode) []Resource { resources := make([]Resource, 0) err := filepath.Walk(folder, func(path string, info os.FileInfo, err error) error { if err != nil { @@ -65,7 +65,7 @@ func Folder(folder string, filemode os.FileMode) []Resource { return nil } - resources = append(resources, &LocalFile{Path: path, FileMode: filemode}) + resources = append(resources, &RelativeFile{LocalFile{Path: path, FileMode: filemode}, root}) return nil }) @@ -104,6 +104,21 @@ func (l *LocalFile) Mode() os.FileMode { return l.FileMode } +// RelativeFile is a Localfile which needs to be placed relatively in the +// root of the bundle. +type RelativeFile struct { + LocalFile + root string +} + +// Name returns the name of the file. +func (r *RelativeFile) Name() string { + if r.root == "" { + return r.LocalFile.Path + } + return r.LocalFile.Path[len(r.root)+1:] +} + // MemoryFile an in-memory representation of a physical file. type MemoryFile struct { Path string diff --git a/x-pack/functionbeat/manager/gcp/template_builder.go b/x-pack/functionbeat/manager/gcp/template_builder.go index 5471322d98b..8e489766eb0 100644 --- a/x-pack/functionbeat/manager/gcp/template_builder.go +++ b/x-pack/functionbeat/manager/gcp/template_builder.go @@ -186,6 +186,7 @@ func ZipResources() map[string][]bundle.Resource { } func zipResources(typeName string) []bundle.Resource { - vendor := bundle.Folder(filepath.Join("pkg", typeName, "vendor"), 0655) + root := filepath.Join("pkg", typeName) + vendor := bundle.Folder(filepath.Join(root, "vendor"), root, 0655) return append(vendor, &bundle.LocalFile{Path: filepath.Join("pkg", typeName, typeName+".go"), FileMode: 0755}) }