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

fix/clusterPodStatuses: only process when conditional if specified #1088

Merged
merged 6 commits into from
Apr 6, 2023
Merged
49 changes: 26 additions & 23 deletions pkg/analyze/cluster_pod_statuses.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,33 +104,36 @@ func clusterPodStatuses(analyzer *troubleshootv1beta2.ClusterPodStatuses, getChi
continue
}

parts := strings.Split(strings.TrimSpace(when), " ")
if len(parts) < 2 {
println(fmt.Sprintf("invalid 'when' format: %s\n", when)) // don't stop
continue
}

operator := parts[0]
reason := parts[1]
operator := ""
reason := ""
match := false

switch operator {
case "=", "==", "===":
if reason == "Healthy" {
match = !k8sutil.IsPodUnhealthy(&pod)
} else {
match = reason == string(pod.Status.Phase) || reason == string(pod.Status.Reason)
if when != "" {
parts := strings.Split(strings.TrimSpace(when), " ")
if len(parts) < 2 {
println(fmt.Sprintf("invalid 'when' format: %s\n", when)) // don't stop
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whilst here, shall we use klog.Errorf instead? There is another println somewhere in the file

continue
}
case "!=", "!==":
if reason == "Healthy" {
match = k8sutil.IsPodUnhealthy(&pod)
} else {
match = reason != string(pod.Status.Phase) && reason != string(pod.Status.Reason)
operator = parts[0]
reason = parts[1]

switch operator {
case "=", "==", "===":
if reason == "Healthy" {
match = !k8sutil.IsPodUnhealthy(&pod)
} else {
match = reason == string(pod.Status.Phase) || reason == string(pod.Status.Reason)
}
case "!=", "!==":
if reason == "Healthy" {
match = k8sutil.IsPodUnhealthy(&pod)
} else {
match = reason != string(pod.Status.Phase) && reason != string(pod.Status.Reason)
}
}
}

if !match {
continue
if !match {
continue
}
}

r.InvolvedObject = &corev1.ObjectReference{
Expand Down