...
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package podkill
15
16 import (
17 "context"
18
19 v1 "k8s.io/api/core/v1"
20 "sigs.k8s.io/controller-runtime/pkg/client"
21
22 "github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
23 "github.com/chaos-mesh/chaos-mesh/controllers/utils/controller"
24 )
25
26 type Impl struct {
27 client.Client
28 }
29
30 func (impl *Impl) Apply(ctx context.Context, index int, records []*v1alpha1.Record, obj v1alpha1.InnerObject) (v1alpha1.Phase, error) {
31 podchaos := obj.(*v1alpha1.PodChaos)
32
33 var pod v1.Pod
34 err := impl.Get(ctx, controller.ParseNamespacedName(records[index].Id), &pod)
35 if err != nil {
36
37 return v1alpha1.NotInjected, err
38 }
39
40 err = impl.Delete(ctx, &pod, &client.DeleteOptions{
41 GracePeriodSeconds: &podchaos.Spec.GracePeriod,
42 })
43 if err != nil {
44
45 return v1alpha1.NotInjected, err
46 }
47
48 return v1alpha1.Injected, nil
49 }
50
51 func (impl *Impl) Recover(ctx context.Context, index int, records []*v1alpha1.Record, obj v1alpha1.InnerObject) (v1alpha1.Phase, error) {
52 return v1alpha1.NotInjected, nil
53 }
54
55 func NewImpl(c client.Client) *Impl {
56 return &Impl{
57 Client: c,
58 }
59 }
60