Skip to content

Commit c3a29ab

Browse files
[bug] fix stale chart when multiple registries, and stale values in image when discovering tag (#142)
1 parent 7866240 commit c3a29ab

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

pkg/helm/chartImportOption.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"log"
77
"log/slog"
8+
"os"
89
"sort"
910

1011
"github.com/ChristofferNissen/helmper/pkg/image"
@@ -264,6 +265,7 @@ func (opt ChartImportOption) Run(ctx context.Context, setters ...Option) error {
264265
return fmt.Errorf("helm: error pushing and modifying chart %s to registry %s :: %w", c.Name, r.URL, err)
265266
}
266267
slog.Debug(res)
268+
defer os.RemoveAll(res)
267269
_ = bar.Add(1)
268270
return nil
269271
}

pkg/helm/chartOption.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ type ChartOption struct {
4242
func determineTag(ctx context.Context, img *image.Image, plainHTTP bool) bool {
4343
ctx = context.WithoutCancel(ctx)
4444
ref := img.String()
45-
tag, _ := img.TagOrDigest()
45+
tag, err := img.TagOrDigest()
46+
if err != nil {
47+
return false
48+
}
4649

4750
available, _ := registry.Exist(ctx, ref, tag, plainHTTP)
4851
if available {
@@ -394,6 +397,7 @@ func (co *ChartOption) Run(ctx context.Context, setters ...Option) (ChartData, e
394397

395398
plainHTTP := strings.Contains(i.Registry, "localhost") || strings.Contains(i.Registry, "0.0.0.0")
396399
available := determineTag(egCtx, i, plainHTTP)
400+
i.ResetParsedRef()
397401

398402
// send availability response
399403
channel <- &imageInfo{available, c, i, &helmValuePaths}

pkg/image/image.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ type Image struct {
6363
parsedRef *string
6464
}
6565

66+
func (i *Image) ResetParsedRef() {
67+
// Remove the assignment to i.parsedRef
68+
i.parsedRef = nil
69+
}
70+
6671
// IsEmpty determines if an image is empty (i.e., registry, repository, and name are empty).
6772
func (i Image) IsEmpty() bool {
6873
return i.Registry == "" && i.Repository == "" && i.Tag == ""

0 commit comments

Comments
 (0)