Skip to content

Commit

Permalink
fix: support providing local '.' path to bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
mhrabovcin committed Apr 2, 2023
1 parent 8a19419 commit ae36e04
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewServeCommand(out output.Output) *cobra.Command {

cmd := &cobra.Command{
Use: "serve SUPPORT_BUNDLE_PATH",
Short: "Starts a local envtest based k8s server",
Short: "Starts a local envtest based Kubernetes API server with bundle resources",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runServe(args[0], options, out)
Expand Down
15 changes: 11 additions & 4 deletions pkg/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,25 @@ func (bundle) Layout() Layout {
}

// New creates bundle representation from given path. It supports reading extracted
// bundle from directory or `tar.gz` archive, which is automatically extracted
// bundle from a directory or a `tar.gz` archive, which is automatically extracted
// to a temporary folder.
func New(path string) (Bundle, error) {
var fs afero.Fs

switch {
case strings.HasSuffix(path, ".tar.gz"):
baseDir := filepath.Join(os.TempDir(), "troubleshoot-live")
fi, err := os.Stat(path)
if err != nil {
return nil, err
}

baseDir := filepath.Join(os.TempDir(), "troubleshoot-live")
tmpDir := filepath.Join(baseDir, fmt.Sprintf("%s_%d", filepath.Base(path), fi.Size()))
ok, err := afero.DirExists(afero.NewOsFs(), tmpDir)
if err != nil {
return nil, err
}

// Directory for extracting bundle doesn't exist yet
if !ok {
if err := os.MkdirAll(tmpDir, 0o755); err != nil {
Expand Down Expand Up @@ -79,7 +81,12 @@ func New(path string) (Bundle, error) {

fs = fromDir(filepath.Join(tmpDir, entries[0].Name()))
default:
isDir, err := afero.IsDir(afero.NewOsFs(), path)
absPath, err := filepath.Abs(path)
if err != nil {
return nil, err
}

isDir, err := afero.IsDir(afero.NewOsFs(), absPath)
if err != nil {
return nil, err
}
Expand All @@ -88,7 +95,7 @@ func New(path string) (Bundle, error) {
break
}

fs = fromDir(path)
fs = fromDir(absPath)
}

if fs == nil {
Expand Down

0 comments on commit ae36e04

Please sign in to comment.