@@ -19,7 +19,14 @@ package container
19
19
import (
20
20
"fmt"
21
21
criexec "github.com/chaosblade-io/chaosblade-exec-cri/exec"
22
- "github.com/chaosblade-io/chaosblade-exec-os/exec"
22
+ "github.com/chaosblade-io/chaosblade-exec-os/exec/cpu"
23
+ "github.com/chaosblade-io/chaosblade-exec-os/exec/disk"
24
+ "github.com/chaosblade-io/chaosblade-exec-os/exec/file"
25
+ "github.com/chaosblade-io/chaosblade-exec-os/exec/mem"
26
+ "github.com/chaosblade-io/chaosblade-exec-os/exec/network"
27
+ "github.com/chaosblade-io/chaosblade-exec-os/exec/network/tc"
28
+ "github.com/chaosblade-io/chaosblade-exec-os/exec/process"
29
+ "github.com/chaosblade-io/chaosblade-exec-os/exec/script"
23
30
"github.com/chaosblade-io/chaosblade-spec-go/spec"
24
31
"strings"
25
32
@@ -37,15 +44,21 @@ func NewResourceModelSpec(client *channel.Client) model.ResourceExpModelSpec {
37
44
model .NewBaseResourceExpModelSpec ("container" , client ),
38
45
}
39
46
40
- osSubExpModelSpecs := model .NewOSSubResourceModelSpec ().ExpModels ()
41
47
containerSelfModelSpec := criexec .NewContainerCommandSpec ()
42
48
javaExpModelSpecs := getJvmModels ()
43
49
44
50
subExpModelCommandSpecs := make ([]spec.ExpModelCommandSpec , 0 )
45
51
subExpModelCommandSpecs = append (subExpModelCommandSpecs , containerSelfModelSpec )
46
- subExpModelCommandSpecs = append (append (subExpModelCommandSpecs , osSubExpModelSpecs ... ), javaExpModelSpecs ... )
52
+ subExpModelCommandSpecs = append (subExpModelCommandSpecs , javaExpModelSpecs ... )
53
+
47
54
spec .AddExecutorToModelSpec (& model.ExecCommandInPodExecutor {Client : client }, subExpModelCommandSpecs ... )
48
55
56
+ // nsexec
57
+ osSubExpModelSpecs := model .NewOSSubResourceModelSpec ().ExpModels ()
58
+ spec .AddExecutorToModelSpec (& model.CommonExecutor {Client : client }, osSubExpModelSpecs ... )
59
+
60
+ subExpModelCommandSpecs = append (subExpModelCommandSpecs , osSubExpModelSpecs ... )
61
+
49
62
spec .AddFlagsToModelSpec (getResourceFlags , subExpModelCommandSpecs ... )
50
63
resourceModelSpec .RegisterExpModels (subExpModelCommandSpecs ... )
51
64
addActionExamples (resourceModelSpec )
@@ -58,7 +71,7 @@ func addActionExamples(modelSpec *ResourceModelSpec) {
58
71
for _ , action := range expModelSpec .Actions () {
59
72
v := interface {}(action )
60
73
switch v .(type ) {
61
- case * exec .KillProcessActionCommandSpec :
74
+ case * process .KillProcessActionCommandSpec :
62
75
action .SetLongDesc ("The process scenario in container is the same as the basic resource process scenario" )
63
76
action .SetExample (
64
77
`
@@ -69,7 +82,7 @@ blade create k8s container-process kill --process nginx --names nginx-app --cont
69
82
# Specifies the signal and local port to kill the process in the container
70
83
blade create k8s container-process kill --local-port 8080 --signal 15 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default` )
71
84
72
- case * exec .StopProcessActionCommandSpec :
85
+ case * process .StopProcessActionCommandSpec :
73
86
action .SetLongDesc ("The process scenario in container is the same as the basic resource process scenario" )
74
87
action .SetExample (
75
88
`
@@ -79,7 +92,7 @@ blade create k8s container-process stop --process nginx --names nginx-app --cont
79
92
# Pause the Java process in the container
80
93
blade create k8s container-process stop --process-cmd java --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default` )
81
94
82
- case * exec .FullLoadActionCommand :
95
+ case * cpu .FullLoadActionCommand :
83
96
action .SetLongDesc ("The CPU load experiment scenario in container is the same as the CPU scenario of basic resources" )
84
97
action .SetExample (
85
98
`
@@ -98,7 +111,7 @@ blade create k8s container-cpu load --cpu-list 1-3 --names nginx-app --container
98
111
# Specified percentage load in the container
99
112
blade create k8s container-cpu load --cpu-percent 60 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default` )
100
113
101
- case * exec .FillActionSpec :
114
+ case * disk .FillActionSpec :
102
115
action .SetLongDesc ("The disk fill scenario experiment in the container" )
103
116
action .SetExample (
104
117
`
@@ -111,7 +124,7 @@ blade create k8s container-disk fill --path /home --percent 80 --retain-handle -
111
124
# Perform a fixed-size experimental scenario in the container
112
125
blade c k8s container-disk fill --path /home --reserve 1024 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
113
126
` )
114
- case * exec .BurnActionSpec :
127
+ case * disk .BurnActionSpec :
115
128
action .SetLongDesc ("Disk read and write IO load experiment in the container" )
116
129
action .SetExample (
117
130
`# The data of rkB/s, wkB/s and % Util were mainly observed. Perform disk read IO high-load scenarios
@@ -123,7 +136,7 @@ blade create k8s container-disk burn --write --path /home --names nginx-app --co
123
136
# Read and write IO load scenarios are performed at the same time. Path is not specified. The default is /
124
137
blade create k8s container-disk burn --read --write --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default` )
125
138
126
- case * exec .MemLoadActionCommand :
139
+ case * mem .MemLoadActionCommand :
127
140
action .SetLongDesc ("The memory fill experiment scenario in container" )
128
141
action .SetExample (
129
142
`# The execution memory footprint is 50%
@@ -140,7 +153,7 @@ blade create k8s container-mem load --mode ram --mem-percent 50 --timeout 200 --
140
153
141
154
# 200M memory is reserved
142
155
blade create k8s container-mem load --mode ram --reserve 200 --rate 100 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default` )
143
- case * exec .FileAppendActionSpec :
156
+ case * file .FileAppendActionSpec :
144
157
action .SetLongDesc ("The file append experiment scenario in container" )
145
158
action .SetExample (
146
159
`# Appends the content "HELLO WORLD" to the /home/logs/nginx.log file
@@ -155,7 +168,7 @@ blade create k8s container-file append --filepath=/home/logs/nginx.log --content
155
168
# mock interface timeout exception
156
169
blade create k8s container-file append --filepath=/home/logs/nginx.log --content="@{DATE:+%Y-%m-%d %H:%M:%S} ERROR invoke getUser timeout [@{RANDOM:100-200}]ms abc mock exception" --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
157
170
` )
158
- case * exec .FileAddActionSpec :
171
+ case * file .FileAddActionSpec :
159
172
action .SetLongDesc ("The file add experiment scenario in container" )
160
173
action .SetExample (
161
174
`# Create a file named nginx.log in the /home directory
@@ -171,12 +184,12 @@ blade create k8s container-file add --filepath /temp/nginx.log --auto-create-dir
171
184
blade create k8s container-file add --directory --filepath /temp/nginx --auto-create-dir --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
172
185
` )
173
186
174
- case * exec .FileChmodActionSpec :
187
+ case * file .FileChmodActionSpec :
175
188
action .SetLongDesc ("The file permission modification scenario in container" )
176
189
action .SetExample (`# Modify /home/logs/nginx.log file permissions to 777
177
190
blade create k8s container-file chmod --filepath /home/logs/nginx.log --mark=777 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
178
191
` )
179
- case * exec .FileDeleteActionSpec :
192
+ case * file .FileDeleteActionSpec :
180
193
action .SetLongDesc ("The file delete scenario in container" )
181
194
action .SetExample (
182
195
`# Delete the file /home/logs/nginx.log
@@ -185,7 +198,7 @@ blade create k8s container-file delete --filepath /home/logs/nginx.log --names n
185
198
# Force delete the file /home/logs/nginx.log unrecoverable
186
199
blade create k8s container-file delete --filepath /home/logs/nginx.log --force --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
187
200
` )
188
- case * exec .FileMoveActionSpec :
201
+ case * file .FileMoveActionSpec :
189
202
action .SetExample ("The file move scenario in container" )
190
203
action .SetExample (`# Move the file /home/logs/nginx.log to /tmp
191
204
blade create k8s container-file delete --filepath /home/logs/nginx.log --target /tmp --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
@@ -196,7 +209,7 @@ blade create k8s container-file delete --filepath /home/logs/nginx.log --target
196
209
# Move the file /home/logs/nginx.log to /temp/ and automatically create directories that don't exist
197
210
blade create k8s container-file delete --filepath /home/logs/nginx.log --target /temp --auto-create-dir --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
198
211
` )
199
- case * exec .DelayActionSpec :
212
+ case * tc .DelayActionSpec :
200
213
action .SetExample (
201
214
`# Access to native 8080 and 8081 ports is delayed by 3 seconds, and the delay time fluctuates by 1 second
202
215
blade create k8s container-network delay --time 3000 --offset 1000 --interface eth0 --local-port 8080,8081 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
@@ -206,15 +219,15 @@ blade create k8s container-network delay --time 3000 --interface eth0 --remote-p
206
219
207
220
# Do a 5 second delay for the entire network card eth0, excluding ports 22 and 8000 to 8080
208
221
blade create k8s container-network delay --time 5000 --interface eth0 --exclude-port 22,8000-8080 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default` )
209
- case * exec .DropActionSpec :
222
+ case * network .DropActionSpec :
210
223
action .SetExample (
211
224
`# Experimental scenario of network shielding
212
225
blade create k8s container-network drop --source-port 80 --network-traffic in --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default` )
213
- case * exec .DnsActionSpec :
226
+ case * network .DnsActionSpec :
214
227
action .SetExample (
215
228
`# The domain name www.baidu.com is not accessible
216
229
blade create k8s container-network dns --domain www.baidu.com --ip 10.0.0.0 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default` )
217
- case * exec .LossActionSpec :
230
+ case * tc .LossActionSpec :
218
231
action .SetExample (`# Access to native 8080 and 8081 ports lost 70% of packets
219
232
blade create k8s container-network loss --percent 70 --interface eth0 --local-port 8080,8081 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
220
233
@@ -226,26 +239,26 @@ blade create k8s container-network loss --percent 60 --interface eth0 --exclude-
226
239
227
240
# Realize the whole network card is not accessible, not accessible time 20 seconds. After executing the following command, the current network is disconnected and restored in 20 seconds. Remember!! Don't forget -timeout parameter
228
241
blade create k8s container-network loss --percent 100 --interface eth0 --timeout 20 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default` )
229
- case * exec .DuplicateActionSpec :
242
+ case * tc .DuplicateActionSpec :
230
243
action .SetExample (`# Specify the network card eth0 and repeat the packet by 10%
231
244
blade create k8s container-network duplicate --percent=10 --interface=eth0 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default` )
232
- case * exec .CorruptActionSpec :
245
+ case * tc .CorruptActionSpec :
233
246
action .SetExample (`# Access to the specified IP request packet is corrupted, 80% of the time
234
247
blade create k8s container-network corrupt --percent 80 --destination-ip 180.101.49.12 --interface eth0 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default` )
235
- case * exec .ReorderActionSpec :
248
+ case * tc .ReorderActionSpec :
236
249
action .SetExample (`# Access the specified IP request packet disorder
237
250
blade create k8s container-network reorder --correlation 80 --percent 50 --gap 2 --time 500 --interface eth0 --destination-ip 180.101.49.12 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default` )
238
- case * exec .OccupyActionSpec :
251
+ case * network .OccupyActionSpec :
239
252
action .SetExample (`#Specify port 8080 occupancy
240
253
blade create k8s container-network occupy --port 8080 --force --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
241
254
242
255
# The machine accesses external 14.215.177.39 machine (ping www.baidu.com) 80 port packet loss rate 100%
243
256
blade create k8s container-network loss --percent 100 --interface eth0 --remote-port 80 --destination-ip 14.215.177.39 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default` )
244
- case * exec .ScriptDelayActionCommand :
257
+ case * script .ScriptDelayActionCommand :
245
258
action .SetExample (`
246
259
# Add commands to the script "start0() { sleep 10.000000 ...}"
247
260
blade create k8s pod-script delay --time 10000 --file test.sh --function-name start0 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default` )
248
- case * exec .ScriptExitActionCommand :
261
+ case * script .ScriptExitActionCommand :
249
262
action .SetExample (`
250
263
# Add commands to the script "start0() { echo this-is-error-message; exit 1; ... }"
251
264
blade create k8s pod-script exit --exit-code 1 --exit-message this-is-error-message --file test.sh --function-name start0 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default` )
0 commit comments