github.com/argoproj/argo-cd@v1.8.7/util/helm/index.go (about)

     1  package helm
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"github.com/Masterminds/semver"
     8  )
     9  
    10  type Entry struct {
    11  	Version string
    12  	Created time.Time
    13  }
    14  
    15  type Index struct {
    16  	Entries map[string]Entries
    17  }
    18  
    19  func (i *Index) GetEntries(chart string) (Entries, error) {
    20  	entries, ok := i.Entries[chart]
    21  	if !ok {
    22  		return nil, fmt.Errorf("chart '%s' not found in index", chart)
    23  	}
    24  	return entries, nil
    25  }
    26  
    27  type Entries []Entry
    28  
    29  func (e Entries) MaxVersion(constraints *semver.Constraints) (*semver.Version, error) {
    30  	versions := semver.Collection{}
    31  	for _, entry := range e {
    32  		v, err := semver.NewVersion(entry.Version)
    33  		if err != nil {
    34  			return nil, fmt.Errorf("invalid constraint in index: %v", err)
    35  		}
    36  		if constraints.Check(v) {
    37  			versions = append(versions, v)
    38  		}
    39  	}
    40  	if len(versions) == 0 {
    41  		return nil, fmt.Errorf("constraint not found in index")
    42  	}
    43  	maxVersion := versions[0]
    44  	for _, v := range versions {
    45  		if v.GreaterThan(maxVersion) {
    46  			maxVersion = v
    47  		}
    48  	}
    49  	return maxVersion, nil
    50  }