ce7cb702218693d08ea6d83464d2457c9250027c

This commit is contained in:
ms2k 2026-11-12 20:46:28 +09:00
commit 34c5f8963c

View file

@ -0,0 +1,67 @@
diff --git a/pkg/cmpstatus/quay.go b/pkg/cmpstatus/quay.go
index 29ed6cb..c37a76a 100644
--- a/pkg/cmpstatus/quay.go
+++ b/pkg/cmpstatus/quay.go
@@ -128,6 +128,12 @@ func (q *Quay) upgradeJob(ctx context.Context, reg qv1.QuayRegistry) error {
var job batchv1.Job
if err := q.Client.Get(ctx, nsn, &job); err != nil {
if errors.IsNotFound(err) {
+ created := qv1.GetCondition(reg.Status.Conditions, qv1.ConditionComponentsCreated)
+ if reg.Status.CurrentVersion != "" && reg.Status.CurrentVersion == qv1.QuayVersionCurrent &&
+ created != nil && created.Status == metav1.ConditionTrue &&
+ created.Reason == qv1.ConditionReasonComponentsCreationSuccess {
+ return nil
+ }
return fmt.Errorf("job %s not found", jname)
}
return fmt.Errorf("unexpected error reading upgrade job: %w", err)
diff --git a/pkg/cmpstatus/quay_test.go b/pkg/cmpstatus/quay_test.go
index 04be959..ddeac87 100644
--- a/pkg/cmpstatus/quay_test.go
+++ b/pkg/cmpstatus/quay_test.go
@@ -415,3 +415,45 @@ func TestQuayCheck(t *testing.T) {
})
}
}
+
+func TestUpgradeReceipt(t *testing.T) {
+ old := qv1.QuayVersionCurrent
+ qv1.QuayVersionCurrent = "3.18.2"
+ t.Cleanup(func() { qv1.QuayVersionCurrent = old })
+ for _, tc := range []struct {
+ name string
+ version qv1.QuayVersion
+ condition *qv1.Condition
+ job *batchv1.Job
+ wantErr bool
+ }{
+ {name: "completed", version: "3.18.2", condition: &qv1.Condition{Type: qv1.ConditionComponentsCreated, Status: metav1.ConditionTrue, Reason: qv1.ConditionReasonComponentsCreationSuccess}},
+ {name: "initial", wantErr: true},
+ {name: "older", version: "3.18.1", condition: &qv1.Condition{Type: qv1.ConditionComponentsCreated, Status: metav1.ConditionTrue, Reason: qv1.ConditionReasonComponentsCreationSuccess}, wantErr: true},
+ {name: "no receipt", version: "3.18.2", wantErr: true},
+ {name: "migrating", version: "3.18.2", condition: &qv1.Condition{Type: qv1.ConditionComponentsCreated, Status: metav1.ConditionFalse, Reason: qv1.ConditionReasonMigrationsInProgress}, wantErr: true},
+ {name: "unfinished job", version: "3.18.2", condition: &qv1.Condition{Type: qv1.ConditionComponentsCreated, Status: metav1.ConditionTrue, Reason: qv1.ConditionReasonComponentsCreationSuccess}, job: &batchv1.Job{ObjectMeta: metav1.ObjectMeta{Name: "registry-quay-app-upgrade", Namespace: "quay"}}, wantErr: true},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ reg := qv1.QuayRegistry{ObjectMeta: metav1.ObjectMeta{Name: "registry", Namespace: "quay"}}
+ reg.Status.CurrentVersion = tc.version
+ if tc.condition != nil {
+ reg.Status.Conditions = []qv1.Condition{*tc.condition}
+ }
+ builder := fake.NewClientBuilder()
+ if tc.job != nil {
+ builder = builder.WithObjects(tc.job)
+ }
+ q := Quay{Client: builder.Build()}
+ if err := q.upgradeJob(context.Background(), reg); (err != nil) != tc.wantErr {
+ t.Fatalf("upgradeJob error = %v, want error %t", err, tc.wantErr)
+ }
+ if !tc.wantErr {
+ cond, err := q.Check(context.Background(), reg)
+ if err != nil || cond.Status != metav1.ConditionFalse || cond.Message != "Deployment registry-quay-app not found" {
+ t.Fatalf("missing deployment must remain unhealthy: %+v, %v", cond, err)
+ }
+ }
+ })
+ }
+}