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

Add container kill chaos #203

Merged
merged 43 commits into from
Feb 14, 2020
Merged

Add container kill chaos #203

merged 43 commits into from
Feb 14, 2020

Conversation

fewdan
Copy link
Member

@fewdan fewdan commented Feb 7, 2020

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

  • No code

Code changes

  • Has Go code change

Side effects

  • No

Related changes

  • Need to update the documentation

Does this PR introduce a user-facing change?:

NONE

@fewdan fewdan changed the title Temp20200207 add container kill Feb 7, 2020
@zhouqiang-cl zhouqiang-cl changed the title add container kill [WIP] add container kill Feb 7, 2020
@zhouqiang-cl zhouqiang-cl linked an issue Feb 7, 2020 that may be closed by this pull request
"errors"
"fmt"

v1 "k8s.io/api/core/v1"
Copy link
Contributor

Choose a reason for hiding this comment

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

please group import

Copy link
Member Author

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.

Copy link
Contributor

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"

Copy link
Member Author

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) {
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@fewdan PTAL

Copy link
Contributor

@zhouqiang-cl zhouqiang-cl left a comment

Choose a reason for hiding this comment

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

rest LGTM

@codecov-io
Copy link

codecov-io commented Feb 7, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@91dbba8). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 91dbba8...06c3ab4. Read the comment docs.


func (r *Reconciler) KillContainer(ctx context.Context, pod *v1.Pod, containerID string) error {

r.Log.Info("try to kill container")
Copy link
Contributor

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

Copy link
Member Author

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.

controllers/podchaos/containerkill/types.go Outdated Show resolved Hide resolved
controllers/podchaos/containerkill/types.go Outdated Show resolved Hide resolved
pkg/chaosdaemon/container-kill.go Outdated Show resolved Hide resolved
pkg/chaosdaemon/util.go Outdated Show resolved Hide resolved
return err
}

err = container.Delete(ctx)
Copy link
Contributor

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;
}
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Member

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

I agree with your option, @fewdan you can add a field to represent the chaos action.

@zhouqiang-cl zhouqiang-cl changed the title [WIP] add container kill add container kill Feb 8, 2020
@zhouqiang-cl
Copy link
Contributor

@fewdan PTAL

Copy link
Contributor

@zhouqiang-cl zhouqiang-cl left a comment

Choose a reason for hiding this comment

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

Maybe we also need support duration kill? @Yisaer @cwen0

@@ -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
Copy link
Contributor

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..."

Copy link
Member Author

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"
Copy link
Contributor

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"

controllers/podchaos/containerkill/types.go Outdated Show resolved Hide resolved
manifests/crd.yaml Outdated Show resolved Hide resolved
@@ -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
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

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")
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

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.

@zhouqiang-cl
Copy link
Contributor

@fewdan could you please fix ci

@zhouqiang-cl
Copy link
Contributor

@fewdan we should also add doc, it can be another pr

mahjonp
mahjonp previously approved these changes Feb 13, 2020
mahjonp
mahjonp previously approved these changes Feb 14, 2020
containerID := pod.Status.ContainerStatuses[containerIndex].ContainerID

if containerName == podchaos.Spec.ContainerName {
haveSelected = true
Copy link
Member

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) {
Copy link

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 {
Copy link

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

Copy link
Contributor

@zhouqiang-cl zhouqiang-cl left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@cwen0 cwen0 left a comment

Choose a reason for hiding this comment

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

LGTM

@cwen0 cwen0 merged commit cdb9c61 into chaos-mesh:master Feb 14, 2020
@zhouqiang-cl zhouqiang-cl changed the title add container kill Add container kill chaos Feb 14, 2020
@fewdan fewdan deleted the temp20200207 branch February 17, 2020 07:03
@dcalvin dcalvin mentioned this pull request Feb 5, 2021
sjwsl pushed a commit to sjwsl/chaos-mesh that referenced this pull request May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add container kill
10 participants