Skip to content

Commit

Permalink
fix(readiness): prioritize forced success status over failure
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Lesikov <[email protected]>
  • Loading branch information
ilya-lesikov committed Feb 28, 2024
1 parent c1febe1 commit 7163abd
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions pkg/trackers/dyntracker/dynamic_readiness_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,14 +977,6 @@ func (t *DynamicReadinessTracker) handleDeploymentStatus(status *deployment.Depl
})
}

if status.IsFailed {
taskState.ResourceState(taskState.Name(), taskState.Namespace(), taskState.GroupVersionKind()).RWTransaction(func(rs *statestore.ResourceState) {
rs.AddError(errors.New(status.FailedReason), "", time.Now())
})

return
}

if status.IsReady {
taskState.SetStatus(statestore.ReadinessTaskStatusReady)

Expand All @@ -994,14 +986,6 @@ func (t *DynamicReadinessTracker) handleDeploymentStatus(status *deployment.Depl
})
}
}
}

func (t *DynamicReadinessTracker) handleStatefulSetStatus(status *statefulset.StatefulSetStatus, taskState *statestore.ReadinessTaskState) {
if status.ReplicasIndicator != nil {
taskState.ResourceState(taskState.Name(), taskState.Namespace(), taskState.GroupVersionKind()).RWTransaction(func(rs *statestore.ResourceState) {
setReplicasAttribute(rs, int(status.ReplicasIndicator.TargetValue))
})
}

if status.IsFailed {
taskState.ResourceState(taskState.Name(), taskState.Namespace(), taskState.GroupVersionKind()).RWTransaction(func(rs *statestore.ResourceState) {
Expand All @@ -1010,6 +994,14 @@ func (t *DynamicReadinessTracker) handleStatefulSetStatus(status *statefulset.St

return
}
}

func (t *DynamicReadinessTracker) handleStatefulSetStatus(status *statefulset.StatefulSetStatus, taskState *statestore.ReadinessTaskState) {
if status.ReplicasIndicator != nil {
taskState.ResourceState(taskState.Name(), taskState.Namespace(), taskState.GroupVersionKind()).RWTransaction(func(rs *statestore.ResourceState) {
setReplicasAttribute(rs, int(status.ReplicasIndicator.TargetValue))
})
}

if status.IsReady {
taskState.SetStatus(statestore.ReadinessTaskStatusReady)
Expand All @@ -1020,14 +1012,6 @@ func (t *DynamicReadinessTracker) handleStatefulSetStatus(status *statefulset.St
})
}
}
}

func (t *DynamicReadinessTracker) handleDaemonSetStatus(status *daemonset.DaemonSetStatus, taskState *statestore.ReadinessTaskState) {
if status.ReplicasIndicator != nil {
taskState.ResourceState(taskState.Name(), taskState.Namespace(), taskState.GroupVersionKind()).RWTransaction(func(rs *statestore.ResourceState) {
setReplicasAttribute(rs, int(status.ReplicasIndicator.TargetValue))
})
}

if status.IsFailed {
taskState.ResourceState(taskState.Name(), taskState.Namespace(), taskState.GroupVersionKind()).RWTransaction(func(rs *statestore.ResourceState) {
Expand All @@ -1036,6 +1020,14 @@ func (t *DynamicReadinessTracker) handleDaemonSetStatus(status *daemonset.Daemon

return
}
}

func (t *DynamicReadinessTracker) handleDaemonSetStatus(status *daemonset.DaemonSetStatus, taskState *statestore.ReadinessTaskState) {
if status.ReplicasIndicator != nil {
taskState.ResourceState(taskState.Name(), taskState.Namespace(), taskState.GroupVersionKind()).RWTransaction(func(rs *statestore.ResourceState) {
setReplicasAttribute(rs, int(status.ReplicasIndicator.TargetValue))
})
}

if status.IsReady {
taskState.SetStatus(statestore.ReadinessTaskStatusReady)
Expand All @@ -1046,12 +1038,6 @@ func (t *DynamicReadinessTracker) handleDaemonSetStatus(status *daemonset.Daemon
})
}
}
}

func (t *DynamicReadinessTracker) handleJobStatus(status *job.JobStatus, taskState *statestore.ReadinessTaskState) {
taskState.ResourceState(taskState.Name(), taskState.Namespace(), taskState.GroupVersionKind()).RWTransaction(func(rs *statestore.ResourceState) {
setReplicasAttribute(rs, 1)
})

if status.IsFailed {
taskState.ResourceState(taskState.Name(), taskState.Namespace(), taskState.GroupVersionKind()).RWTransaction(func(rs *statestore.ResourceState) {
Expand All @@ -1060,6 +1046,12 @@ func (t *DynamicReadinessTracker) handleJobStatus(status *job.JobStatus, taskSta

return
}
}

func (t *DynamicReadinessTracker) handleJobStatus(status *job.JobStatus, taskState *statestore.ReadinessTaskState) {
taskState.ResourceState(taskState.Name(), taskState.Namespace(), taskState.GroupVersionKind()).RWTransaction(func(rs *statestore.ResourceState) {
setReplicasAttribute(rs, 1)
})

if status.IsSucceeded {
taskState.SetStatus(statestore.ReadinessTaskStatusReady)
Expand All @@ -1070,17 +1062,17 @@ func (t *DynamicReadinessTracker) handleJobStatus(status *job.JobStatus, taskSta
})
}
}
}

func (t *DynamicReadinessTracker) handleCanaryStatus(status *canary.CanaryStatus, taskState *statestore.ReadinessTaskState) {
if status.IsFailed {
taskState.ResourceState(taskState.Name(), taskState.Namespace(), taskState.GroupVersionKind()).RWTransaction(func(rs *statestore.ResourceState) {
rs.AddError(errors.New(status.FailedReason), "", time.Now())
})

return
}
}

func (t *DynamicReadinessTracker) handleCanaryStatus(status *canary.CanaryStatus, taskState *statestore.ReadinessTaskState) {
if status.IsSucceeded {
taskState.SetStatus(statestore.ReadinessTaskStatusReady)

Expand All @@ -1090,21 +1082,21 @@ func (t *DynamicReadinessTracker) handleCanaryStatus(status *canary.CanaryStatus
})
}
}
}

func (t *DynamicReadinessTracker) handleGenericResourceStatus(status *generic.ResourceStatus, taskState *statestore.ReadinessTaskState) {
if status.Indicator != nil {
if status.IsFailed {
taskState.ResourceState(taskState.Name(), taskState.Namespace(), taskState.GroupVersionKind()).RWTransaction(func(rs *statestore.ResourceState) {
setGenericConditionAttributes(rs, status)
rs.AddError(errors.New(status.FailedReason), "", time.Now())
})

return
}
}

if status.IsFailed() {
func (t *DynamicReadinessTracker) handleGenericResourceStatus(status *generic.ResourceStatus, taskState *statestore.ReadinessTaskState) {
if status.Indicator != nil {
taskState.ResourceState(taskState.Name(), taskState.Namespace(), taskState.GroupVersionKind()).RWTransaction(func(rs *statestore.ResourceState) {
rs.AddError(errors.New(status.FailureReason()), "", time.Now())
setGenericConditionAttributes(rs, status)
})

return
}

if status.IsReady() {
Expand All @@ -1119,6 +1111,14 @@ func (t *DynamicReadinessTracker) handleGenericResourceStatus(status *generic.Re
return
}

if status.IsFailed() {
taskState.ResourceState(taskState.Name(), taskState.Namespace(), taskState.GroupVersionKind()).RWTransaction(func(rs *statestore.ResourceState) {
rs.AddError(errors.New(status.FailureReason()), "", time.Now())
})

return
}

if status.IsDeleted() {
for _, state := range taskState.ResourceStates() {
state.RWTransaction(func(rs *statestore.ResourceState) {
Expand Down

0 comments on commit 7163abd

Please sign in to comment.