8000 [Improvement] Extract api.Condition Or function (#1544) · arangodb/kube-arangodb@607dd1b · GitHub
[go: up one dir, main page]

Skip to content

Commit 607dd1b

Browse files
authored
[Improvement] Extract api.Condition Or function (#1544)
1 parent 18133de commit 607dd1b

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

pkg/deployment/resources/pod_inspector.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,11 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter
339339

340340
if k8sutil.IsPodReady(pod) && k8sutil.AreContainersReady(pod, coreContainers) {
341341
// Pod is now ready
342-
if anyOf(memberStatus.Conditions.Update(api.ConditionTypeReady, true, "Pod Ready", ""),
342+
if util.Or(
343+
memberStatus.Conditions.Update(api.ConditionTypeReady, true, "Pod Ready", ""),
343344
memberStatus.Conditions.Update(api.ConditionTypeStarted, true, "Pod Started", ""),
344-
memberStatus.Conditions.Update(api.ConditionTypeServing, true, "Pod Serving", "")) {
345+
memberStatus.Conditions.Update(api.ConditionTypeServing, true, "Pod Serving", ""),
346+
) {
345347
log.Str("pod-name", pod.GetName()).Debug("Updating member condition Ready, Started & Serving to true")
346348

347349
if status.Topology.IsTopologyOwned(memberStatus.Topology) {
@@ -363,16 +365,20 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter
363365
}
364366
} else if k8sutil.AreContainersReady(pod, coreContainers) {
365367
// Pod is not ready, but core containers are fine
366-
if anyOf(memberStatus.Conditions.Update(api.ConditionTypeReady, false, "Pod Not Ready", ""),
367-
memberStatus.Conditions.Update(api.ConditionTypeServing, true, "Pod is still serving", "")) {
368+
if util.Or(
369+
memberStatus.Conditions.Update(api.ConditionTypeReady, false, "Pod Not Ready", ""),
370+
memberStatus.Conditions.Update(api.ConditionTypeServing, true, "Pod is still serving", ""),
371+
) {
368372
log.Str("pod-name", pod.GetName()).Debug("Updating member condition Ready to false, while all core containers are ready")
369373
updateMemberStatusNeeded = true
370374
nextInterval = nextInterval.ReduceTo(recheckSoonPodInspectorInterval)
371375
}
372376
} else {
373377
// Pod is not ready
374-
if anyOf(memberStatus.Conditions.Update(api.ConditionTypeReady, false, "Pod Not Ready", ""),
375-
memberStatus.Conditions.Update(api.ConditionTypeServing, false, "Pod Core containers are not ready", strings.Join(coreContainers, ", "))) {
378+
if util.Or(
379+
memberStatus.Conditions.Update(api.ConditionTypeReady, false, "Pod Not Ready", ""),
380+
memberStatus.Conditions.Update(api.ConditionTypeServing, false, "Pod Core containers are not ready", strings.Join(coreContainers, ", ")),
381+
) {
376382
log.Str("pod-name", pod.GetName()).Debug("Updating member condition Ready & Serving to false")
377383
updateMemberStatusNeeded = true
378384
nextInterval = nextInterval.ReduceTo(recheckSoonPodInspectorInterval)
@@ -566,13 +572,3 @@ func removeLabel(labels map[string]string, key string) map[string]string {
566572

567573
return labels
568574
}
569-
570-
func anyOf(bools ...bool) bool {
571-
for _, b := range bools {
572-
if b {
573-
return true
574-
}
575-
}
576-
577-
return false
578-
}

pkg/util/refs.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,23 @@ func CheckConditionalP1Nil[T, P1 interface{}](in ConditionalP1Function[T, P1], p
105105

106106
return nil
107107
}
108+
109+
func Or(in ...bool) bool {
110+
for _, v := range in {
111+
if v {
112+
return true
113+
}
114+
}
115+
116+
return false
117+
}
118+
119+
func And(in ...bool) bool {
120+
for _, v := range in {
121+
if !v {
122+
return false
123+
}
124+
}
125+
126+
return len(in) > 0
127+
}

0 commit comments

Comments
 (0)
0