-
Notifications
You must be signed in to change notification settings - Fork 230
USHIFT-1087 Simple list of blocked upgrades #1949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-robot
merged 1 commit into
openshift:main
from
pmtk:1087-list-of-blocked-upgrades
Jun 23, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,59 @@ | ||
| package prerun | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "io/fs" | ||
|
|
||
| embedded "github.com/openshift/microshift/assets" | ||
| "k8s.io/klog/v2" | ||
| ) | ||
|
|
||
| func IsUpgradeBlocked(execVersion versionMetadata, dataVersion versionMetadata) (bool, error) { | ||
| buf, err := getBlockedUpgradesAsset() | ||
| if err != nil { | ||
| if errors.Is(err, fs.ErrNotExist) { | ||
| return false, nil | ||
| } | ||
| return false, fmt.Errorf("failed to load embedded blocked upgrades asset: %w", err) | ||
| } | ||
|
|
||
| m, err := unmarshalBlockedUpgrades(buf) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
|
|
||
| return isBlocked(m, execVersion.String(), dataVersion.String()), nil | ||
| } | ||
|
|
||
| func getBlockedUpgradesAsset() ([]byte, error) { | ||
| return embedded.Asset("release/upgrade-blocks.json") | ||
| } | ||
|
|
||
| func unmarshalBlockedUpgrades(data []byte) (map[string][]string, error) { | ||
| var blockedEdges map[string][]string | ||
| err := json.Unmarshal(data, &blockedEdges) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to unmarshal %q: %w", string(data), err) | ||
| } | ||
| return blockedEdges, nil | ||
| } | ||
|
|
||
| func isBlocked(blockedUpgrades map[string][]string, execVersion, dataVersion string) bool { | ||
| klog.InfoS("Checking if upgrade is allowed", "existing-data-version", dataVersion, "new-binary-version", execVersion, "blocked-upgrades", blockedUpgrades) | ||
|
|
||
| for targetVersion, fromVersions := range blockedUpgrades { | ||
| if targetVersion == execVersion { | ||
| for _, from := range fromVersions { | ||
| if from == dataVersion { | ||
| klog.ErrorS(nil, "Detected an attempt of unsupported upgrade", "existing-data-version", dataVersion, "new-binary-version", execVersion) | ||
| return true | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| klog.InfoS("Upgrade is allowed", "existing-data-version", dataVersion, "new-binary-version", execVersion) | ||
| return false | ||
| } | ||
This file contains hidden or 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,77 @@ | ||
| package prerun | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func Test_UnmarshalBlockedUpgrades(t *testing.T) { | ||
| testData := []struct { | ||
| input string | ||
| expectedOutput map[string][]string | ||
| }{ | ||
| { | ||
| input: `{"4.14.10": ["4.14.5", "4.14.4"]}`, | ||
| expectedOutput: map[string][]string{"4.14.10": {"4.14.5", "4.14.4"}}, | ||
| }, | ||
| { | ||
| input: `{}`, | ||
| expectedOutput: make(map[string][]string), | ||
| }, | ||
| } | ||
|
|
||
| for _, td := range testData { | ||
| result, err := unmarshalBlockedUpgrades([]byte(td.input)) | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, td.expectedOutput, result) | ||
| } | ||
| } | ||
|
|
||
| func Test_IsBlocked(t *testing.T) { | ||
| edges := map[string][]string{ | ||
| "4.14.10": {"4.14.5", "4.14.6"}, | ||
| "4.15.5": {"4.15.2"}, | ||
| } | ||
|
|
||
| testData := []struct { | ||
| dataVersion string | ||
| execVersion string | ||
| expectedResult bool | ||
| }{ | ||
| { | ||
| dataVersion: "4.14.4", | ||
| execVersion: "4.14.10", | ||
| expectedResult: false, | ||
| }, | ||
| { | ||
| dataVersion: "4.14.5", | ||
| execVersion: "4.14.10", | ||
| expectedResult: true, | ||
| }, | ||
| { | ||
| dataVersion: "4.14.6", | ||
| execVersion: "4.14.10", | ||
| expectedResult: true, | ||
| }, | ||
| { | ||
| dataVersion: "4.14.7", | ||
| execVersion: "4.14.10", | ||
| expectedResult: false, | ||
| }, | ||
| { | ||
| dataVersion: "4.14.7", | ||
| execVersion: "4.15.0", | ||
| expectedResult: false, | ||
| }, | ||
| { | ||
| dataVersion: "4.15.2", | ||
| execVersion: "4.15.5", | ||
| expectedResult: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, td := range testData { | ||
| assert.Equal(t, td.expectedResult, isBlocked(edges, td.execVersion, td.dataVersion)) | ||
| } | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is using an asset easier to manage than just embedding the list in this go module? Are you thinking of automation managing that file (in which case, yes, I agree YAML is going to be easier)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point I don't have any idea how we'll use this feature and manage the list. Asset just felt natural since we already embed some files that way but it's not a strong feeling and we can change it