Skip to content

Commit

Permalink
[bug] add charts with no images to ChartOption.Run return value (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristofferNissen authored Oct 30, 2024
1 parent 37534af commit c8745f9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ func TestFindImagesInHelmChartsOnKyvernoChart(t *testing.T) {
t.Error(err)
}

expectedChartCount := 1
expectedChartCount := 2
expectedImageCount := 10

// Act
Expand Down
22 changes: 19 additions & 3 deletions pkg/helm/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func (c Chart) addToHelmRepositoryFile(settings *cli.EnvSettings) (bool, error)
}

func (c Chart) CountDependencies(settings *cli.EnvSettings) (int, error) {

HelmDriver := "configmap"
actionConfig := new(action.Configuration)
if err := actionConfig.Init(settings.RESTClientGetter(), settings.Namespace(), HelmDriver, slog.Info); err != nil {
Expand Down Expand Up @@ -304,8 +303,25 @@ func (c Chart) Pull(settings *cli.EnvSettings) (string, error) {
tarPattern := fmt.Sprintf("%s-*%s*.tgz", chartPath, c.Version)

if file.FileExists(chartPath) {
slog.Info("Reusing existing archieve for chart", slog.String("chart", c.Name), slog.String("path", chartPath))
return chartPath, nil
path := filepath.Join(chartPath, chartutil.ChartsDir, c.Name, chartutil.ChartfileName)
if file.FileExists(path) {
// Check chart is the correct version
meta, err := chartutil.LoadChartfile(path)
if err != nil {
return "", err
}

if meta.Version == c.Version {
slog.Info("Reusing existing achieve for chart", slog.String("chart", c.Name), slog.String("path", chartPath))
return chartPath, nil
}

slog.Info("Deleting existing achieve for chart", slog.String("chart", c.Name), slog.String("desired version", c.Version), slog.String("found version", meta.Version), slog.String("path", chartPath))
err = os.RemoveAll(chartPath)
if err != nil {
return "", err
}
}
}

if foundPath, ok := findFile(tarPattern); ok {
Expand Down
5 changes: 2 additions & 3 deletions pkg/helm/chartImportOption.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,16 @@ func (io *IdentifyImportOption) Run(_ context.Context) (RegistryChartStatus, Reg
row := table.Row{sc.Value("index_import_charts"), fmt.Sprintf("charts/%s", c.Name), c.Version}

for _, r := range io.Registries {
existsInRegistry := registry.Exists(context.TODO(), n, v, []*registry.Registry{r})[r.URL]

elem := m1[r]
if elem == nil {
// init map
elem = make(map[*Chart]bool, 0)
m1[r] = elem
}

existsInRegistry := registry.Exists(context.TODO(), n, v, []*registry.Registry{r})[r.URL]
b := io.All || !existsInRegistry
elem[&c] = b

if b {
sc.Inc(r.URL + "charts")
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/helm/chartOption.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,5 +488,12 @@ func (co *ChartOption) Run(ctx context.Context, setters ...Option) (ChartData, e
cd[placeHolder] = m
}

// Make sure we parse Charts with no images as well
for _, c := range co.ChartCollection.Charts {
if cd[*c] == nil {
cd[*c] = make(map[*image.Image][]string)
}
}

return cd, nil
}

0 comments on commit c8745f9

Please sign in to comment.