未验证 提交 40e5920c 编写于 作者: K KubeSphere CI Bot 提交者: GitHub

Merge pull request #3574 from xyz-li/app-fix

Fix: handle invalid semver
...@@ -52,7 +52,7 @@ const ( ...@@ -52,7 +52,7 @@ const (
) )
func (r *ReconcileHelmApplication) Reconcile(request reconcile.Request) (reconcile.Result, error) { func (r *ReconcileHelmApplication) Reconcile(request reconcile.Request) (reconcile.Result, error) {
klog.V(4).Info("sync helm application") klog.V(4).Infof("sync helm application: %s ", request.String())
rootCtx := context.Background() rootCtx := context.Background()
app := &v1alpha1.HelmApplication{} app := &v1alpha1.HelmApplication{}
......
...@@ -210,41 +210,42 @@ func (r *ReconcileHelmApplicationVersion) updateStatus(appVersion *v1alpha1.Helm ...@@ -210,41 +210,42 @@ func (r *ReconcileHelmApplicationVersion) updateStatus(appVersion *v1alpha1.Helm
return nil return nil
} }
// getLatestVersionName get the latest version of versions.
// if inAppStore is false, get the latest version name of all of the versions
// if inAppStore is true, get the latest version name of the ACTIVE versions.
func getLatestVersionName(versions v1alpha1.HelmApplicationVersionList, inAppStore bool) string { func getLatestVersionName(versions v1alpha1.HelmApplicationVersionList, inAppStore bool) string {
l := versions.Items if len(versions.Items) == 0 {
if len(l) == 0 {
return "" return ""
} }
verInd := 0 var latestVersionName string
if inAppStore { var latestSemver *semver.Version
// only check active app version
for ; verInd < len(l); verInd++ {
if l[verInd].Status.State == v1alpha1.StateActive {
break
}
}
}
if verInd == len(l) {
return ""
}
latestSemver, _ := semver.NewVersion(l[verInd].GetSemver()) for _, version := range versions.Items {
// If the appVersion is being deleted, ignore it.
// If inAppStore is true, we just need ACTIVE appVersion.
if version.DeletionTimestamp != nil || (inAppStore && version.Status.State != v1alpha1.StateActive) {
continue
}
for i := verInd + 1; i < len(l); i++ { currSemver, err := semver.NewVersion(version.GetSemver())
curr, _ := semver.NewVersion(l[i].GetSemver()) if err == nil {
if inAppStore { if latestSemver == nil {
if l[i].Status.State != v1alpha1.StateActive { // the first valid semver
continue latestSemver = currSemver
latestVersionName = version.GetVersionName()
} else if latestSemver.LessThan(currSemver) {
// find a newer valid semver
latestSemver = currSemver
latestVersionName = version.GetVersionName()
} }
} } else {
if latestSemver.LessThan(curr) { // If the semver is invalid, just ignore it.
verInd = i klog.V(2).Infof("parse version failed, id: %s, err: %s", version.Name, err)
} }
} }
return l[verInd].GetVersionName() return latestVersionName
} }
func mergeApplicationVersionState(versions v1alpha1.HelmApplicationVersionList) string { func mergeApplicationVersionState(versions v1alpha1.HelmApplicationVersionList) string {
...@@ -257,7 +258,7 @@ func mergeApplicationVersionState(versions v1alpha1.HelmApplicationVersionList) ...@@ -257,7 +258,7 @@ func mergeApplicationVersionState(versions v1alpha1.HelmApplicationVersionList)
} }
} }
// If there is on active appVersion, the helm application is active // If there is one or more active appVersion, the helm application is active
if states[v1alpha1.StateActive] > 0 { if states[v1alpha1.StateActive] > 0 {
return v1alpha1.StateActive return v1alpha1.StateActive
} }
...@@ -267,6 +268,7 @@ func mergeApplicationVersionState(versions v1alpha1.HelmApplicationVersionList) ...@@ -267,6 +268,7 @@ func mergeApplicationVersionState(versions v1alpha1.HelmApplicationVersionList)
return v1alpha1.StateDraft return v1alpha1.StateDraft
} }
// No active appVersion or draft appVersion, then the app state is suspended
if states[v1alpha1.StateSuspended] > 0 { if states[v1alpha1.StateSuspended] > 0 {
return v1alpha1.StateSuspended return v1alpha1.StateSuspended
} }
......
...@@ -32,7 +32,6 @@ import ( ...@@ -32,7 +32,6 @@ import (
"kubesphere.io/kubesphere/pkg/utils/stringutils" "kubesphere.io/kubesphere/pkg/utils/stringutils"
"path" "path"
"regexp" "regexp"
"sort"
"strings" "strings"
"time" "time"
) )
...@@ -320,10 +319,16 @@ func convertApp(app *v1alpha1.HelmApplication, versions []*v1alpha1.HelmApplicat ...@@ -320,10 +319,16 @@ func convertApp(app *v1alpha1.HelmApplication, versions []*v1alpha1.HelmApplicat
} else { } else {
out.CategorySet = AppCategorySet{} out.CategorySet = AppCategorySet{}
} }
if versions != nil && len(versions) > 0 {
sort.Sort(AppVersions(versions)) for _, version := range versions {
out.LatestAppVersion = convertAppVersion(versions[len(versions)-1]) if app.Status.LatestVersion == version.GetVersionName() {
} else { // find the latest version, and convert its format
out.LatestAppVersion = convertAppVersion(version)
break
}
}
if out.LatestAppVersion == nil {
out.LatestAppVersion = &AppVersion{} out.LatestAppVersion = &AppVersion{}
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册