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

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

Fix: handle invalid semver
......@@ -52,7 +52,7 @@ const (
)
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()
app := &v1alpha1.HelmApplication{}
......
......@@ -210,41 +210,42 @@ func (r *ReconcileHelmApplicationVersion) updateStatus(appVersion *v1alpha1.Helm
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 {
l := versions.Items
if len(l) == 0 {
if len(versions.Items) == 0 {
return ""
}
verInd := 0
if inAppStore {
// only check active app version
for ; verInd < len(l); verInd++ {
if l[verInd].Status.State == v1alpha1.StateActive {
break
}
}
}
if verInd == len(l) {
return ""
}
var latestVersionName string
var latestSemver *semver.Version
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++ {
curr, _ := semver.NewVersion(l[i].GetSemver())
if inAppStore {
if l[i].Status.State != v1alpha1.StateActive {
continue
currSemver, err := semver.NewVersion(version.GetSemver())
if err == nil {
if latestSemver == nil {
// the first valid semver
latestSemver = currSemver
latestVersionName = version.GetVersionName()
} else if latestSemver.LessThan(currSemver) {
// find a newer valid semver
latestSemver = currSemver
latestVersionName = version.GetVersionName()
}
}
if latestSemver.LessThan(curr) {
verInd = i
} else {
// If the semver is invalid, just ignore it.
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 {
......@@ -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 {
return v1alpha1.StateActive
}
......@@ -267,6 +268,7 @@ func mergeApplicationVersionState(versions v1alpha1.HelmApplicationVersionList)
return v1alpha1.StateDraft
}
// No active appVersion or draft appVersion, then the app state is suspended
if states[v1alpha1.StateSuspended] > 0 {
return v1alpha1.StateSuspended
}
......
......@@ -32,7 +32,6 @@ import (
"kubesphere.io/kubesphere/pkg/utils/stringutils"
"path"
"regexp"
"sort"
"strings"
"time"
)
......@@ -320,10 +319,16 @@ func convertApp(app *v1alpha1.HelmApplication, versions []*v1alpha1.HelmApplicat
} else {
out.CategorySet = AppCategorySet{}
}
if versions != nil && len(versions) > 0 {
sort.Sort(AppVersions(versions))
out.LatestAppVersion = convertAppVersion(versions[len(versions)-1])
} else {
for _, version := range versions {
if app.Status.LatestVersion == version.GetVersionName() {
// find the latest version, and convert its format
out.LatestAppVersion = convertAppVersion(version)
break
}
}
if out.LatestAppVersion == nil {
out.LatestAppVersion = &AppVersion{}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册