Skip to content

Commit 5be117d

Browse files
authored
fix(openebs): ignore pre-release chart versions (#2322)
1 parent e995d82 commit 5be117d

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

pkg/helm/client.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ func (h *HelmClient) AddRepo(repo *repo.Entry) error {
185185
}
186186

187187
func (h *HelmClient) Latest(reponame, chart string) (string, error) {
188+
stableConstraint, err := semver.NewConstraint(">0.0.0") // search only for stable versions
189+
if err != nil {
190+
return "", fmt.Errorf("create stable constraint: %w", err)
191+
}
192+
188193
for _, repository := range h.repos {
189194
if repository.Name != reponame {
190195
continue
@@ -207,14 +212,24 @@ func (h *HelmClient) Latest(reponame, chart string) (string, error) {
207212
versions, ok := repoidx.Entries[chart]
208213
if !ok {
209214
return "", fmt.Errorf("chart %s not found", chart)
210-
} else if len(versions) == 0 {
211-
return "", fmt.Errorf("chart %s has no versions", chart)
212215
}
213216

214217
if len(versions) == 0 {
215218
return "", fmt.Errorf("chart %s has no versions", chart)
216219
}
217-
return versions[0].Version, nil
220+
221+
for _, version := range versions {
222+
v, err := semver.NewVersion(version.Version)
223+
if err != nil {
224+
continue
225+
}
226+
227+
if stableConstraint.Check(v) {
228+
return version.Version, nil
229+
}
230+
}
231+
232+
return "", fmt.Errorf("no stable version found for chart %s", chart)
218233
}
219234
return "", fmt.Errorf("repository %s not found", reponame)
220235
}

0 commit comments

Comments
 (0)