check for new current tag
parent
16e2decc6d
commit
1548203462
|
@ -3,10 +3,13 @@ package version
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Masterminds/semver"
|
"github.com/Masterminds/semver"
|
||||||
"github.com/rusenask/keel/types"
|
"github.com/rusenask/keel/types"
|
||||||
|
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrVersionTagMissing - tag missing error
|
// ErrVersionTagMissing - tag missing error
|
||||||
|
@ -60,6 +63,47 @@ func GetImageNameAndVersion(name string) (string, *types.Version, error) {
|
||||||
return "", nil, ErrVersionTagMissing
|
return "", nil, ErrVersionTagMissing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewAvailable - takes version and current tags. Checks whether there is a new version in the list of tags
|
||||||
|
// and returns it as well as newAvailable bool
|
||||||
|
func NewAvailable(current string, tags []string) (newVersion string, newAvailable bool, err error) {
|
||||||
|
|
||||||
|
currentVersion, err := semver.NewVersion(current)
|
||||||
|
if err != nil {
|
||||||
|
return "", false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(tags) == 0 {
|
||||||
|
return "", false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var vs []*semver.Version
|
||||||
|
for _, r := range tags {
|
||||||
|
v, err := semver.NewVersion(r)
|
||||||
|
if err != nil {
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"error": err,
|
||||||
|
"tag": r,
|
||||||
|
}).Error("failed to parse tag")
|
||||||
|
continue
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
vs = append(vs, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(vs) == 0 {
|
||||||
|
log.Error("no versions available")
|
||||||
|
return "", false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Sort(sort.Reverse(semver.Collection(vs)))
|
||||||
|
|
||||||
|
if currentVersion.LessThan(vs[0]) {
|
||||||
|
return vs[0].String(), true, nil
|
||||||
|
}
|
||||||
|
return "", false, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ShouldUpdate - checks whether update is needed
|
// ShouldUpdate - checks whether update is needed
|
||||||
func ShouldUpdate(current *types.Version, new *types.Version, policy types.PolicyType) (bool, error) {
|
func ShouldUpdate(current *types.Version, new *types.Version, policy types.PolicyType) (bool, error) {
|
||||||
if policy == types.PolicyTypeForce {
|
if policy == types.PolicyTypeForce {
|
||||||
|
|
Loading…
Reference in New Issue