fix: devbox release tag use last predicated success commit. (#5379)

This commit is contained in:
yy
2025-02-18 11:54:31 +08:00
committed by GitHub
parent d4e39c246c
commit 8b81bb67d0
2 changed files with 19 additions and 2 deletions
@@ -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