Skip to content

Commit

Permalink
fix stale chart when multiple registries, and stale values in image w…
Browse files Browse the repository at this point in the history
…hen discovering tag
  • Loading branch information
ChristofferNissen committed Nov 22, 2024
1 parent 7866240 commit fa921b4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/helm/chartImportOption.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"log/slog"
"os"
"sort"

"github.com/ChristofferNissen/helmper/pkg/image"
Expand Down Expand Up @@ -264,6 +265,7 @@ func (opt ChartImportOption) Run(ctx context.Context, setters ...Option) error {
return fmt.Errorf("helm: error pushing and modifying chart %s to registry %s :: %w", c.Name, r.URL, err)
}
slog.Debug(res)
defer os.RemoveAll(res)
_ = bar.Add(1)
return nil
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/helm/chartOption.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ type ChartOption struct {
func determineTag(ctx context.Context, img *image.Image, plainHTTP bool) bool {
ctx = context.WithoutCancel(ctx)
ref := img.String()
tag, _ := img.TagOrDigest()
tag, err := img.TagOrDigest()
if err != nil {
return false
}

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

plainHTTP := strings.Contains(i.Registry, "localhost") || strings.Contains(i.Registry, "0.0.0.0")
available := determineTag(egCtx, i, plainHTTP)
i.ResetParsedRef()

// send availability response
channel <- &imageInfo{available, c, i, &helmValuePaths}
Expand Down
5 changes: 5 additions & 0 deletions pkg/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ type Image struct {
parsedRef *string
}

func (i *Image) ResetParsedRef() {
// Remove the assignment to i.parsedRef
i.parsedRef = nil
}

// IsEmpty determines if an image is empty (i.e., registry, repository, and name are empty).
func (i Image) IsEmpty() bool {
return i.Registry == "" && i.Repository == "" && i.Tag == ""
Expand Down

0 comments on commit fa921b4

Please sign in to comment.