Skip to content

Commit f2ac936

Browse files
committed
pkg/cvo/availableupdates: Cache original upstream updates
We've been mixing in alerts since 3b365d0 (OTA-1813: Populate risks from alerts, 2026-02-27, #1329). But when the alerts get resolved, we want the cluster to notice quickly. With this change, we keep the original upstream data isolated in new properties, so an evaluation round will be able to clear out resolved alerts, even if needFreshFetch is false because available updates were recently retrieved.
1 parent df0f6d9 commit f2ac936

3 files changed

Lines changed: 44 additions & 16 deletions

File tree

pkg/cvo/availableupdates.go

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,13 @@ func (optr *Operator) syncAvailableUpdates(ctx context.Context, config *configv1
153153
condition.Reason == "ResponseInvalid"))
154154
if !responseFailed || (responseFailed && !preserveCacheOnFailure) {
155155
optrAvailableUpdates.Current = current
156-
optrAvailableUpdates.Updates = updates
157-
optrAvailableUpdates.ConditionalUpdates = conditionalUpdates
156+
optrAvailableUpdates.upstreamUpdates = updates
157+
optrAvailableUpdates.upstreamConditionalUpdates = conditionalUpdates
158158
}
159159
}
160160

161+
optrAvailableUpdates.Updates = deepCopyReleases(optrAvailableUpdates.upstreamUpdates)
162+
optrAvailableUpdates.ConditionalUpdates = deepCopyConditionalUpdates(optrAvailableUpdates.upstreamConditionalUpdates)
161163
optrAvailableUpdates.AcceptRisks = acceptRisks
162164
optrAvailableUpdates.ShouldReconcileAcceptRisks = optr.shouldReconcileAcceptRisks
163165
optrAvailableUpdates.risks = optr.risks
@@ -205,10 +207,12 @@ type availableUpdates struct {
205207
// slice was empty.
206208
LastSyncOrConfigChange time.Time
207209

208-
Current configv1.Release
209-
Updates []configv1.Release
210-
ConditionalUpdates []configv1.ConditionalUpdate
211-
ConditionRegistry clusterconditions.ConditionRegistry
210+
Current configv1.Release
211+
Updates []configv1.Release
212+
upstreamUpdates []configv1.Release
213+
ConditionalUpdates []configv1.ConditionalUpdate
214+
upstreamConditionalUpdates []configv1.ConditionalUpdate
215+
ConditionRegistry clusterconditions.ConditionRegistry
212216

213217
Condition configv1.ClusterOperatorStatusCondition
214218

@@ -332,22 +336,46 @@ func (optr *Operator) getAvailableUpdates() *availableUpdates {
332336
}
333337

334338
if optr.availableUpdates.Updates != nil {
335-
u.Updates = make([]configv1.Release, 0, len(optr.availableUpdates.Updates))
336-
for _, update := range optr.availableUpdates.Updates {
337-
u.Updates = append(u.Updates, *update.DeepCopy())
338-
}
339+
u.Updates = deepCopyReleases(optr.availableUpdates.Updates)
340+
}
341+
342+
if optr.availableUpdates.upstreamUpdates != nil {
343+
u.upstreamUpdates = deepCopyReleases(optr.availableUpdates.upstreamUpdates)
339344
}
340345

341346
if optr.availableUpdates.ConditionalUpdates != nil {
342-
u.ConditionalUpdates = make([]configv1.ConditionalUpdate, 0, len(optr.availableUpdates.ConditionalUpdates))
343-
for _, conditionalUpdate := range optr.availableUpdates.ConditionalUpdates {
344-
u.ConditionalUpdates = append(u.ConditionalUpdates, *conditionalUpdate.DeepCopy())
345-
}
347+
u.ConditionalUpdates = deepCopyConditionalUpdates(optr.availableUpdates.ConditionalUpdates)
348+
}
349+
350+
if optr.availableUpdates.upstreamConditionalUpdates != nil {
351+
u.upstreamConditionalUpdates = deepCopyConditionalUpdates(optr.availableUpdates.upstreamConditionalUpdates)
346352
}
347353

348354
return u
349355
}
350356

357+
func deepCopyReleases(releases []configv1.Release) []configv1.Release {
358+
if releases == nil {
359+
return nil
360+
}
361+
c := make([]configv1.Release, 0, len(releases))
362+
for _, update := range releases {
363+
c = append(c, *update.DeepCopy())
364+
}
365+
return c
366+
}
367+
368+
func deepCopyConditionalUpdates(updates []configv1.ConditionalUpdate) []configv1.ConditionalUpdate {
369+
if updates == nil {
370+
return nil
371+
}
372+
c := make([]configv1.ConditionalUpdate, 0, len(updates))
373+
for _, update := range updates {
374+
c = append(c, *update.DeepCopy())
375+
}
376+
return c
377+
}
378+
351379
func loadRiskConditions(ctx context.Context, risks []string, riskVersions map[string]riskWithVersion, conditionRegistry clusterconditions.ConditionRegistry) map[string][]metav1.Condition {
352380
riskConditions := map[string][]metav1.Condition{}
353381
for _, riskName := range risks {

pkg/cvo/availableupdates_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ var cvFixture = &configv1.ClusterVersion{
213213
}
214214

215215
var availableUpdatesCmpOpts = []cmp.Option{
216+
cmpopts.IgnoreUnexported(availableUpdates{}),
216217
cmpopts.IgnoreFields(availableUpdates{}, "ShouldReconcileAcceptRisks"),
217218
cmpopts.IgnoreTypes(time.Time{}),
218219
cmpopts.IgnoreInterfaces(struct {

pkg/cvo/cvo_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616

1717
"github.com/davecgh/go-spew/spew"
1818
"github.com/google/go-cmp/cmp"
19-
"github.com/google/go-cmp/cmp/cmpopts"
2019
"github.com/google/uuid"
2120

2221
appsv1 "k8s.io/api/apps/v1"
@@ -2783,7 +2782,7 @@ func TestOperator_availableUpdatesSync(t *testing.T) {
27832782
}
27842783
}
27852784

2786-
if diff := cmp.Diff(tt.wantUpdates, optr.availableUpdates, cmpopts.IgnoreFields(availableUpdates{}, "ShouldReconcileAcceptRisks", "risks")); diff != "" {
2785+
if diff := cmp.Diff(tt.wantUpdates, optr.availableUpdates, availableUpdatesCmpOpts...); diff != "" {
27872786
t.Fatalf("unexpected: %s", diff)
27882787
}
27892788
if (optr.queue.Len() > 0) != (optr.availableUpdates != nil) {

0 commit comments

Comments
 (0)