-
Notifications
You must be signed in to change notification settings - Fork 850
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
Add container kill chaos #203
Conversation
"errors" | ||
"fmt" | ||
|
||
v1 "k8s.io/api/core/v1" |
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.
please group 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.
The result after I executed "goimports -w -l -local github.com/pingcap/chaos-mesh ./" is like this. Maybe I can adjust it manually. But "goimports" in "makefile" will change back.
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.
Goimports only groups and formats imported packages in the same group. Each group is a continous packages which is not seperated with Enter
. You could group it with ctrl "sigs.k8s.io/controller-runtime"
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.
thx. I have edited it.
Log logr.Logger | ||
} | ||
|
||
func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, 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.
Can you split this function, it is too long
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.
@fewdan PTAL
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.
rest LGTM
Codecov Report
@@ Coverage Diff @@
## master #203 +/- ##
=========================================
Coverage ? 43.64%
=========================================
Files ? 18
Lines ? 685
Branches ? 0
=========================================
Hits ? 299
Misses ? 353
Partials ? 33 Continue to review full report at Codecov.
|
|
||
func (r *Reconciler) KillContainer(ctx context.Context, pod *v1.Pod, containerID string) error { | ||
|
||
r.Log.Info("try to kill container") |
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.
Is it better to add more info to this log? Maybe we can also show some info about the pod and container here. Just my personal thought
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 have added "pod.Namespace", "pod.Name" and containerID.
pkg/chaosdaemon/util.go
Outdated
return err | ||
} | ||
|
||
err = container.Delete(ctx) |
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 maybe we need to add the deleteOption containerd.WithSnapshotCleanup
here. I am not familiar with containerd, but I check the implementation in container cri and ctr, they all have this option. I am not sure whether this is needed.
Also, I am not sure whether this is equivalent with sending SIGKILL
to that container or not? There is already an implementation to do kill to the task, check here
} | ||
|
||
message ContainerRequest{ | ||
string container_id = 1; | ||
} |
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.
Any design for this RPC request? For future scalability, I think kill
is just one type of action to containers. So maybe we can add a field like type
or action
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. I think maybe other signal can be set in type
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.
But this is ok currently. We can leave that change to future 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.
Any design for this RPC request? For future scalability, I think
kill
is just one type of action to containers. So maybe we can add a field liketype
oraction
I agree with your option, @fewdan you can add a field to represent the chaos action.
@fewdan PTAL |
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.
@@ -38,6 +38,9 @@ spec: | |||
description: 'Action defines the specific pod chaos action. Supported | |||
action: pod-kill / pod-failure Default action: pod-kill' | |||
type: string | |||
containerName: | |||
description: Needed in container-kill. Indicates the name of the container |
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 you please tweak the description so that it complies with "ContainerName blablabla..."
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 changed the order. PTAL
"errors" | ||
"fmt" | ||
|
||
v1 "k8s.io/api/core/v1" |
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.
Goimports only groups and formats imported packages in the same group. Each group is a continous packages which is not seperated with Enter
. You could group it with ctrl "sigs.k8s.io/controller-runtime"
@@ -40,6 +41,7 @@ const ( | |||
// ContainerRuntimeInfoClient represents a struct which can give you information about container runtime | |||
type ContainerRuntimeInfoClient interface { | |||
GetPidFromContainerID(ctx context.Context, containerID string) (uint32, error) | |||
ContainerKillByContainerID(ctx context.Context, containerID 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.
Actually I am still not sure about the naming. I think both GetPidFromContainerID
and ContainerKillByContainerID
is quite redundant. It is okay to just use GetPid
and KillContainer
. WDYT @fewdan @zhouqiang-cl
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 not sure if there are other ways in the future, such as not based on "ID" but on "image" and the like. So I think we can name it longer now.
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.
Sure. That makes sense 😄
podchaos.Status.Experiment.Pods = append(podchaos.Status.Experiment.Pods, ps) | ||
} | ||
if err := r.Update(ctx, &podchaos); err != nil { | ||
r.Log.Error(err, "unable to update chaosctl status") |
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.
Hmm, may I ask what does this chaosctl
mean
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.
Actually, I see this "log msg" appear multiple times in the project. So this is consistent with other places.
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.
It is not clear enough to users.
@fewdan could you please fix ci |
@fewdan we should also add doc, it can be another pr |
containerID := pod.Status.ContainerStatuses[containerIndex].ContainerID | ||
|
||
if containerName == podchaos.Spec.ContainerName { | ||
haveSelected = 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 think haveSelected
is unnecessary, because If the only one from all selected pod met this name, we will think all pod meets the name.
Log logr.Logger | ||
} | ||
|
||
func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, 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.
exported method Reconciler.Reconcile should have comment or be unexported
containerKillActionMsg = "delete container %s" | ||
) | ||
|
||
type Reconciler struct { |
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.
exported type Reconciler should have comment or be unexported
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.
LGTM
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.
LGTM
What problem does this PR solve?
Add container kill
What is changed and how does it work?
Using client in chaos-daemon to achieve container-kill
Check List
Tests
Code changes
Side effects
Related changes
Does this PR introduce a user-facing change?: