-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use semver on the upgrade process (#1034)
* Use semver on the upgrade process Signed-off-by: Ruben Vargas <[email protected]> * More tests Signed-off-by: Ruben Vargas <[email protected]> * Simplify upgrade ManagedInstance function, address comments Signed-off-by: Ruben Vargas <[email protected]> * Address some small changes Signed-off-by: Ruben Vargas <[email protected]> * Create function that parse semver and sort it Signed-off-by: Ruben Vargas <[email protected]> * Validate to upper versions and update tests Signed-off-by: Ruben Vargas <[email protected]> * Improve logging messages Signed-off-by: Ruben Vargas <[email protected]> * Change version to initialized on version package init Signed-off-by: Ruben Vargas <[email protected]> * Panic on semver parsing failure, more log messages improvments Signed-off-by: Ruben Vargas <[email protected]> * Move some stuff to versions main.go, added tests Signed-off-by: Ruben Vargas <[email protected]> * Change one log field name Signed-off-by: Ruben Vargas <[email protected]> * More movements, little improvments Signed-off-by: Ruben Vargas <[email protected]>
- Loading branch information
1 parent
d51756e
commit db31a0c
Showing
22 changed files
with
247 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package upgrade | ||
|
||
import ( | ||
"sort" | ||
|
||
"github.com/Masterminds/semver" | ||
) | ||
|
||
var ( | ||
semanticVersions []*semver.Version | ||
startUpdatesVersion *semver.Version | ||
) | ||
|
||
func init() { | ||
parseSemVer() | ||
} | ||
|
||
func parseSemVer() { | ||
semvers, err := versions(upgrades) | ||
if err != nil { | ||
panic(err) | ||
} | ||
semanticVersions = semvers | ||
startUpdatesVersion = semver.MustParse("1.11.0") | ||
} | ||
|
||
// Versions return the list of semantic version sorted | ||
func versions(versions map[string]upgradeFunction) ([]*semver.Version, error) { | ||
versionLists := make([]*semver.Version, len(versions)) | ||
versionIndex := 0 | ||
for v := range versions { | ||
semv, err := semver.NewVersion(v) | ||
if err != nil { | ||
return nil, err | ||
} | ||
versionLists[versionIndex] = semv | ||
versionIndex++ | ||
} | ||
|
||
// apply the updates in order | ||
sort.Sort(semver.Collection(versionLists)) | ||
return versionLists, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package upgrade | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/Masterminds/semver" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1" | ||
) | ||
|
||
func noop(ctx context.Context, client client.Client, jaeger v1.Jaeger) (v1.Jaeger, error) { | ||
return jaeger, nil | ||
} | ||
|
||
func TestVersions(t *testing.T) { | ||
maptoTest := map[string]upgradeFunction{ | ||
"1.17.0": noop, | ||
"1.15.4": noop, | ||
"1.15.0": noop, | ||
"1.16.1": noop, | ||
"1.12.2": noop, | ||
} | ||
sortedSemVersions := []*semver.Version{ | ||
semver.MustParse("1.12.2"), | ||
semver.MustParse("1.15.0"), | ||
semver.MustParse("1.15.4"), | ||
semver.MustParse("1.16.1"), | ||
semver.MustParse("1.17.0"), | ||
} | ||
|
||
semVersions, err := versions(maptoTest) | ||
assert.NoError(t, err) | ||
assert.Equal(t, semVersions, sortedSemVersions) | ||
} | ||
|
||
func TestVersionsError(t *testing.T) { | ||
maptoTest := map[string]upgradeFunction{ | ||
"1.17.0": noop, | ||
"1.15.4": noop, | ||
"1.15.0": noop, | ||
"1,16.1": noop, // Bad format, coma instead of point | ||
"1.12.2": noop, | ||
} | ||
|
||
_, err := versions(maptoTest) | ||
assert.Error(t, err) | ||
} |
Oops, something went wrong.