-
Notifications
You must be signed in to change notification settings - Fork 9
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
Pod termination fault #359
Conversation
83e47f7
to
d369de2
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.
Looking good to me, left minor comments about error messages and style
e2e/disruptors/pod_e2e_test.go
Outdated
@@ -55,22 +57,24 @@ func Test_PodDisruptor(t *testing.T) { | |||
return | |||
} | |||
|
|||
t.Run("Test fault injection", func(t *testing.T) { | |||
t.Run("TProtocol fault injection", func(t *testing.T) { |
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.
Small typo
d.terminatePods(fault) | ||
`, | ||
expectError: true, | ||
}, |
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'd suggest to add a test for an empty fault object as well
}, | |
}, | |
{ | |
description: "Terminate Pods (empty fault)", | |
script: ` | |
d.terminatePods({}) | |
`, | |
expectError: true, | |
}, |
pkg/api/api_test.go
Outdated
{ | ||
description: "Terminate Pods (missing argument)", | ||
script: ` | ||
|
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.
Stray newline
func (d *podDisruptor) Targets(_ context.Context) ([]string, error) { | ||
return utils.PodNames(d.targets), nil |
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.
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'm pretty sure we will need the context to retrieve the list of targets instead of using a pre-stored list, and this process may return an error. I prefer to leave it as it is instead of changing the implementation back and forth.
type PodTerminationFault struct { | ||
// Count indicates how many pods to terminate. Can be a number or a percentage or targets | ||
Count intstr.IntOrString | ||
// Timeout specifies the maximum time to wait for a pod to terminate |
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.
Does this mean that Terminate
will return an error if the pod is still in Terminating
state after this amount of time passes? If so, it might be good to include it in the comment above just for clarity.
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'm putting the comment in the method TerminatePods
as it where the error is returned
pkg/kubernetes/helpers/pods_test.go
Outdated
expectError: false, | ||
}, | ||
{ | ||
title: "pod does not exists", |
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.
Small typo
title: "pod does not exists", | |
title: "pod does not exist", |
pkg/testutils/e2e/deploy/deploy.go
Outdated
@@ -14,7 +15,7 @@ import ( | |||
"k8s.io/apimachinery/pkg/util/intstr" | |||
) | |||
|
|||
// RunPod creates a pod and waits it for be running | |||
// RunPod creates apreplicas pod and waits it for be running |
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.
Seems like a leftover from a previous iteration where RunPod
received a replicas arg.
// The ingress routes request that specify the service's name as host to this service. | ||
func ExposeApp( | ||
k8s kubernetes.Kubernetes, | ||
namespace string, | ||
pod corev1.Pod, | ||
replicas int, |
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 return an error if replicas == 0
? Seems like it could be the source of one of annoying to debug situations where nothing happens but no error is returned.
pkg/utils/kubernetes.go
Outdated
names := []string{} | ||
for _, pod := range pods { | ||
names = append(names, pod.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.
We can probably preallocate the names
slice here. It's not like it's the hot path, but maybe just as a "best practices" approach:
names := []string{} | |
for _, pod := range pods { | |
names = append(names, pod.Name) | |
} | |
names := make([]string, 0, len(pods)) | |
for _, pod := range pods { | |
names = append(names, pod.Name) | |
} |
pkg/utils/kubernetes.go
Outdated
} | ||
|
||
if sampleSize > len(pods) { | ||
return nil, fmt.Errorf("not enough elements to sample") |
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'd suggest to add the numbers in play to the error message so it is easier to trace what's going on from logs:
return nil, fmt.Errorf("not enough elements to sample") | |
return nil, fmt.Errorf("cannot sample %d pods out of a total of %d", sampleSize, len(pods)) |
Signed-off-by: Pablo Chacin <[email protected]>
Signed-off-by: Pablo Chacin <[email protected]>
Signed-off-by: Pablo Chacin <[email protected]>
Signed-off-by: Pablo Chacin <[email protected]>
Signed-off-by: Pablo Chacin <[email protected]>
Signed-off-by: Pablo Chacin <[email protected]>
Signed-off-by: Pablo Chacin <[email protected]>
Signed-off-by: Pablo Chacin <[email protected]>
3a0d652
to
e38a6db
Compare
Description
Introduces the Terminate pod fault.
Documentation: grafana/k6-docs#1381
Checklist:
make lint
) and all checks pass.make test
) and all tests pass.make integration-xxx
for affected packages)make e2e-xxx
fordisruptors
, orcluster
related changes)