Skip to content

Commit

Permalink
skip required versions if channel is different (#4699)
Browse files Browse the repository at this point in the history
* skip required versions if channel is different
---------

Co-authored-by: Salah Al Saleh <[email protected]>
  • Loading branch information
jdewinne and sgalsaleh authored Jun 20, 2024
1 parent 79014da commit ca59bbc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
13 changes: 10 additions & 3 deletions pkg/airgap/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ func UpdateAppFromPath(a *apptypes.App, airgapRoot string, airgapBundlePath stri
return errors.Wrap(err, "failed to create new version")
}

// a version has been created, reset the "channel_changed" flag
if err := store.GetStore().SetAppChannelChanged(a.ID, false); err != nil {
logger.Error(errors.Wrapf(err, "failed to reset channel changed flag"))
}

hasStrictPreflights, err := store.GetStore().HasStrictPreflights(a.ID, newSequence)
if err != nil {
return errors.Wrap(err, "failed to check if app preflight has strict analyzers")
Expand Down Expand Up @@ -318,12 +323,14 @@ func GetMissingRequiredVersions(app *apptypes.App, airgap *kotsv1beta1.Airgap) (
return nil, errors.Wrap(err, "failed to load license")
}

return getMissingRequiredVersions(airgap, license, appVersions.AllVersions)
return getMissingRequiredVersions(airgap, license, appVersions.AllVersions, app.ChannelChanged)
}

func getMissingRequiredVersions(airgap *kotsv1beta1.Airgap, license *kotsv1beta1.License, installedVersions []*downstreamtypes.DownstreamVersion) ([]string, error) {
func getMissingRequiredVersions(airgap *kotsv1beta1.Airgap, license *kotsv1beta1.License, installedVersions []*downstreamtypes.DownstreamVersion, channelChanged bool) ([]string, error) {
missingVersions := make([]string, 0)
if len(installedVersions) == 0 {
// If no versions are installed, we can consider this an initial install.
// If the channel changed, we can consider this an initial install.
if len(installedVersions) == 0 || channelChanged {
return missingVersions, nil
}

Expand Down
10 changes: 6 additions & 4 deletions pkg/airgap/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func Test_getMissingRequiredVersions(t *testing.T) {
airgap *kotsv1beta1.Airgap
license *kotsv1beta1.License
installedVersions []*downstreamtypes.DownstreamVersion
channelChanged bool
wantSemver []string
wantNoSemver []string
}{
Expand Down Expand Up @@ -167,15 +168,16 @@ func Test_getMissingRequiredVersions(t *testing.T) {
license: &kotsv1beta1.License{
Spec: kotsv1beta1.LicenseSpec{},
},
channelChanged: true,
installedVersions: []*downstreamtypes.DownstreamVersion{
{
ChannelID: "different-channel",
VersionLabel: "0.1.117",
UpdateCursor: "117",
},
},
wantNoSemver: []string{"0.1.115", "0.1.120", "0.1.123"},
wantSemver: []string{"0.1.120", "0.1.123"},
wantNoSemver: []string{},
wantSemver: []string{},
},
}
for _, tt := range tests {
Expand All @@ -192,13 +194,13 @@ func Test_getMissingRequiredVersions(t *testing.T) {

// cursor based
tt.license.Spec.IsSemverRequired = false
got, err := getMissingRequiredVersions(tt.airgap, tt.license, tt.installedVersions)
got, err := getMissingRequiredVersions(tt.airgap, tt.license, tt.installedVersions, tt.channelChanged)
req.NoError(err)
req.Equal(tt.wantNoSemver, got)

// semver based
tt.license.Spec.IsSemverRequired = true
got, err = getMissingRequiredVersions(tt.airgap, tt.license, tt.installedVersions)
got, err = getMissingRequiredVersions(tt.airgap, tt.license, tt.installedVersions, tt.channelChanged)
req.NoError(err)
req.Equal(tt.wantSemver, got)
})
Expand Down

0 comments on commit ca59bbc

Please sign in to comment.