Skip to content

Commit 46c4ed6

Browse files
committed
feature:improvement the action use case
Signed-off-by: tiny.x <[email protected]>
1 parent e2f83d4 commit 46c4ed6

File tree

7 files changed

+499
-3
lines changed

7 files changed

+499
-3
lines changed

exec/container/container.go

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package container
1818

1919
import (
20+
"github.com/chaosblade-io/chaosblade-exec-os/exec"
2021
"github.com/chaosblade-io/chaosblade-spec-go/spec"
2122

2223
"github.com/chaosblade-io/chaosblade-operator/channel"
@@ -36,9 +37,205 @@ func NewResourceModelSpec(client *channel.Client) model.ResourceExpModelSpec {
3637

3738
spec.AddFlagsToModelSpec(getResourceFlags, dockerModelSpecs...)
3839
modelSpec.RegisterExpModels(dockerModelSpecs...)
40+
addActionExamples(modelSpec)
3941
return modelSpec
4042
}
4143

44+
func addActionExamples(modelSpec *ResourceModelSpec) {
45+
for _, expModelSpec := range modelSpec.ExpModelSpecs {
46+
47+
for _, action := range expModelSpec.Actions() {
48+
v := interface{}(action)
49+
switch v.(type) {
50+
case *exec.KillProcessActionCommandSpec:
51+
action.SetLongDesc("The process scenario in container is the same as the basic resource process scenario")
52+
action.SetExample(
53+
`
54+
# Kill the nginx process in the container
55+
blade create k8s container-process kill --process nginx --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
56+
57+
# Use blade CLI
58+
# Specifies the signal and local port to kill the process in the container
59+
blade create k8s container-process kill --local-port 8080 --signal 15 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default`)
60+
61+
case *exec.StopProcessActionCommandSpec:
62+
action.SetLongDesc("The process scenario in container is the same as the basic resource process scenario")
63+
action.SetExample(
64+
`
65+
# Pause the process that contains the "nginx" keyword in the container
66+
blade create k8s container-process stop --process nginx --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
67+
68+
# Pause the Java process in the container
69+
blade create k8s container-process stop --process-cmd java --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default`)
70+
71+
case *exec.FullLoadActionCommand:
72+
action.SetLongDesc("The CPU load experiment scenario in container is the same as the CPU scenario of basic resources")
73+
action.SetExample(
74+
`
75+
# Create a CPU full load experiment in the container
76+
blade create k8s container-cpu load --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
77+
78+
#Specifies two random kernel's full load in the container
79+
blade create k8s container-cpu load --cpu-percent 60 --cpu-count 2 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
80+
81+
# Specifies that the kernel is full load with index 0, 3, and that the kernel's index starts at 0
82+
blade create k8s container-cpu load --cpu-list 0,3 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
83+
84+
# Specify the kernel full load of indexes 1-3
85+
blade create k8s container-cpu load --cpu-list 1-3 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
86+
87+
# Specified percentage load in the container
88+
blade create k8s container-cpu load --cpu-percent 60 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default`)
89+
90+
case *exec.FillActionSpec:
91+
action.SetLongDesc("The disk fill scenario experiment in the container")
92+
action.SetExample(
93+
`
94+
# Fill the /home directory with 40G of disk space in the container
95+
blade create k8s container-disk fill --path /home --size 40000 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
96+
97+
# Fill the /home directory with 80% of the disk space in the container and retains the file handle that populates the disk
98+
blade create k8s container-disk fill --path /home --percent 80 --retain-handle --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
99+
100+
# Perform a fixed-size experimental scenario in the container
101+
blade c k8s container-disk fill --path /home --reserve 1024 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
102+
`)
103+
case *exec.BurnActionSpec:
104+
action.SetLongDesc("Disk read and write IO load experiment in the container")
105+
action.SetExample(
106+
`# The data of rkB/s, wkB/s and % Util were mainly observed. Perform disk read IO high-load scenarios
107+
blade create k8s container-disk burn --read --path /home --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
108+
109+
# Perform disk write IO high-load scenarios
110+
blade create k8s container-disk burn --write --path /home --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default8
111+
112+
# Read and write IO load scenarios are performed at the same time. Path is not specified. The default is /
113+
blade create k8s container-disk burn --read --write --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default`)
114+
115+
case exec.MemCommandModelSpec:
116+
action.SetLongDesc("The memory fill experiment scenario in container")
117+
action.SetExample(
118+
`# The execution memory footprint is 50%
119+
blade create k8s container-mem load --mode ram --mem-percent 50 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
120+
121+
# The execution memory footprint is 50%, cache model
122+
blade create k8s container-mem load --mode cache --mem-percent 50 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
123+
124+
# The execution memory footprint is 50%, usage contains buffer/cache
125+
blade create k8s container-mem load --mode ram --mem-percent 50 --include-buffer-cache --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
126+
127+
# The execution memory footprint is 50% for 200 seconds
128+
blade create k8s container-mem load --mode ram --mem-percent 50 --timeout 200 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
129+
130+
# 200M memory is reserved
131+
blade create k8s container-mem load --mode ram --reserve 200 --rate 100 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default`)
132+
case *exec.FileAppendActionSpec:
133+
action.SetLongDesc("The file append experiment scenario in container")
134+
action.SetExample(
135+
`# Appends the content "HELLO WORLD" to the /home/logs/nginx.log file
136+
blade create k8s container-file append --filepath=/home/logs/nginx.log --content="HELL WORLD" --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
137+
138+
# Appends the content "HELLO WORLD" to the /home/logs/nginx.log file, interval 10 seconds
139+
blade create k8s container-file append --filepath=/home/logs/nginx.log --content="HELL WORLD" --interval 10 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
140+
141+
# Appends the content "HELLO WORLD" to the /home/logs/nginx.log file, enable base64 encoding
142+
blade create k8s container-file append --filepath=/home/logs/nginx.log --content=SEVMTE8gV09STEQ= --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
143+
144+
# mock interface timeout exception
145+
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 config --namespace default
146+
`)
147+
case *exec.FileAddActionSpec:
148+
action.SetLongDesc("The file add experiment scenario in container")
149+
action.SetExample(
150+
`# Create a file named nginx.log in the /home directory
151+
blade create k8s container-file add --filepath /home/nginx.log --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
152+
153+
# Create a file named nginx.log in the /home directory with the contents of HELLO WORLD
154+
blade create k8s container-file add --filepath /home/nginx.log --content "HELLO WORLD" --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
155+
156+
# Create a file named nginx.log in the /temp directory and automatically create directories that don't exist
157+
blade create k8s container-file add --filepath /temp/nginx.log --auto-create-dir --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
158+
159+
# Create a directory named /nginx in the /temp directory and automatically create directories that don't exist
160+
blade create k8s container-file add --directory --filepath /temp/nginx --auto-create-dir --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
161+
`)
162+
163+
case *exec.FileChmodActionSpec:
164+
action.SetLongDesc("The file permission modification scenario in container")
165+
action.SetExample(`# Modify /home/logs/nginx.log file permissions to 777
166+
blade create k8s container-file chmod --filepath /home/logs/nginx.log --mark=777 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
167+
`)
168+
case *exec.FileDeleteActionSpec:
169+
action.SetLongDesc("The file delete scenario in container")
170+
action.SetExample(
171+
`# Delete the file /home/logs/nginx.log
172+
blade create k8s container-file delete --filepath /home/logs/nginx.log --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
173+
174+
# Force delete the file /home/logs/nginx.log unrecoverable
175+
blade create k8s container-file delete --filepath /home/logs/nginx.log --force --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
176+
`)
177+
case *exec.FileMoveActionSpec:
178+
action.SetExample("The file move scenario in container")
179+
action.SetExample(`# Move the file /home/logs/nginx.log to /tmp
180+
blade create k8s container-file delete --filepath /home/logs/nginx.log --target /tmp --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
181+
182+
# Force Move the file /home/logs/nginx.log to /temp
183+
blade create k8s container-file delete --filepath /home/logs/nginx.log --target /tmp --force --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
184+
185+
# Move the file /home/logs/nginx.log to /temp/ and automatically create directories that don't exist
186+
blade create k8s container-file delete --filepath /home/logs/nginx.log --target /temp --auto-create-dir --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
187+
`)
188+
case *exec.DelayActionSpec:
189+
action.SetExample(
190+
`# Access to native 8080 and 8081 ports is delayed by 3 seconds, and the delay time fluctuates by 1 second
191+
blade create k8s container-network delay --time 3000 --offset 1000 --interface eth0 --local-port 8080,8081 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
192+
193+
# Local access to external 14.215.177.39 machine (ping www.baidu.com obtained IP) port 80 delay of 3 seconds
194+
blade create k8s container-network delay --time 3000 --interface eth0 --remote-port 80 --destination-ip 14.215.177.39 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
195+
196+
# Do a 5 second delay for the entire network card eth0, excluding ports 22 and 8000 to 8080
197+
blade create k8s container-network delay --time 5000 --interface eth0 --exclude-port 22,8000-8080 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default`)
198+
case *exec.DropActionSpec:
199+
action.SetExample(
200+
`# Experimental scenario of network shielding
201+
blade create k8s container-network drop --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default`)
202+
case *exec.DnsActionSpec:
203+
action.SetExample(
204+
`# The domain name www.baidu.com is not accessible
205+
blade create k8s container-network dns --domain www.baidu.com --ip 10.0.0.0 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default`)
206+
case *exec.LossActionSpec:
207+
action.SetExample(`# Access to native 8080 and 8081 ports lost 70% of packets
208+
blade create k8s container-network loss --percent 70 --interface eth0 --local-port 8080,8081 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
209+
210+
# The machine accesses external 14.215.177.39 machine (ping www.baidu.com) 80 port packet loss rate 100%
211+
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 config --namespace default
212+
213+
# Do 60% packet loss for the entire network card Eth0, excluding ports 22 and 8000 to 8080
214+
blade create k8s container-network loss --percent 60 --interface eth0 --exclude-port 22,8000-8080 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
215+
216+
# 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
217+
blade create k8s container-network loss --percent 100 --interface eth0 --timeout 20 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default`)
218+
case *exec.DuplicateActionSpec:
219+
action.SetExample(`# Specify the network card eth0 and repeat the packet by 10%
220+
blade create k8s container-network duplicate --percent=10 --interface=eth0 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default`)
221+
case *exec.CorruptActionSpec:
222+
action.SetExample(`# Access to the specified IP request packet is corrupted, 80% of the time
223+
blade create k8s container-network corrupt --percent 80 --destination-ip 180.101.49.12 --interface eth0 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default`)
224+
case *exec.ReorderActionSpec:
225+
action.SetExample(`# Access the specified IP request packet disorder
226+
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 config --namespace default`)
227+
case *exec.OccupyActionSpec:
228+
action.SetExample(`#Specify port 8080 occupancy
229+
blade create k8s container-network occupy --port 8080 --force --names nginx-app --container-ids f1de335b4eeaf --kubeconfig config --namespace default
230+
231+
# The machine accesses external 14.215.177.39 machine (ping www.baidu.com) 80 port packet loss rate 100%
232+
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 config --namespace default`)
233+
}
234+
}
235+
}
236+
237+
}
238+
42239
func getResourceFlags() []spec.ExpFlagSpec {
43240
coverageFlags := model.GetResourceCoverageFlags()
44241
commonFlags := model.GetResourceCommonFlags()

0 commit comments

Comments
 (0)