@@ -22,18 +22,18 @@ type ComponentManager struct {
2222}
2323
2424type ComponentManagerStatus struct {
25- needSync bool
26- needInit bool
27- needUpdate []components.Component
28- allReadyOrUpdating bool
25+ allReady bool // All components are Ready - no reconciliations required
26+ allRunning bool // All components are Ready or NeedUpdate - can start updates
27+ allReadyOrUpdating bool // All components are Ready or Updating - no new updates
28+
29+ needUpdate []components.Component // Components in state NeedUpdate
2930}
3031
3132func NewComponentManager (
3233 ctx context.Context ,
3334 ytsaurus * apiProxy.Ytsaurus ,
3435 clusterDomain string ,
3536) (* ComponentManager , error ) {
36- logger := log .FromContext (ctx )
3737 resource := ytsaurus .GetResource ()
3838
3939 if clusterDomain == "" {
@@ -164,79 +164,87 @@ func NewComponentManager(
164164 tt := components .NewTimbertruck (cfgen , ytsaurus , tnds , yc )
165165 allComponents = append (allComponents , tt )
166166
167+ return & ComponentManager {
168+ ytsaurus : ytsaurus ,
169+ allComponents : allComponents ,
170+ }, nil
171+ }
172+
173+ func (cm * ComponentManager ) FetchStatus (ctx context.Context ) error {
174+ logger := log .FromContext (ctx )
175+ resource := cm .ytsaurus .GetResource ()
176+
167177 // Fetch component status.
168178 var readyComponents []string
179+ var needUpdateComponents []string
169180 var updatingComponents []string
170181 var notReadyComponents []string
171182
172- status := ComponentManagerStatus {
173- needInit : false ,
174- needSync : false ,
175- needUpdate : nil ,
183+ cm .status = ComponentManagerStatus {
184+ allReady : true ,
185+ allRunning : true ,
176186 allReadyOrUpdating : true ,
187+ needUpdate : nil ,
177188 }
178- for _ , c := range allComponents {
179- err := c .Fetch (ctx )
180- if err != nil {
181- logger .Error (err , "failed to fetch status for controller" , "component" , c .GetFullName ())
182- return nil , err
183- }
184189
185- componentStatus , err := c .Status (ctx )
190+ for _ , component := range cm .allComponents {
191+ err := component .Fetch (ctx )
186192 if err != nil {
187- return nil , fmt .Errorf ("failed to get component %s status : %w" , c .GetFullName (), err )
193+ return fmt .Errorf ("failed to fetch component %s: %w" , component .GetFullName (), err )
188194 }
189195
190- c .SetReadyCondition (componentStatus )
191- syncStatus := componentStatus .SyncStatus
192-
193- if syncStatus == components .SyncStatusNeedLocalUpdate {
194- status .needUpdate = append (status .needUpdate , c )
196+ status , err := component .Status (ctx )
197+ if err != nil {
198+ return fmt .Errorf ("failed to get component %s status: %w" , component .GetFullName (), err )
195199 }
196200
197- if ! components .IsRunningStatus (syncStatus ) {
198- if ytsaurus .GetClusterState () == ytv1 .ClusterStateRunning {
199- msg := fmt .Sprintf ("component `%s` status is neither Ready nor NeedLocalUpdate, but `%s`, " +
200- "needInit=true will be set, which will lead to Reconfiguration since cluster is in Running state" ,
201- c .GetFullName (), syncStatus ,
202- )
203- logger .Info (msg ,
204- "component" , c .GetFullName (),
205- "syncStatus" , syncStatus ,
201+ component .SetReadyCondition (status )
202+ logger .Info ("Component status" ,
203+ "component" , component .GetFullName (),
204+ "status" , status .SyncStatus ,
205+ "message" , status .Message ,
206+ )
207+
208+ switch status .SyncStatus {
209+ case components .SyncStatusReady :
210+ readyComponents = append (readyComponents , component .GetFullName ())
211+ case components .SyncStatusNeedUpdate :
212+ needUpdateComponents = append (needUpdateComponents , component .GetFullName ())
213+ cm .status .needUpdate = append (cm .status .needUpdate , component )
214+ cm .status .allReady = false
215+ cm .status .allReadyOrUpdating = false
216+ case components .SyncStatusUpdating :
217+ updatingComponents = append (updatingComponents , component .GetFullName ())
218+ cm .status .allReady = false
219+ cm .status .allRunning = false
220+ default :
221+ notReadyComponents = append (notReadyComponents , component .GetFullName ())
222+ cm .status .allReady = false
223+ cm .status .allRunning = false
224+ cm .status .allReadyOrUpdating = false
225+ if cm .ytsaurus .GetClusterState () == ytv1 .ClusterStateRunning {
226+ logger .Info ("Cluster needs reconfiguration because component is not running" ,
227+ "component" , component .GetFullName (),
228+ "status" , status .SyncStatus ,
229+ "message" , status .Message ,
206230 )
207231 }
208- status .needInit = true
209- }
210-
211- if syncStatus != components .SyncStatusReady && syncStatus != components .SyncStatusUpdating {
212- status .allReadyOrUpdating = false
213- }
214-
215- if syncStatus != components .SyncStatusReady {
216- logger .Info ("component is not ready" , "component" , c .GetFullName (), "syncStatus" , syncStatus , "message" , componentStatus .Message )
217- notReadyComponents = append (notReadyComponents , c .GetFullName ())
218- status .needSync = true
219- } else {
220- readyComponents = append (readyComponents , c .GetFullName ())
221- }
222-
223- if syncStatus == components .SyncStatusUpdating {
224- updatingComponents = append (updatingComponents , c .GetFullName ())
225232 }
226233 }
227234
228235 logger .Info ("Ytsaurus sync status" ,
236+ "clusterState" , resource .Status .State ,
237+ "updateState" , resource .Status .UpdateStatus .State ,
238+ "allReady" , cm .status .allReady ,
239+ "allRunning" , cm .status .allRunning ,
240+ "allReadyOrUpdating" , cm .status .allReadyOrUpdating ,
241+ "needUpdateComponents" , needUpdateComponents ,
242+ "updatingComponents" , updatingComponents ,
229243 "notReadyComponents" , notReadyComponents ,
230244 "readyComponents" , readyComponents ,
231- "updatingComponents" , updatingComponents ,
232- "updateState" , resource .Status .UpdateStatus .State ,
233- "clusterState" , resource .Status .State )
245+ )
234246
235- return & ComponentManager {
236- ytsaurus : ytsaurus ,
237- allComponents : allComponents ,
238- status : status ,
239- }, nil
247+ return nil
240248}
241249
242250func (cm * ComponentManager ) Sync (ctx context.Context ) (ctrl.Result , error ) {
@@ -273,22 +281,6 @@ func (cm *ComponentManager) Sync(ctx context.Context) (ctrl.Result, error) {
273281 return ctrl.Result {RequeueAfter : time .Second }, nil
274282}
275283
276- func (cm * ComponentManager ) needSync () bool {
277- return cm .status .needSync
278- }
279-
280- func (cm * ComponentManager ) needInit () bool {
281- return cm .status .needInit
282- }
283-
284- func (cm * ComponentManager ) needUpdate () []components.Component {
285- return cm .status .needUpdate
286- }
287-
288- func (cm * ComponentManager ) allReadyOrUpdating () bool {
289- return cm .status .allReadyOrUpdating
290- }
291-
292284func (cm * ComponentManager ) arePodsRemoved () bool {
293285 for _ , cmp := range cm .allComponents {
294286 if cmp .GetType () == consts .YtsaurusClientType {
0 commit comments