@@ -185,6 +185,11 @@ func (h *HelmClient) AddRepo(repo *repo.Entry) error {
185
185
}
186
186
187
187
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
+
188
193
for _ , repository := range h .repos {
189
194
if repository .Name != reponame {
190
195
continue
@@ -207,14 +212,24 @@ func (h *HelmClient) Latest(reponame, chart string) (string, error) {
207
212
versions , ok := repoidx .Entries [chart ]
208
213
if ! ok {
209
214
return "" , fmt .Errorf ("chart %s not found" , chart )
210
- } else if len (versions ) == 0 {
211
- return "" , fmt .Errorf ("chart %s has no versions" , chart )
212
215
}
213
216
214
217
if len (versions ) == 0 {
215
218
return "" , fmt .Errorf ("chart %s has no versions" , chart )
216
219
}
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 )
218
233
}
219
234
return "" , fmt .Errorf ("repository %s not found" , reponame )
220
235
}
0 commit comments