Skip to content

Commit

Permalink
fix: Chart Path Fallback
Browse files Browse the repository at this point in the history
Trying first the local file-system, then fallback to the embedded
resources, just like the rest of `rhtap-cli` behavior.`
  • Loading branch information
otaviof committed Jan 7, 2025
1 parent e0ab03c commit f097abd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
18 changes: 13 additions & 5 deletions pkg/chartfs/chartfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,24 @@ func (c *ChartFS) ReadFile(name string) ([]byte, error) {
return nil, err
}

// GetChartForDep returns the Helm chart for the given dependency. It uses
// BufferredFiles to walk through the filesytem and collect the chart files.
func (c *ChartFS) GetChartForDep(chartPath string) (*chart.Chart, error) {
bf := NewBufferedFiles(c.embeddedFS, chartPath)
if err := fs.WalkDir(c.embeddedFS, chartPath, bf.Walk); err != nil {
// walkChartDir walks through the chart directory, and loads the chart files.
func (c *ChartFS) walkChartDir(fsys fs.FS, chartPath string) (*chart.Chart, error) {
bf := NewBufferedFiles(fsys, chartPath)
if err := fs.WalkDir(fsys, chartPath, bf.Walk); err != nil {
return nil, err
}
return loader.LoadFiles(bf.Files())
}

// GetChartFiles returns the informed Helm chart path instantiated files.
func (c *ChartFS) GetChartFiles(chartPath string) (*chart.Chart, error) {
chartFiles, err := c.walkChartDir(c.localFS, chartPath)
if err == nil {
return chartFiles, nil
}
return c.walkChartDir(c.embeddedFS, chartPath)
}

// NewChartFS instantiates a ChartFS instance using the embedded tarball,
// and the local base directory.
func NewChartFS(baseDir string) (*ChartFS, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/chartfs/chartfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestNewChartFS(t *testing.T) {
})

t.Run("GetChartForDep", func(t *testing.T) {
chart, err := c.GetChartForDep("charts/rhtap-openshift")
chart, err := c.GetChartFiles("charts/rhtap-openshift")
g.Expect(err).To(o.Succeed())
g.Expect(chart).ToNot(o.BeNil())
g.Expect(chart.Name()).To(o.Equal("rhtap-openshift"))
Expand Down
6 changes: 3 additions & 3 deletions pkg/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ type Installer struct {
// prepareHelmClient prepares the Helm client for the given dependency, which also
// specifies the default namespace for the Helm Chart.
func (i *Installer) prepareHelmClient() (*deployer.Helm, error) {
i.logger.Debug("Loading dependency Helm chart (from CFS)")
chart, err := i.cfs.GetChartForDep(i.dep.Chart)
i.logger.Debug("Loading dependency Helm chart...")
cf, err := i.cfs.GetChartFiles(i.dep.Chart)
if err != nil {
return nil, err
}

i.logger.Debug("Loading Helm client for dependency and namespace")
return deployer.NewHelm(i.logger, i.flags, i.kube, i.dep.Namespace, chart)
return deployer.NewHelm(i.logger, i.flags, i.kube, i.dep.Namespace, cf)
}

// SetValues prepares the values template for the Helm chart installation.
Expand Down

0 comments on commit f097abd

Please sign in to comment.