From fa0e7ca7360037d2a2a4d22b4803f713c78df167 Mon Sep 17 00:00:00 2001 From: William Saakyan Date: Wed, 5 Feb 2025 14:40:40 +0100 Subject: [PATCH] Decouple needFullUpdate --- controllers/sync.go | 26 ++++++++++++++++++-------- pkg/consts/types.go | 4 +++- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/controllers/sync.go b/controllers/sync.go index 35465b25..470dceba 100644 --- a/controllers/sync.go +++ b/controllers/sync.go @@ -32,7 +32,7 @@ func canUpdateComponent(selectors []ytv1.ComponentUpdateSelector, component ytv1 case consts.ComponentGroupNothing: return false case consts.ComponentGroupStateful: - if component.Type == consts.DataNodeType || component.Type == consts.TabletNodeType { + if component.Type != consts.MasterType { return true } case consts.ComponentGroupStateless: @@ -52,8 +52,6 @@ func canUpdateComponent(selectors []ytv1.ComponentUpdateSelector, component ytv1 // If update is not blocked, updateMeta containing a chosen flow and the component names to update returned. func chooseUpdatingComponents(spec ytv1.YtsaurusSpec, needUpdate []components.Component, allComponents []components.Component) (components []ytv1.Component, blockMsg string) { configuredSelectors := getEffectiveSelectors(spec) - needFullUpdate := false - var canUpdate []ytv1.Component var cannotUpdate []ytv1.Component @@ -68,10 +66,6 @@ func chooseUpdatingComponents(spec ytv1.YtsaurusSpec, needUpdate []components.Co } else { cannotUpdate = append(cannotUpdate, component) } - statelessCheck := canUpdateComponent([]ytv1.ComponentUpdateSelector{{ComponentGroup: consts.ComponentGroupStateless}}, component) - if !statelessCheck && component.Type != consts.DataNodeType { - needFullUpdate = true - } } if len(canUpdate) == 0 { @@ -82,7 +76,8 @@ func chooseUpdatingComponents(spec ytv1.YtsaurusSpec, needUpdate []components.Co } if len(configuredSelectors) == 1 && configuredSelectors[0].ComponentGroup == consts.ComponentGroupEverything { - if needFullUpdate { + if needFullUpdate(needUpdate) { + // Here we update not only components that are not up-to-date, but all cluster. return convertToComponent(allComponents), "" } else { return canUpdate, "" @@ -91,6 +86,21 @@ func chooseUpdatingComponents(spec ytv1.YtsaurusSpec, needUpdate []components.Co return canUpdate, "" } +func needFullUpdate(needUpdate []components.Component) bool { + statelessSelector := []ytv1.ComponentUpdateSelector{{ComponentGroup: consts.ComponentGroupStateless}} + for _, comp := range needUpdate { + component := ytv1.Component{ + Name: comp.GetName(), + Type: comp.GetType(), + } + isStateless := canUpdateComponent(statelessSelector, component) + if !isStateless && component.Type != consts.DataNodeType { + return true + } + } + return false +} + func getEffectiveSelectors(spec ytv1.YtsaurusSpec) []ytv1.ComponentUpdateSelector { if len(spec.UpdateSelectors) != 0 { return spec.UpdateSelectors diff --git a/pkg/consts/types.go b/pkg/consts/types.go index 41ef82bd..02f66edd 100644 --- a/pkg/consts/types.go +++ b/pkg/consts/types.go @@ -28,7 +28,9 @@ const ( type ComponentGroup string const ( - ComponentGroupStateless ComponentGroup = "Stateless" + // ComponentGroupStateless group contains only stateless components (not master, data nodes, tablet nodes) + ComponentGroupStateless ComponentGroup = "Stateless" + // ComponentGroupStateful group contains every component except master ComponentGroupStateful ComponentGroup = "Stateful" ComponentGroupEverything ComponentGroup = "Everything" ComponentGroupNothing ComponentGroup = "Nothing"