diff --git a/pkg/airgap/update.go b/pkg/airgap/update.go index a3b7582d92..b143bc8860 100644 --- a/pkg/airgap/update.go +++ b/pkg/airgap/update.go @@ -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") @@ -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 } diff --git a/pkg/airgap/update_test.go b/pkg/airgap/update_test.go index 9f341cdcc7..40180a907b 100644 --- a/pkg/airgap/update_test.go +++ b/pkg/airgap/update_test.go @@ -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 }{ @@ -167,6 +168,7 @@ func Test_getMissingRequiredVersions(t *testing.T) { license: &kotsv1beta1.License{ Spec: kotsv1beta1.LicenseSpec{}, }, + channelChanged: true, installedVersions: []*downstreamtypes.DownstreamVersion{ { ChannelID: "different-channel", @@ -174,8 +176,8 @@ func Test_getMissingRequiredVersions(t *testing.T) { 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 { @@ -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) })