Skip to content

Commit 41e1706

Browse files
committed
bypass template upserts on registry only change; ignore unskips on registry change
1 parent 72c7e93 commit 41e1706

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

pkg/stub/config.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +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+
// fourth boolean: if the registry changed, that means a) we have to update all imagestreams regardless of skip lists;
71+
// and b) we don't have to update the templates if that is the only change
7072
// first map: imagestreams that were unskipped (imagestream updates can be expensive, so an optimization)
7173
// second map: templates that were unskipped
72-
func (h *Handler) VariableConfigChanged(cfg *v1.Config) (bool, bool, bool, map[string]bool, map[string]bool) {
74+
func (h *Handler) VariableConfigChanged(cfg *v1.Config) (bool, bool, bool, bool, map[string]bool, map[string]bool) {
7375
configChangeAtAll := false
7476
configChangeRequireUpsert := false
7577
clearImageImportErrors := false
78+
registryChange := false
7679

7780
logrus.Debugf("the before skipped templates %#v", cfg.Status.SkippedTemplates)
7881
logrus.Debugf("the after skipped templates %#v and associated map %#v", cfg.Spec.SkippedTemplates, h.skippedTemplates)
@@ -101,12 +104,6 @@ func (h *Handler) VariableConfigChanged(cfg *v1.Config) (bool, bool, bool, map[s
101104
logrus.Printf("SkippedTemplates changed from %#v to %#v", cfg.Status.SkippedTemplates, cfg.Spec.SkippedTemplates)
102105
}
103106

104-
if cfg.Spec.SamplesRegistry != cfg.Status.SamplesRegistry {
105-
logrus.Printf("SamplesRegistry changed from %s to %s", cfg.Status.SamplesRegistry, cfg.Spec.SamplesRegistry)
106-
configChangeAtAll = true
107-
configChangeRequireUpsert = true
108-
}
109-
110107
streamChange := false
111108
// capture additions/subtractions from skipped list in general change boolean
112109
if len(cfg.Spec.SkippedImagestreams) != len(cfg.Status.SkippedImagestreams) {
@@ -147,7 +144,16 @@ func (h *Handler) VariableConfigChanged(cfg *v1.Config) (bool, bool, bool, map[s
147144
}
148145
}
149146

150-
return configChangeAtAll, configChangeRequireUpsert, clearImageImportErrors, unskippedStreams, unskippedTemplates
147+
if cfg.Spec.SamplesRegistry != cfg.Status.SamplesRegistry {
148+
logrus.Printf("SamplesRegistry changed from %s to %s", cfg.Status.SamplesRegistry, cfg.Spec.SamplesRegistry)
149+
configChangeAtAll = true
150+
configChangeRequireUpsert = true
151+
// skip/unskip imagestream does not matter, reset that list
152+
registryChange = true
153+
unskippedStreams = map[string]bool{}
154+
}
155+
156+
return configChangeAtAll, configChangeRequireUpsert, clearImageImportErrors, registryChange, unskippedStreams, unskippedTemplates
151157
}
152158

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

pkg/stub/handler.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,11 @@ func (h *Handler) Handle(event v1.Event) error {
537537
configChanged := false
538538
configChangeRequiresUpsert := false
539539
configChangeRequiresImportErrorUpdate := false
540+
registryChanged := false
540541
unskippedStreams := map[string]bool{}
541542
unskippedTemplates := map[string]bool{}
542543
if cfg.Spec.ManagementState == cfg.Status.ManagementState {
543-
configChanged, configChangeRequiresUpsert, configChangeRequiresImportErrorUpdate, unskippedStreams, unskippedTemplates = h.VariableConfigChanged(cfg)
544+
configChanged, configChangeRequiresUpsert, configChangeRequiresImportErrorUpdate, registryChanged, unskippedStreams, unskippedTemplates = h.VariableConfigChanged(cfg)
544545
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",
545546
configChanged,
546547
configChangeRequiresUpsert,
@@ -561,7 +562,7 @@ func (h *Handler) Handle(event v1.Event) error {
561562
// and see if any samples were deleted while samples operator was down
562563
h.buildFileMaps(cfg, false)
563564
// passing in false means if the samples is present, we leave it alone
564-
return h.createSamples(cfg, false, unskippedStreams, unskippedTemplates)
565+
return h.createSamples(cfg, false, registryChanged, unskippedStreams, unskippedTemplates)
565566
}
566567
// if config changed requiring an upsert, but a prior config action is still in progress,
567568
// reset in progress to false and return; the next event should drive the actual
@@ -670,7 +671,7 @@ func (h *Handler) Handle(event v1.Event) error {
670671
return err
671672
}
672673

673-
err = h.createSamples(cfg, true, unskippedStreams, unskippedTemplates)
674+
err = h.createSamples(cfg, true, registryChanged, unskippedStreams, unskippedTemplates)
674675
if err != nil {
675676
h.processError(cfg, v1.ImageChangesInProgress, corev1.ConditionUnknown, err, "error creating samples: %v")
676677
logrus.Printf("CRDUPDATE setting in progress to unknown")
@@ -787,7 +788,7 @@ func (h *Handler) setSampleManagedLabelToFalse(kind, name string) error {
787788
return nil
788789
}
789790

790-
func (h *Handler) createSamples(cfg *v1.Config, updateIfPresent bool, unskippedStreams, unskippedTemplates map[string]bool) error {
791+
func (h *Handler) createSamples(cfg *v1.Config, updateIfPresent, registryChanged bool, unskippedStreams, unskippedTemplates map[string]bool) error {
791792
// first, got through the list and prime our upsert cache
792793
// prior to any actual upserts
793794
imagestreams := []*imagev1.ImageStream{}
@@ -835,6 +836,13 @@ func (h *Handler) createSamples(cfg *v1.Config, updateIfPresent bool, unskippedS
835836
return err
836837
}
837838
}
839+
840+
// if after initial startup, and not migration, the only cfg change was changing the registry, since that does not impact
841+
// the templates, we can move on
842+
if len(unskippedTemplates) == 0 && registryChanged && cfg.ConditionTrue(v1.SamplesExist) && cfg.ConditionFalse(v1.MigrationInProgress) {
843+
return nil
844+
}
845+
838846
for _, fileName := range h.templateFile {
839847
template, err := h.Filetemplategetter.Get(fileName)
840848
if err != nil {

0 commit comments

Comments
 (0)