Skip to content

Commit aca74a2

Browse files
committed
controller: fix component is Started state when a vm is Unhealthy
1 parent 5de9dd8 commit aca74a2

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

controller/reconcile.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,17 +484,20 @@ func (c *Controller) createComponentVMs(appName string, comp *v1.Component, comp
484484
if err := db.DB.Model(&v1.VirtualMachine{}).Where("name LIKE ?", comp.Metadata.Name+"-%").Count(&count).Error; err == nil {
485485
comp.ObservedReplicas = int(count)
486486
}
487-
// If the component is not being removed, mark it Started/Ready now that
488-
// its VMs have been created/ensured. This mirrors Application state.
489-
if comp.Status.ObservedState != "Removing" {
490-
comp.Status.Ready = false // not healthy yet, just started
491-
comp.Status.ObservedState = "Started"
492-
comp.Status.LastChecked = time.Now()
493-
}
487+
// Persist observed replica count first.
494488
if err := db.DB.Save(comp).Error; err != nil {
495489
return err
496490
}
497491

492+
// After creating VMs, run a health check to set the component state.
493+
// This avoids overwriting a previously-detected Unhealthy state with
494+
// a generic "Started" value when one or more VMs remain unhealthy.
495+
if comp.Status.ObservedState != "Removing" {
496+
if _, err := c.CheckComponentHealth(comp); err != nil {
497+
return err
498+
}
499+
}
500+
498501
return nil
499502
}
500503

0 commit comments

Comments
 (0)