{internal/version,versioncontrol}: fix old versions (#3359)

* fix old semver

* go jenkins!
This commit is contained in:
Bryan White 2019-10-24 22:24:28 +02:00 committed by littleskunk
parent 696c567e89
commit 0b678c23c7
2 changed files with 35 additions and 12 deletions

View File

@ -51,20 +51,28 @@ type Info struct {
Release bool `json:"release,omitempty"`
}
// SemVer represents a semantic version
// SemVer represents a semantic version.
// TODO: replace with semver.Version
type SemVer struct {
semver.Version
}
// AllowedVersions provides the Minimum SemVer per Service
// OldSemVer represents a semantic version.
// NB: this will be deprecated in favor of `SemVer`; these structs marshal to JSON differently.
type OldSemVer struct {
Major int64 `json:"major"`
Minor int64 `json:"minor"`
Patch int64 `json:"patch"`
}
// AllowedVersions provides the Minimum SemVer per Service.
// TODO: I don't think this name is representative of what this struct now holds.
type AllowedVersions struct {
Satellite SemVer
Storagenode SemVer
Uplink SemVer
Gateway SemVer
Identity SemVer
Satellite OldSemVer
Storagenode OldSemVer
Uplink OldSemVer
Gateway OldSemVer
Identity OldSemVer
Processes Processes `json:"processes"`
}
@ -136,6 +144,21 @@ func NewSemVer(v string) (SemVer, error) {
}, nil
}
// NewOldSemVer parses a given version and returns an instance of OldSemVer or
// an error if unable to parse the version.
func NewOldSemVer(v string) (OldSemVer, error) {
ver, err := NewSemVer(v)
if err != nil {
return OldSemVer{}, err
}
return OldSemVer{
Major: int64(ver.Major),
Minor: int64(ver.Minor),
Patch: int64(ver.Patch),
}, nil
}
// Compare compare two versions, return -1 if compared version is greater, 0 if equal and 1 if less.
func (sem *SemVer) Compare(version SemVer) int {
return sem.Version.Compare(version.Version)

View File

@ -125,27 +125,27 @@ func New(log *zap.Logger, config *Config) (peer *Peer, err error) {
}
// Convert each Service's VersionConfig String to SemVer
peer.Versions.Satellite, err = version.NewSemVer(config.Versions.Satellite)
peer.Versions.Satellite, err = version.NewOldSemVer(config.Versions.Satellite)
if err != nil {
return &Peer{}, err
}
peer.Versions.Storagenode, err = version.NewSemVer(config.Versions.Storagenode)
peer.Versions.Storagenode, err = version.NewOldSemVer(config.Versions.Storagenode)
if err != nil {
return &Peer{}, err
}
peer.Versions.Uplink, err = version.NewSemVer(config.Versions.Uplink)
peer.Versions.Uplink, err = version.NewOldSemVer(config.Versions.Uplink)
if err != nil {
return &Peer{}, err
}
peer.Versions.Gateway, err = version.NewSemVer(config.Versions.Gateway)
peer.Versions.Gateway, err = version.NewOldSemVer(config.Versions.Gateway)
if err != nil {
return &Peer{}, err
}
peer.Versions.Identity, err = version.NewSemVer(config.Versions.Identity)
peer.Versions.Identity, err = version.NewOldSemVer(config.Versions.Identity)
if err != nil {
return &Peer{}, err
}