Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improvement] Extract api.Condition Or function #1544

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions pkg/deployment/resources/pod_inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,11 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter

if k8sutil.IsPodReady(pod) && k8sutil.AreContainersReady(pod, coreContainers) {
// Pod is now ready
if anyOf(memberStatus.Conditions.Update(api.ConditionTypeReady, true, "Pod Ready", ""),
if util.Or(
memberStatus.Conditions.Update(api.ConditionTypeReady, true, "Pod Ready", ""),
memberStatus.Conditions.Update(api.ConditionTypeStarted, true, "Pod Started", ""),
memberStatus.Conditions.Update(api.ConditionTypeServing, true, "Pod Serving", "")) {
memberStatus.Conditions.Update(api.ConditionTypeServing, true, "Pod Serving", ""),
) {
log.Str("pod-name", pod.GetName()).Debug("Updating member condition Ready, Started & Serving to true")

if status.Topology.IsTopologyOwned(memberStatus.Topology) {
Expand All @@ -363,16 +365,20 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter
}
} else if k8sutil.AreContainersReady(pod, coreContainers) {
// Pod is not ready, but core containers are fine
if anyOf(memberStatus.Conditions.Update(api.ConditionTypeReady, false, "Pod Not Ready", ""),
memberStatus.Conditions.Update(api.ConditionTypeServing, true, "Pod is still serving", "")) {
if util.Or(
memberStatus.Conditions.Update(api.ConditionTypeReady, false, "Pod Not Ready", ""),
memberStatus.Conditions.Update(api.ConditionTypeServing, true, "Pod is still serving", ""),
) {
log.Str("pod-name", pod.GetName()).Debug("Updating member condition Ready to false, while all core containers are ready")
updateMemberStatusNeeded = true
nextInterval = nextInterval.ReduceTo(recheckSoonPodInspectorInterval)
}
} else {
// Pod is not ready
if anyOf(memberStatus.Conditions.Update(api.ConditionTypeReady, false, "Pod Not Ready", ""),
memberStatus.Conditions.Update(api.ConditionTypeServing, false, "Pod Core containers are not ready", strings.Join(coreContainers, ", "))) {
if util.Or(
memberStatus.Conditions.Update(api.ConditionTypeReady, false, "Pod Not Ready", ""),
memberStatus.Conditions.Update(api.ConditionTypeServing, false, "Pod Core containers are not ready", strings.Join(coreContainers, ", ")),
) {
log.Str("pod-name", pod.GetName()).Debug("Updating member condition Ready & Serving to false")
updateMemberStatusNeeded = true
nextInterval = nextInterval.ReduceTo(recheckSoonPodInspectorInterval)
Expand Down Expand Up @@ -566,13 +572,3 @@ func removeLabel(labels map[string]string, key string) map[string]string {

return labels
}

func anyOf(bools ...bool) bool {
for _, b := range bools {
if b {
return true
}
}

return false
}
20 changes: 20 additions & 0 deletions pkg/util/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,23 @@ func CheckConditionalP1Nil[T, P1 interface{}](in ConditionalP1Function[T, P1], p

return nil
}

func Or(in ...bool) bool {
for _, v := range in {
if v {
return true
}
}

return false
}

func And(in ...bool) bool {
for _, v := range in {
if !v {
return false
}
}

return len(in) > 0
}