@@ -128,26 +128,42 @@ func updateHealthStatus(ctx context.Context, container containerd.Container, hcC
128128 currentHealth = & HealthState {
129129 Status : Starting ,
130130 FailingStreak : 0 ,
131+ StartPeriod : hcConfig .StartPeriod > 0 ,
131132 }
132133 }
133134
134- // Check if still within start period
135- startPeriod := hcConfig .StartPeriod
135+ // Get container info for start period check
136136 info , err := container .Info (ctx )
137137 if err != nil {
138138 return fmt .Errorf ("failed to get container info: %w" , err )
139139 }
140140 containerCreated := info .CreatedAt
141- stillInStartPeriod := hcResult .Start .Sub (containerCreated ) < startPeriod
142-
143- // Update health status based on exit code
144- if hcResult .ExitCode == 0 {
145- currentHealth .Status = Healthy
146- currentHealth .FailingStreak = 0
147- } else if ! stillInStartPeriod {
148- currentHealth .FailingStreak ++
149- if currentHealth .FailingStreak >= hcConfig .Retries {
150- currentHealth .Status = Unhealthy
141+
142+ // Check if we're in start period workflow
143+ inStartPeriodTime := hcResult .Start .Sub (containerCreated ) < hcConfig .StartPeriod
144+ inStartPeriodState := currentHealth .StartPeriod
145+
146+ if inStartPeriodTime && inStartPeriodState {
147+ // Start Period Workflow
148+ if hcResult .ExitCode == 0 {
149+ // First healthy result transitions us out of start period
150+ currentHealth .Status = Healthy
151+ currentHealth .FailingStreak = 0
152+ currentHealth .StartPeriod = false
153+ }
154+ // Ignore unhealthy results during start period
155+ } else {
156+ // Health Interval Workflow
157+ if hcResult .ExitCode == 0 {
158+ if currentHealth .Status != Healthy {
159+ currentHealth .Status = Healthy
160+ currentHealth .FailingStreak = 0
161+ }
162+ } else {
163+ currentHealth .FailingStreak ++
164+ if currentHealth .FailingStreak >= hcConfig .Retries && currentHealth .Status != Unhealthy {
165+ currentHealth .Status = Unhealthy
166+ }
151167 }
152168 }
153169
0 commit comments