Skip to content

Commit 092ab39

Browse files
committed
perf improvement for unskipped streams
1 parent c5f1c00 commit 092ab39

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

pkg/stub/config.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,15 @@ func (h *Handler) SpecValidation(cfg *v1.Config) error {
6767
// second boolean: does the config change require a samples upsert; for example, simply adding
6868
// to a skip list does not require a samples upsert
6969
// third boolean: even if an upsert is not needed, update the config instance to clear out image import errors
70-
func (h *Handler) VariableConfigChanged(cfg *v1.Config) (bool, bool, bool) {
70+
// map: imagestreams that were unskipped (imagestream updates can be expensive, so an optimizatino)
71+
func (h *Handler) VariableConfigChanged(cfg *v1.Config) (bool, bool, bool, map[string]bool) {
72+
unskippedStreams := map[string]bool{}
7173
if cfg.Spec.SamplesRegistry != cfg.Status.SamplesRegistry {
7274
logrus.Printf("SamplesRegistry changed from %s to %s", cfg.Status.SamplesRegistry, cfg.Spec.SamplesRegistry)
73-
return true, true, false
75+
return true, true, false, unskippedStreams
7476
}
7577

7678
logrus.Debugf("cfg skipped streams %#v", cfg.Spec.SkippedImagestreams)
77-
unskippedStreams := map[string]bool{}
7879
streamsThatWereSkipped := map[string]bool{}
7980
for _, stream := range cfg.Status.SkippedImagestreams {
8081
streamsThatWereSkipped[stream] = true
@@ -88,12 +89,12 @@ func (h *Handler) VariableConfigChanged(cfg *v1.Config) (bool, bool, bool) {
8889
logrus.Printf("SkippedImagestreams changed in size from %#v to %#v", cfg.Status.SkippedImagestreams, cfg.Spec.SkippedImagestreams)
8990
if len(cfg.Spec.SkippedImagestreams) < len(cfg.Status.SkippedImagestreams) {
9091
// skip list reduced, meaning we need to upsert some samples we were ignoring
91-
return true, true, false
92+
return true, true, false, unskippedStreams
9293
}
9394
// even if the skipped list has been increased, if a stream we were skipping
9495
// has been removed, we need to upsert; assumes buildSkipFilters called beforehand
9596
if len(unskippedStreams) > 0 {
96-
return true, true, true
97+
return true, true, true, unskippedStreams
9798
}
9899

99100
// otherwise, we've only added to the skip list, so don't upsert,but also see if we
@@ -110,7 +111,7 @@ func (h *Handler) VariableConfigChanged(cfg *v1.Config) (bool, bool, bool) {
110111
// we do not break here cause we want to clear out all possible streams
111112
}
112113
}
113-
return true, false, clearImageImportErrors
114+
return true, false, clearImageImportErrors, unskippedStreams
114115
}
115116

116117
clearImageImportErrors := false
@@ -129,33 +130,33 @@ func (h *Handler) VariableConfigChanged(cfg *v1.Config) (bool, bool, bool) {
129130
}
130131
}
131132
if changeInContent {
132-
return changeInContent, changeInContent, clearImageImportErrors
133+
return changeInContent, changeInContent, clearImageImportErrors, unskippedStreams
133134
}
134135

135136
if len(cfg.Spec.SkippedTemplates) != len(cfg.Status.SkippedTemplates) {
136137
logrus.Printf("SkippedTemplates changed from %#v to %#v", cfg.Status.SkippedTemplates, cfg.Spec.SkippedTemplates)
137138
if len(cfg.Spec.SkippedTemplates) < len(cfg.Status.SkippedTemplates) {
138-
return true, true, false
139+
return true, true, false, unskippedStreams
139140
}
140141
for _, tpl := range cfg.Status.SkippedTemplates {
141142
// even if the skipped list has been increased, if a tpl we were skipping
142143
// has been removed, we need to upsert; assumes buildSkipFilters called beforehand
143144
if _, ok := h.skippedTemplates[tpl]; !ok {
144-
return true, true, false
145+
return true, true, false, unskippedStreams
145146
}
146147
}
147-
return true, false, false
148+
return true, false, false, unskippedStreams
148149
}
149150

150151
for _, skip := range cfg.Status.SkippedTemplates {
151152
if _, ok := h.skippedTemplates[skip]; !ok {
152153
logrus.Printf("SkippedTemplates changed in content ... minimally %s has been removed", skip)
153-
return true, true, false
154+
return true, true, false, unskippedStreams
154155
}
155156
}
156157

157158
logrus.Debugf("Incoming Config unchanged from last processed version")
158-
return false, false, false
159+
return false, false, false, unskippedStreams
159160
}
160161

161162
func (h *Handler) buildSkipFilters(opcfg *v1.Config) {

pkg/stub/handler.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,9 @@ func (h *Handler) Handle(event v1.Event) error {
537537
configChanged := false
538538
configChangeRequiresUpsert := false
539539
configChangeRequiresImportErrorUpdate := false
540+
unskippedStreams := map[string]bool{}
540541
if cfg.Spec.ManagementState == cfg.Status.ManagementState {
541-
configChanged, configChangeRequiresUpsert, configChangeRequiresImportErrorUpdate = h.VariableConfigChanged(cfg)
542+
configChanged, configChangeRequiresUpsert, configChangeRequiresImportErrorUpdate, unskippedStreams = h.VariableConfigChanged(cfg)
542543
logrus.Debugf("config changed %v upsert needed %v import error upd needed %v exists/true %v progressing/false %v op version %s status version %s",
543544
configChanged,
544545
configChangeRequiresUpsert,
@@ -559,7 +560,7 @@ func (h *Handler) Handle(event v1.Event) error {
559560
// and see if any samples were deleted while samples operator was down
560561
h.buildFileMaps(cfg, false)
561562
// passing in false means if the samples is present, we leave it alone
562-
return h.createSamples(cfg, false)
563+
return h.createSamples(cfg, false, unskippedStreams)
563564
}
564565
// if config changed requiring an upsert, but a prior config action is still in progress,
565566
// reset in progress to false and return; the next event should drive the actual
@@ -668,7 +669,7 @@ func (h *Handler) Handle(event v1.Event) error {
668669
return err
669670
}
670671

671-
err = h.createSamples(cfg, true)
672+
err = h.createSamples(cfg, true, unskippedStreams)
672673
if err != nil {
673674
h.processError(cfg, v1.ImageChangesInProgress, corev1.ConditionUnknown, err, "error creating samples: %v")
674675
logrus.Printf("CRDUPDATE setting in progress to unknown")
@@ -686,6 +687,11 @@ func (h *Handler) Handle(event v1.Event) error {
686687
progressing.Status = corev1.ConditionTrue
687688
for isName := range h.imagestreamFile {
688689
_, skipped := h.skippedImagestreams[isName]
690+
unskipping := len(unskippedStreams) > 0
691+
_, unskipped := unskippedStreams[isName]
692+
if unskipping && !unskipped {
693+
continue
694+
}
689695
if !cfg.NameInReason(progressing.Reason, isName) && !skipped {
690696
progressing.Reason = progressing.Reason + isName + " "
691697
}
@@ -780,7 +786,7 @@ func (h *Handler) setSampleManagedLabelToFalse(kind, name string) error {
780786
return nil
781787
}
782788

783-
func (h *Handler) createSamples(cfg *v1.Config, updateIfPresent bool) error {
789+
func (h *Handler) createSamples(cfg *v1.Config, updateIfPresent bool, unskippedStreams map[string]bool) error {
784790
// first, got through the list and prime our upsert cache
785791
// prior to any actual upserts
786792
imagestreams := []*imagev1.ImageStream{}
@@ -789,6 +795,15 @@ func (h *Handler) createSamples(cfg *v1.Config, updateIfPresent bool) error {
789795
if err != nil {
790796
return err
791797
}
798+
799+
// if unskippedStreams has >0 entries, then we are down this path to only upsert the streams
800+
// listed there
801+
if len(unskippedStreams) > 0 {
802+
if _, ok := unskippedStreams[imagestream.Name]; !ok {
803+
continue
804+
}
805+
}
806+
792807
if _, isok := h.skippedImagestreams[imagestream.Name]; !isok {
793808
if updateIfPresent {
794809
cache.AddUpsert(imagestream.Name)

0 commit comments

Comments
 (0)