Skip to content

Commit

Permalink
refactor: Reducing complexity of some parts
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Feb 15, 2023
1 parent 8f12f0a commit c7a7e12
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
19 changes: 6 additions & 13 deletions cmd/log_color.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,21 @@ func moveDecoderToKey(decoder *json.Decoder, keys ...string) error {
return fmt.Errorf("decode token: %w", err)
}

if nested == 1 {
tokenStr := fmt.Sprintf("%s", token)
var found bool
tokenStr := fmt.Sprintf("%s", token)

if nested == 1 {
for _, key := range keys {
if strings.EqualFold(tokenStr, key) {
found = true
break
return nil
}
}

if found {
break
}
}

if strToken := fmt.Sprintf("%s", token); strToken == "{" {
switch tokenStr {
case "{":
nested++
} else if strToken == "}" {
case "}":
nested--
}
}

return nil
}
29 changes: 18 additions & 11 deletions cmd/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,22 +381,29 @@ func getPodWide(pod v1.Pod) (string, string, string, string) {

readinessGates := noneValue
if len(pod.Spec.ReadinessGates) > 0 {
trueConditions := 0
for _, readinessGate := range pod.Spec.ReadinessGates {
conditionType := readinessGate.ConditionType
for _, condition := range pod.Status.Conditions {
if condition.Type == conditionType {
if condition.Status == v1.ConditionTrue {
trueConditions++
}
break
readinessGates = fmt.Sprintf("%d/%d", getTrueReadyConditions(pod.Spec.ReadinessGates, pod.Status.Conditions), len(pod.Spec.ReadinessGates))
}

return podIP, nodeName, nominatedNodeName, readinessGates
}

func getTrueReadyConditions(gates []v1.PodReadinessGate, conditions []v1.PodCondition) uint {
var output uint

for _, readinessGate := range gates {
conditionType := readinessGate.ConditionType

for _, condition := range conditions {
if condition.Type == conditionType {
if condition.Status == v1.ConditionTrue {
output++
}
break
}
}
readinessGates = fmt.Sprintf("%d/%d", trueConditions, len(pod.Spec.ReadinessGates))
}

return podIP, nodeName, nominatedNodeName, readinessGates
return output
}

func hasPodReadyCondition(conditions []v1.PodCondition) bool {
Expand Down

0 comments on commit c7a7e12

Please sign in to comment.