-
Notifications
You must be signed in to change notification settings - Fork 88
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
Assessment runner refactors #2123
Assessment runner refactors #2123
Conversation
41d51c4
to
024978b
Compare
return podErr | ||
} | ||
|
||
t.Logf("podEvents: %+v\n", podEventsDescriptions) |
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.
Hi @stevenhorsman !
What does the "+" in "+v" do? I vaguely remember I had to remove it to print the string correctly, I just don't remember where.
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.
The %+v
includes the field names of the struct. In this case it's a string IIRC, so I should just switch to %s
instead. I think the %+v
was from an earlier version. Sorry about that.
|
||
t.Logf("podEvents: %+v\n", podEventsDescriptions) | ||
if !strings.Contains(podEventsDescriptions, expectedPodEventDescribe) { | ||
err = fmt.Errorf("error: Pod Descriptions don't contain Expected String %s", expectedPodEventDescribe) |
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.
Nit: s/Pod Descriptions/Pod Events/
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.
Thanks - I usually think of the pod events in the context of kubectl describe
, so my inconsistencies leak in.
pods, err := GetPodNamesByLabel(ctx, client, t, caaPod.GetObjectMeta().GetNamespace(), "app", "cloud-api-adaptor") | ||
if err != nil { | ||
return nil, fmt.Errorf("getCaaPod: GetPodNamesByLabel failed: %v", err) | ||
} | ||
caaPod.Name = pods.Items[0].Name |
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.
should we assert that it's exactly 1 pod? (sometimes there's e.g. a crashed pod in "Terminating" State and another one in "Creating")
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.
Yes definitely. I will add that in. Thanks for the suggestion.
024978b
to
30a7d81
Compare
return descriptionsBuilder.String(), nil | ||
} | ||
|
||
func ComparePodEventWarningDescriptions(ctx context.Context, t *testing.T, client klient.Client, pod v1.Pod, expectedPodEvent string) error { |
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.
Suggestion: document the function so users understand the logic easily. You did it very well on the commit message, btw.
if err != nil { | ||
return false, err | ||
} | ||
caaPod.Name = pods.Items[0].Name |
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.
The nodeName
parameter is not longer used (can be removed) and first caa pod is picked up. Is there a bad consequence if running the test on multiple-workers type of cluster?
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.
That's an interesting point. I think we need to pass the nodeName into the CAA pod so we can check we are getting the correct one. Let me try that
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.
Ok, I've added 69e05f0 which I hope addresses your concern?
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.
I think it does address. thanks @stevenhorsman !
We have some repeated patterns of looking through list of pods to find the one matching our expected name and then extracting some information from it. Rather than repeat this in multiple places we can refactor this pattern out in assessment_helpers and re-use it. Signed-off-by: stevenhorsman <steven@uk.ibm.com>
I used the `PodEventExtractor` method to compare against an expected error message, but didn't realise at the time that it just watched for the first warning message and returned that. We then use this output in `assessment_runner` to see if our expected error description is there. Note: As we use it in the `Assess` phase of testing and the pod should be in the expected state after the `WithSetup`, we should be able to replace the need for the watch and just get a list of the events - Rename to clarify that only warning (and error) events are considered and create a `ComparePodEventDescriptions` method in `assessment_helper` to help simplify the logic in `assessment_runner` and process all warning events looking for a description match, not just the first match. If no error was expected then mark the test as failing. - In some of the tests that expect failure events, as we are no longer watching for the first error, we should wait for pod to have gone into failed state before processing the events, in others we add a retry to check for the message. Based on the above logic we can simplify the instance type testing Signed-off-by: stevenhorsman <steven@uk.ibm.com>
Refactor out the instance type check to the assessment_helper, to make the assessment_runner flow easier to read Signed-off-by: stevenhorsman <steven@uk.ibm.com>
Refactor out the logic that checks the alternativeImage is used to make the assessment_runner flow cleaner Signed-off-by: stevenhorsman <steven@uk.ibm.com>
- Refactor out the logic that checks if nydus snapshotter was used for image pull, to make the assessment_runner flow cleaner. - Refactor IsPulledWithNydusSnapshotter to use remove the duplicated code and re-use other helper functions Signed-off-by: stevenhorsman <steven@uk.ibm.com>
Create new methods for VerifyCaaPodLogContains and getCaaPod to avoid duplication and improve readability. Signed-off-by: stevenhorsman <steven@uk.ibm.com>
No tests are using the `WithFailReason` option, so remove the code to reduce clutter Signed-off-by: stevenhorsman <steven@uk.ibm.com>
The [Go Wiki]|(https://go.dev/wiki/TestComments) states > On a practical level, prefer calling t.Error over t.Fatal. > t.Fatal is usually only appropriate when some piece > of test setup fails, without which you cannot run the > test at all. - Update t.Fatal's in assess methods to t.Error's - Pass pointers to pods rather than the Pod, like the Kubernetes e2e pod base does Signed-off-by: stevenhorsman <steven@uk.ibm.com>
Refactor out the logic that checks if the image pull timing, to make the assessment_runner flow cleaner. Signed-off-by: stevenhorsman <steven@uk.ibm.com>
After confidential-containers#2121 the rust version is no longer needed Signed-off-by: stevenhorsman <steven@uk.ibm.com>
30a7d81
to
e1767d2
Compare
As Wainer pointed out in the review, if we ran the e2e tests on a cluster with multiple worker nodes, then our logic for only checking for a single CAA pod might fail, so add an additional nodeName filter, so get the CAA that is running on the same node as the pod. Signed-off-by: stevenhorsman <steven@uk.ibm.com>
d701c6e
to
69e05f0
Compare
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.
Hey @stevenhorsman ! Great refactoring, the code is much nicer to read indeed!
Various refactors to the assessment helper and assessment runner to try and abstract out complexity of the large runner Assess section, to make it easier to read and reduce duplication