Skip to content

Commit

Permalink
Support reorder in network delay chaos (chaos-mesh#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
yeya24 authored Mar 2, 2020
1 parent 5e0bac0 commit 0797de5
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 13 deletions.
40 changes: 33 additions & 7 deletions api/v1alpha1/networkchaos_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
// DelayAction represents the chaos action of adding delay on pods.
DelayAction NetworkChaosAction = "delay"

// LossAction represents the chaos action of lossing packets on pods.
// LossAction represents the chaos action of losing packets on pods.
LossAction NetworkChaosAction = "loss"

// DuplicateAction represents the chaos action of duplicating packets on pods.
Expand Down Expand Up @@ -126,7 +126,7 @@ type NetworkChaosSpec struct {
// DuplicateSpec represents the detail about loss action
Duplicate *DuplicateSpec `json:"duplicate,omitempty"`

// Corrupt represents the detail about loss action
// Corrupt represents the detail about corrupt action
Corrupt *CorruptSpec `json:"corrupt,omitempty"`

// Direction represents the partition direction
Expand Down Expand Up @@ -256,9 +256,10 @@ func (in *NetworkChaos) Validate() (bool, string, error) {

// DelaySpec defines detail of a delay action
type DelaySpec struct {
Latency string `json:"latency"`
Correlation string `json:"correlation"`
Jitter string `json:"jitter"`
Latency string `json:"latency"`
Correlation string `json:"correlation"`
Jitter string `json:"jitter"`
Reorder *ReorderSpec `json:"reorder,omitempty"`
}

func (delay *DelaySpec) ToNetem() (*chaosdaemon.Netem, error) {
Expand All @@ -276,11 +277,29 @@ func (delay *DelaySpec) ToNetem() (*chaosdaemon.Netem, error) {
return nil, err
}

return &chaosdaemon.Netem{
netem := &chaosdaemon.Netem{
Time: uint32(delayTime.Nanoseconds() / 1e3),
DelayCorr: float32(corr),
Jitter: uint32(jitter.Nanoseconds() / 1e3),
}, nil
}

if delay.Reorder != nil {
reorderPercentage, err := strconv.ParseFloat(delay.Reorder.Reorder, 32)
if err != nil {
return nil, err
}

corr, err := strconv.ParseFloat(delay.Reorder.Correlation, 32)
if err != nil {
return nil, err
}

netem.Reorder = float32(reorderPercentage)
netem.ReorderCorr = float32(corr)
netem.Gap = uint32(delay.Reorder.Gap)
}

return netem, nil
}

// LossSpec defines detail of a loss action
Expand Down Expand Up @@ -352,6 +371,13 @@ func (corrupt *CorruptSpec) ToNetem() (*chaosdaemon.Netem, error) {
}, nil
}

// ReorderSpec defines details of packet reorder.
type ReorderSpec struct {
Reorder string `json:"reorder"`
Correlation string `json:"correlation"`
Gap int `json:"gap"`
}

// +kubebuilder:object:root=true

// NetworkChaosList contains a list of NetworkChaos
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/podchaos_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ type PodChaosSpec struct {
Scheduler *SchedulerSpec `json:"scheduler,omitempty"`

// Action defines the specific pod chaos action.
// Supported action: pod-kill / pod-failure
// Supported action: pod-kill / pod-failure / container-kill
// Default action: pod-kill
Action PodChaosAction `json:"action"`

Expand Down
22 changes: 21 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion config/crd/bases/pingcap.com_networkchaos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ spec:
action: delay Default action: delay'
type: string
corrupt:
description: Corrupt represents the detail about loss action
description: Corrupt represents the detail about corrupt action
properties:
correlation:
type: string
Expand All @@ -58,6 +58,20 @@ spec:
type: string
latency:
type: string
reorder:
description: ReorderSpec defines details of packet reorder.
properties:
correlation:
type: string
gap:
type: integer
reorder:
type: string
required:
- correlation
- gap
- reorder
type: object
required:
- correlation
- jitter
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/pingcap.com_podchaos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ spec:
properties:
action:
description: 'Action defines the specific pod chaos action. Supported
action: pod-kill / pod-failure Default action: pod-kill'
action: pod-kill / pod-failure / container-kill Default action: pod-kill'
type: string
containerName:
description: ContainerName indicates the name of the container. Needed
Expand Down
18 changes: 16 additions & 2 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ spec:
action: delay Default action: delay'
type: string
corrupt:
description: Corrupt represents the detail about loss action
description: Corrupt represents the detail about corrupt action
properties:
correlation:
type: string
Expand All @@ -305,6 +305,20 @@ spec:
type: string
latency:
type: string
reorder:
description: ReorderSpec defines details of packet reorder.
properties:
correlation:
type: string
gap:
type: integer
reorder:
type: string
required:
- correlation
- gap
- reorder
type: object
required:
- correlation
- jitter
Expand Down Expand Up @@ -615,7 +629,7 @@ spec:
properties:
action:
description: 'Action defines the specific pod chaos action. Supported
action: pod-kill / pod-failure Default action: pod-kill'
action: pod-kill / pod-failure / container-kill Default action: pod-kill'
type: string
containerName:
description: ContainerName indicates the name of the container. Needed
Expand Down

0 comments on commit 0797de5

Please sign in to comment.