Skip to content

Commit b574e20

Browse files
authored
1.6.0 dev (#149)
* feature: support nsexec Signed-off-by: tiny-x <[email protected]> * chore: update version to 1.6.0 Signed-off-by: tiny-x <[email protected]> * fix: process hang exp Signed-off-by: tiny-x <[email protected]> * feature: improvement compile, remove parse java models Signed-off-by: tiny-x <[email protected]> * feature: update cri version Signed-off-by: tiny-x <[email protected]>
1 parent f673b40 commit b574e20

File tree

16 files changed

+841
-646
lines changed

16 files changed

+841
-646
lines changed

Makefile

+7-24
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ GO=env $(GO_ENV) $(GO_MODULE) go
77
UNAME := $(shell uname)
88

99
ifeq ($(BLADE_VERSION), )
10-
BLADE_VERSION=1.5.0
10+
BLADE_VERSION=1.6.0
1111
endif
1212
ifeq ($(BLADE_VENDOR), )
1313
BLADE_VENDOR=community
@@ -27,27 +27,20 @@ VERSION_PKG=github.com/chaosblade-io/chaosblade-operator/version
2727
GO_X_FLAGS=-X=$(VERSION_PKG).CombinedVersion=$(BLADE_VERSION),$(BLADE_VENDOR)
2828
GO_FLAGS=-ldflags $(GO_X_FLAGS)
2929

30-
# cache downloaded file
31-
CACHE_PATH=build/cache
32-
DOWNLOAD_URL=https://chaosblade.oss-cn-hangzhou.aliyuncs.com/agent/github/${BLADE_VERSION}
33-
CHAOSBLADE_FILE=chaosblade-${BLADE_VERSION}-linux-amd64.tar.gz
34-
CHAOSBLADE_UNZIP_DIR=$(CACHE_PATH)/chaosblade-${BLADE_VERSION}
35-
CHAOSBLADE_PATH=$(CACHE_PATH)/chaosblade
36-
3730
ifeq ($(GOOS), linux)
3831
GO_FLAGS=-ldflags="-linkmode external -extldflags -static $(GO_X_FLAGS)"
3932
endif
4033

4134
build: build_yaml build_fuse
4235

43-
build_all: pre_build pre_chaosblade build docker-build
36+
build_all: pre_build build docker-build
4437

4538
docker-build:
4639
GOOS="linux" GOARCH="amd64" go build $(GO_FLAGS) -o build/_output/bin/chaosblade-operator cmd/manager/main.go
4740
docker build -f build/Dockerfile -t chaosblade-operator:${BLADE_VERSION} .
4841

4942
#operator-sdk 0.19.0 build
50-
build_all_operator: pre_build pre_chaosblade build build_image
43+
build_all_operator: pre_build build build_image
5144
build_image:
5245
operator-sdk build --go-build-args="$(GO_FLAGS)" chaosblade-operator:${BLADE_VERSION}
5346

@@ -60,32 +53,22 @@ build_linux:
6053
-w /go/src/github.com/chaosblade-io/chaosblade-operator \
6154
chaosblade-operator-build-musl:latest
6255

63-
pre_chaosblade:
64-
ifneq ($(CHAOSBLADE_PATH), $(wildcard $(CHAOSBLADE_PATH)))
65-
wget "$(DOWNLOAD_URL)/$(CHAOSBLADE_FILE)" -O $(CACHE_PATH)/$(CHAOSBLADE_FILE)
66-
tar zxvf $(CACHE_PATH)/$(CHAOSBLADE_FILE) -C $(CACHE_PATH)
67-
mv $(CHAOSBLADE_UNZIP_DIR) $(CHAOSBLADE_PATH)
68-
rm -rf $(CACHE_PATH)/$(CHAOSBLADE_FILE)
69-
endif
70-
7156
pre_build:
72-
mkdir -p $(BUILD_TARGET_BIN) $(BUILD_TARGET_YAML) $(CACHE_PATH)
57+
mkdir -p $(BUILD_TARGET_BIN) $(BUILD_TARGET_YAML)
7358

7459
build_spec_yaml: build/spec.go
75-
$(GO) run $< $(OS_YAML_FILE_PATH) $(CHAOSBLADE_PATH)/yaml/chaosblade-jvm-spec-$(BLADE_VERSION).yaml
76-
cp $(OS_YAML_FILE_PATH) $(CHAOSBLADE_PATH)/yaml/
60+
$(GO) run $< $(OS_YAML_FILE_PATH)
7761

78-
build_yaml: pre_build pre_chaosblade build_spec_yaml
62+
build_yaml: pre_build build_spec_yaml
7963

8064
build_fuse:
8165
$(GO) build $(GO_FLAGS) -o $(BUILD_TARGET_BIN)/chaos_fuse cmd/hookfs/main.go
82-
cp $(BUILD_TARGET_BIN)/chaos_fuse $(CHAOSBLADE_PATH)/bin/
8366

8467
# test
8568
test:
8669
go test -race -coverprofile=coverage.txt -covermode=atomic ./...
8770
# clean all build result
8871
clean:
8972
go clean ./...
90-
rm -rf $(BUILD_TARGET) $(CACHE_PATH)
73+
rm -rf $(BUILD_TARGET)
9174
rm -rf $(BUILD_IMAGE_PATH)/$(BUILD_TARGET_DIR_NAME)
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: v1
2-
appVersion: "1.5.0"
2+
appVersion: "1.6.0"
33
description: ChaosBlade Operator
44
name: chaosblade-operator
5-
version: 1.5.0
5+
version: 1.6.0
66
home: https://github.com/chaosblade-io

deploy/helm/chaosblade-operator/templates/daemonset.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ spec:
6262
name: containerd-etc
6363
- mountPath: /var/run/netns
6464
name: netns
65+
- mountPath: /host-sys
66+
name: sys
6567
dnsPolicy: ClusterFirstWithHostNet
6668
hostNetwork: true
6769
hostPID: true
@@ -100,5 +102,8 @@ spec:
100102
- hostPath:
101103
path: /var/run/netns
102104
name: netns
105+
- hostPath:
106+
path: /sys
107+
name: sys
103108
serviceAccountName: chaosblade
104109
{{- end }}

deploy/helm/chaosblade-operator/values.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# chaosblade-operator
44
operator:
55
repository: chaosbladeio/chaosblade-operator
6-
version: 1.5.0
6+
version: 1.6.0
77
# image.pullPolicy: must be Always|IfNotPresent|Never
88
pullPolicy: IfNotPresent
99
# qps of kubernetes client
@@ -12,7 +12,7 @@ operator:
1212

1313
blade:
1414
repository: chaosbladeio/chaosblade-tool
15-
version: 1.5.0
15+
version: 1.6.0
1616
pullPolicy: IfNotPresent
1717
downloadUrl: ""
1818

exec/container/container.go

+37-24
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ package container
1919
import (
2020
"fmt"
2121
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"
2330
"github.com/chaosblade-io/chaosblade-spec-go/spec"
2431
"strings"
2532

@@ -37,15 +44,21 @@ func NewResourceModelSpec(client *channel.Client) model.ResourceExpModelSpec {
3744
model.NewBaseResourceExpModelSpec("container", client),
3845
}
3946

40-
osSubExpModelSpecs := model.NewOSSubResourceModelSpec().ExpModels()
4147
containerSelfModelSpec := criexec.NewContainerCommandSpec()
4248
javaExpModelSpecs := getJvmModels()
4349

4450
subExpModelCommandSpecs := make([]spec.ExpModelCommandSpec, 0)
4551
subExpModelCommandSpecs = append(subExpModelCommandSpecs, containerSelfModelSpec)
46-
subExpModelCommandSpecs = append(append(subExpModelCommandSpecs, osSubExpModelSpecs...), javaExpModelSpecs...)
52+
subExpModelCommandSpecs = append(subExpModelCommandSpecs, javaExpModelSpecs...)
53+
4754
spec.AddExecutorToModelSpec(&model.ExecCommandInPodExecutor{Client: client}, subExpModelCommandSpecs...)
4855

56+
// nsexec
57+
osSubExpModelSpecs := model.NewOSSubResourceModelSpec().ExpModels()
58+
spec.AddExecutorToModelSpec(&model.CommonExecutor{Client: client}, osSubExpModelSpecs...)
59+
60+
subExpModelCommandSpecs = append(subExpModelCommandSpecs, osSubExpModelSpecs...)
61+
4962
spec.AddFlagsToModelSpec(getResourceFlags, subExpModelCommandSpecs...)
5063
resourceModelSpec.RegisterExpModels(subExpModelCommandSpecs...)
5164
addActionExamples(resourceModelSpec)
@@ -58,7 +71,7 @@ func addActionExamples(modelSpec *ResourceModelSpec) {
5871
for _, action := range expModelSpec.Actions() {
5972
v := interface{}(action)
6073
switch v.(type) {
61-
case *exec.KillProcessActionCommandSpec:
74+
case *process.KillProcessActionCommandSpec:
6275
action.SetLongDesc("The process scenario in container is the same as the basic resource process scenario")
6376
action.SetExample(
6477
`
@@ -69,7 +82,7 @@ blade create k8s container-process kill --process nginx --names nginx-app --cont
6982
# Specifies the signal and local port to kill the process in the container
7083
blade create k8s container-process kill --local-port 8080 --signal 15 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default`)
7184

72-
case *exec.StopProcessActionCommandSpec:
85+
case *process.StopProcessActionCommandSpec:
7386
action.SetLongDesc("The process scenario in container is the same as the basic resource process scenario")
7487
action.SetExample(
7588
`
@@ -79,7 +92,7 @@ blade create k8s container-process stop --process nginx --names nginx-app --cont
7992
# Pause the Java process in the container
8093
blade create k8s container-process stop --process-cmd java --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default`)
8194

82-
case *exec.FullLoadActionCommand:
95+
case *cpu.FullLoadActionCommand:
8396
action.SetLongDesc("The CPU load experiment scenario in container is the same as the CPU scenario of basic resources")
8497
action.SetExample(
8598
`
@@ -98,7 +111,7 @@ blade create k8s container-cpu load --cpu-list 1-3 --names nginx-app --container
98111
# Specified percentage load in the container
99112
blade create k8s container-cpu load --cpu-percent 60 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default`)
100113

101-
case *exec.FillActionSpec:
114+
case *disk.FillActionSpec:
102115
action.SetLongDesc("The disk fill scenario experiment in the container")
103116
action.SetExample(
104117
`
@@ -111,7 +124,7 @@ blade create k8s container-disk fill --path /home --percent 80 --retain-handle -
111124
# Perform a fixed-size experimental scenario in the container
112125
blade c k8s container-disk fill --path /home --reserve 1024 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
113126
`)
114-
case *exec.BurnActionSpec:
127+
case *disk.BurnActionSpec:
115128
action.SetLongDesc("Disk read and write IO load experiment in the container")
116129
action.SetExample(
117130
`# 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
123136
# Read and write IO load scenarios are performed at the same time. Path is not specified. The default is /
124137
blade create k8s container-disk burn --read --write --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default`)
125138

126-
case *exec.MemLoadActionCommand:
139+
case *mem.MemLoadActionCommand:
127140
action.SetLongDesc("The memory fill experiment scenario in container")
128141
action.SetExample(
129142
`# The execution memory footprint is 50%
@@ -140,7 +153,7 @@ blade create k8s container-mem load --mode ram --mem-percent 50 --timeout 200 --
140153
141154
# 200M memory is reserved
142155
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:
144157
action.SetLongDesc("The file append experiment scenario in container")
145158
action.SetExample(
146159
`# 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
155168
# mock interface timeout exception
156169
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
157170
`)
158-
case *exec.FileAddActionSpec:
171+
case *file.FileAddActionSpec:
159172
action.SetLongDesc("The file add experiment scenario in container")
160173
action.SetExample(
161174
`# 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
171184
blade create k8s container-file add --directory --filepath /temp/nginx --auto-create-dir --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
172185
`)
173186

174-
case *exec.FileChmodActionSpec:
187+
case *file.FileChmodActionSpec:
175188
action.SetLongDesc("The file permission modification scenario in container")
176189
action.SetExample(`# Modify /home/logs/nginx.log file permissions to 777
177190
blade create k8s container-file chmod --filepath /home/logs/nginx.log --mark=777 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
178191
`)
179-
case *exec.FileDeleteActionSpec:
192+
case *file.FileDeleteActionSpec:
180193
action.SetLongDesc("The file delete scenario in container")
181194
action.SetExample(
182195
`# Delete the file /home/logs/nginx.log
@@ -185,7 +198,7 @@ blade create k8s container-file delete --filepath /home/logs/nginx.log --names n
185198
# Force delete the file /home/logs/nginx.log unrecoverable
186199
blade create k8s container-file delete --filepath /home/logs/nginx.log --force --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
187200
`)
188-
case *exec.FileMoveActionSpec:
201+
case *file.FileMoveActionSpec:
189202
action.SetExample("The file move scenario in container")
190203
action.SetExample(`# Move the file /home/logs/nginx.log to /tmp
191204
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
196209
# Move the file /home/logs/nginx.log to /temp/ and automatically create directories that don't exist
197210
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
198211
`)
199-
case *exec.DelayActionSpec:
212+
case *tc.DelayActionSpec:
200213
action.SetExample(
201214
`# Access to native 8080 and 8081 ports is delayed by 3 seconds, and the delay time fluctuates by 1 second
202215
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
206219
207220
# Do a 5 second delay for the entire network card eth0, excluding ports 22 and 8000 to 8080
208221
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:
210223
action.SetExample(
211224
`# Experimental scenario of network shielding
212225
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:
214227
action.SetExample(
215228
`# The domain name www.baidu.com is not accessible
216229
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:
218231
action.SetExample(`# Access to native 8080 and 8081 ports lost 70% of packets
219232
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
220233
@@ -226,26 +239,26 @@ blade create k8s container-network loss --percent 60 --interface eth0 --exclude-
226239
227240
# 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
228241
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:
230243
action.SetExample(`# Specify the network card eth0 and repeat the packet by 10%
231244
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:
233246
action.SetExample(`# Access to the specified IP request packet is corrupted, 80% of the time
234247
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:
236249
action.SetExample(`# Access the specified IP request packet disorder
237250
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:
239252
action.SetExample(`#Specify port 8080 occupancy
240253
blade create k8s container-network occupy --port 8080 --force --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
241254
242255
# The machine accesses external 14.215.177.39 machine (ping www.baidu.com) 80 port packet loss rate 100%
243256
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:
245258
action.SetExample(`
246259
# Add commands to the script "start0() { sleep 10.000000 ...}"
247260
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:
249262
action.SetExample(`
250263
# Add commands to the script "start0() { echo this-is-error-message; exit 1; ... }"
251264
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

Comments
 (0)