mirror of
https://github.com/labring/sealos.git
synced 2026-09-24 15:46:19 +08:00
fix: devbox release tag use last predicated success commit. (#5379)
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
reference "github.com/google/go-containerregistry/pkg/name"
|
||||
|
||||
@@ -85,7 +86,7 @@ func (r *DevBoxReleaseReconciler) Reconcile(ctx context.Context, req ctrl.Reques
|
||||
err := r.CreateReleaseTag(ctx, devboxRelease)
|
||||
if err != nil && errors.Is(err, registry.ErrorManifestNotFound) {
|
||||
logger.Info("Manifest not found, retrying", "devbox", devboxRelease.Spec.DevboxName, "newTag", devboxRelease.Spec.NewTag)
|
||||
return ctrl.Result{Requeue: true}, nil
|
||||
return ctrl.Result{RequeueAfter: time.Second * 10}, nil
|
||||
} else if err != nil {
|
||||
logger.Error(err, "Failed to create release tag", "devbox", devboxRelease.Spec.DevboxName, "newTag", devboxRelease.Spec.NewTag)
|
||||
devboxRelease.Status.Phase = devboxv1alpha1.DevboxReleasePhaseFailed
|
||||
@@ -135,7 +136,7 @@ func (r *DevBoxReleaseReconciler) GetImageInfo(devbox *devboxv1alpha1.Devbox) (s
|
||||
if len(devbox.Status.CommitHistory) == 0 {
|
||||
return "", "", "", fmt.Errorf("commit history is empty")
|
||||
}
|
||||
commitHistory := helper.GetLastSuccessCommitHistory(devbox)
|
||||
commitHistory := helper.GetLastPredicatedSuccessCommitHistory(devbox)
|
||||
if commitHistory == nil {
|
||||
return "", "", "", fmt.Errorf("no successful commit history found")
|
||||
}
|
||||
|
||||
@@ -254,6 +254,22 @@ func GetLastSuccessCommitHistory(devbox *devboxv1alpha1.Devbox) *devboxv1alpha1.
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetLastPredicatedSuccessCommitHistory(devbox *devboxv1alpha1.Devbox) *devboxv1alpha1.CommitHistory {
|
||||
if len(devbox.Status.CommitHistory) == 0 {
|
||||
return nil
|
||||
}
|
||||
// Sort commit history by time in descending order
|
||||
sort.Slice(devbox.Status.CommitHistory, func(i, j int) bool {
|
||||
return devbox.Status.CommitHistory[i].Time.After(devbox.Status.CommitHistory[j].Time.Time)
|
||||
})
|
||||
for _, commit := range devbox.Status.CommitHistory {
|
||||
if commit.PredicatedStatus == devboxv1alpha1.CommitStatusSuccess {
|
||||
return commit
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetLastSuccessCommitImageName(devbox *devboxv1alpha1.Devbox) string {
|
||||
if len(devbox.Status.CommitHistory) == 0 {
|
||||
return devbox.Spec.Image
|
||||
|
||||
Reference in New Issue
Block a user