-
Notifications
You must be signed in to change notification settings - Fork 94
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@diamonwiggins that is great. Could we try to return only one result when pods are Healthy instead of a list with all Healthy pods on the cluster? Could we just return the list of those that are unhealthy?
I think that's a good idea. Do you think we need to cover that here on this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return many times the same success result seems a bug out of scope of this PR. See: #1089
I think would be nice it has tests but I am so happy with the fix already.
Thank you 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Terrific work 🥇 I added only one nit.
IF possible would be great have the mocks under a directory called testdata to follow the best practices with Golang to keep those. Otherwise, it has my LGTM
@@ -0,0 +1,263 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add it inside of a directory called testdata?
Why Golang has a particular meaning for those and for we add mock data that is the best approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Specifically https://github.com/replicatedhq/troubleshoot/tree/main/testdata
[evans] $ go help test | grep -A1 testdata
The go tool will ignore a directory named "testdata", making it available
to hold ancillary data needed by the tests.
But it can be done in a separate PR. There are many other test data files in the current directory used
Looking at other status analysers (Deployment, StatefulSet...), it looks like the intention is to show the analysis of each resource. I however see your concern here @camilamacedo86. We can improve how these analysis results are reported back by adding a title to each outcome like so. There is a bug (#1093) that needs to be fixed first before this is possible analyzers:
- clusterPodStatuses:
checkName: "Pod(s) health status(es)"
outcomes:
- fail:
title: "Pod {{ .Name }} is unable to pull images"
when: "== ImagePullBackOff"
message: "A Pod, {{ .Name }}, is unable to pull its image. Status is: {{ .Status.Reason }}"
- warn:
title: "Pod {{ .Name }} is unhealthy"
when: "!= Healthy"
message: "A Pod, {{ .Name }}, is unhealthy with a status of: {{ .Status.Reason }}. Restarting the pod may fix the issue."
- pass:
title: "Pod {{ .Name }} is healthy"
message: "Pod {{ .Name }} is healthy" This would render results like below |
@camilamacedo86 I think if we ignore the |
@@ -0,0 +1,266 @@ | |||
package analyzer | |||
|
|||
import ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff with the tests!
Nit pick: Could you add/modify tests to use !==
, ==
, ===
and =
conditionals for completeness? e.g === CrashLoopBackOff
pkg/analyze/cluster_pod_statuses.go
Outdated
if when != "" { | ||
parts := strings.Split(strings.TrimSpace(when), " ") | ||
if len(parts) < 2 { | ||
println(fmt.Sprintf("invalid 'when' format: %s\n", when)) // don't stop |
There was a problem hiding this comment.
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
…eplicatedhq/troubleshoot into diamonwiggins/fix-cluster-pod-analyzer
bb1257a
Description, Motivation and Context
Currently the
when
conditional for theclusterPodStatuses
analyzer is expected for all outcome types and if not specified the following behavior is seen using the following spec:Because
when
isn't set forpass
you see the above errors. With the changes in this PR,when
is optional and the expected pattern of having a default outcome at the end of your outcome list is supported.Fixes: #1087
Checklist
Does this PR introduce a breaking change?