Skip to content

Commit

Permalink
1.6.0 dev (#149)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
tiny-x authored Apr 29, 2022
1 parent f673b40 commit b574e20
Show file tree
Hide file tree
Showing 16 changed files with 841 additions and 646 deletions.
31 changes: 7 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GO=env $(GO_ENV) $(GO_MODULE) go
UNAME := $(shell uname)

ifeq ($(BLADE_VERSION), )
BLADE_VERSION=1.5.0
BLADE_VERSION=1.6.0
endif
ifeq ($(BLADE_VENDOR), )
BLADE_VENDOR=community
Expand All @@ -27,27 +27,20 @@ VERSION_PKG=github.com/chaosblade-io/chaosblade-operator/version
GO_X_FLAGS=-X=$(VERSION_PKG).CombinedVersion=$(BLADE_VERSION),$(BLADE_VENDOR)
GO_FLAGS=-ldflags $(GO_X_FLAGS)

# cache downloaded file
CACHE_PATH=build/cache
DOWNLOAD_URL=https://chaosblade.oss-cn-hangzhou.aliyuncs.com/agent/github/${BLADE_VERSION}
CHAOSBLADE_FILE=chaosblade-${BLADE_VERSION}-linux-amd64.tar.gz
CHAOSBLADE_UNZIP_DIR=$(CACHE_PATH)/chaosblade-${BLADE_VERSION}
CHAOSBLADE_PATH=$(CACHE_PATH)/chaosblade

ifeq ($(GOOS), linux)
GO_FLAGS=-ldflags="-linkmode external -extldflags -static $(GO_X_FLAGS)"
endif

build: build_yaml build_fuse

build_all: pre_build pre_chaosblade build docker-build
build_all: pre_build build docker-build

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

#operator-sdk 0.19.0 build
build_all_operator: pre_build pre_chaosblade build build_image
build_all_operator: pre_build build build_image
build_image:
operator-sdk build --go-build-args="$(GO_FLAGS)" chaosblade-operator:${BLADE_VERSION}

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

pre_chaosblade:
ifneq ($(CHAOSBLADE_PATH), $(wildcard $(CHAOSBLADE_PATH)))
wget "$(DOWNLOAD_URL)/$(CHAOSBLADE_FILE)" -O $(CACHE_PATH)/$(CHAOSBLADE_FILE)
tar zxvf $(CACHE_PATH)/$(CHAOSBLADE_FILE) -C $(CACHE_PATH)
mv $(CHAOSBLADE_UNZIP_DIR) $(CHAOSBLADE_PATH)
rm -rf $(CACHE_PATH)/$(CHAOSBLADE_FILE)
endif

pre_build:
mkdir -p $(BUILD_TARGET_BIN) $(BUILD_TARGET_YAML) $(CACHE_PATH)
mkdir -p $(BUILD_TARGET_BIN) $(BUILD_TARGET_YAML)

build_spec_yaml: build/spec.go
$(GO) run $< $(OS_YAML_FILE_PATH) $(CHAOSBLADE_PATH)/yaml/chaosblade-jvm-spec-$(BLADE_VERSION).yaml
cp $(OS_YAML_FILE_PATH) $(CHAOSBLADE_PATH)/yaml/
$(GO) run $< $(OS_YAML_FILE_PATH)

build_yaml: pre_build pre_chaosblade build_spec_yaml
build_yaml: pre_build build_spec_yaml

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

# test
test:
go test -race -coverprofile=coverage.txt -covermode=atomic ./...
# clean all build result
clean:
go clean ./...
rm -rf $(BUILD_TARGET) $(CACHE_PATH)
rm -rf $(BUILD_TARGET)
rm -rf $(BUILD_IMAGE_PATH)/$(BUILD_TARGET_DIR_NAME)
4 changes: 2 additions & 2 deletions deploy/helm/chaosblade-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v1
appVersion: "1.5.0"
appVersion: "1.6.0"
description: ChaosBlade Operator
name: chaosblade-operator
version: 1.5.0
version: 1.6.0
home: https://github.com/chaosblade-io
5 changes: 5 additions & 0 deletions deploy/helm/chaosblade-operator/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ spec:
name: containerd-etc
- mountPath: /var/run/netns
name: netns
- mountPath: /host-sys
name: sys
dnsPolicy: ClusterFirstWithHostNet
hostNetwork: true
hostPID: true
Expand Down Expand Up @@ -100,5 +102,8 @@ spec:
- hostPath:
path: /var/run/netns
name: netns
- hostPath:
path: /sys
name: sys
serviceAccountName: chaosblade
{{- end }}
4 changes: 2 additions & 2 deletions deploy/helm/chaosblade-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# chaosblade-operator
operator:
repository: chaosbladeio/chaosblade-operator
version: 1.5.0
version: 1.6.0
# image.pullPolicy: must be Always|IfNotPresent|Never
pullPolicy: IfNotPresent
# qps of kubernetes client
Expand All @@ -12,7 +12,7 @@ operator:

blade:
repository: chaosbladeio/chaosblade-tool
version: 1.5.0
version: 1.6.0
pullPolicy: IfNotPresent
downloadUrl: ""

Expand Down
61 changes: 37 additions & 24 deletions exec/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ package container
import (
"fmt"
criexec "github.com/chaosblade-io/chaosblade-exec-cri/exec"
"github.com/chaosblade-io/chaosblade-exec-os/exec"
"github.com/chaosblade-io/chaosblade-exec-os/exec/cpu"
"github.com/chaosblade-io/chaosblade-exec-os/exec/disk"
"github.com/chaosblade-io/chaosblade-exec-os/exec/file"
"github.com/chaosblade-io/chaosblade-exec-os/exec/mem"
"github.com/chaosblade-io/chaosblade-exec-os/exec/network"
"github.com/chaosblade-io/chaosblade-exec-os/exec/network/tc"
"github.com/chaosblade-io/chaosblade-exec-os/exec/process"
"github.com/chaosblade-io/chaosblade-exec-os/exec/script"
"github.com/chaosblade-io/chaosblade-spec-go/spec"
"strings"

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

osSubExpModelSpecs := model.NewOSSubResourceModelSpec().ExpModels()
containerSelfModelSpec := criexec.NewContainerCommandSpec()
javaExpModelSpecs := getJvmModels()

subExpModelCommandSpecs := make([]spec.ExpModelCommandSpec, 0)
subExpModelCommandSpecs = append(subExpModelCommandSpecs, containerSelfModelSpec)
subExpModelCommandSpecs = append(append(subExpModelCommandSpecs, osSubExpModelSpecs...), javaExpModelSpecs...)
subExpModelCommandSpecs = append(subExpModelCommandSpecs, javaExpModelSpecs...)

spec.AddExecutorToModelSpec(&model.ExecCommandInPodExecutor{Client: client}, subExpModelCommandSpecs...)

// nsexec
osSubExpModelSpecs := model.NewOSSubResourceModelSpec().ExpModels()
spec.AddExecutorToModelSpec(&model.CommonExecutor{Client: client}, osSubExpModelSpecs...)

subExpModelCommandSpecs = append(subExpModelCommandSpecs, osSubExpModelSpecs...)

spec.AddFlagsToModelSpec(getResourceFlags, subExpModelCommandSpecs...)
resourceModelSpec.RegisterExpModels(subExpModelCommandSpecs...)
addActionExamples(resourceModelSpec)
Expand All @@ -58,7 +71,7 @@ func addActionExamples(modelSpec *ResourceModelSpec) {
for _, action := range expModelSpec.Actions() {
v := interface{}(action)
switch v.(type) {
case *exec.KillProcessActionCommandSpec:
case *process.KillProcessActionCommandSpec:
action.SetLongDesc("The process scenario in container is the same as the basic resource process scenario")
action.SetExample(
`
Expand All @@ -69,7 +82,7 @@ blade create k8s container-process kill --process nginx --names nginx-app --cont
# Specifies the signal and local port to kill the process in the container
blade create k8s container-process kill --local-port 8080 --signal 15 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default`)

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

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

case *exec.FillActionSpec:
case *disk.FillActionSpec:
action.SetLongDesc("The disk fill scenario experiment in the container")
action.SetExample(
`
Expand All @@ -111,7 +124,7 @@ blade create k8s container-disk fill --path /home --percent 80 --retain-handle -
# Perform a fixed-size experimental scenario in the container
blade c k8s container-disk fill --path /home --reserve 1024 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
`)
case *exec.BurnActionSpec:
case *disk.BurnActionSpec:
action.SetLongDesc("Disk read and write IO load experiment in the container")
action.SetExample(
`# The data of rkB/s, wkB/s and % Util were mainly observed. Perform disk read IO high-load scenarios
Expand All @@ -123,7 +136,7 @@ blade create k8s container-disk burn --write --path /home --names nginx-app --co
# Read and write IO load scenarios are performed at the same time. Path is not specified. The default is /
blade create k8s container-disk burn --read --write --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default`)

case *exec.MemLoadActionCommand:
case *mem.MemLoadActionCommand:
action.SetLongDesc("The memory fill experiment scenario in container")
action.SetExample(
`# The execution memory footprint is 50%
Expand All @@ -140,7 +153,7 @@ blade create k8s container-mem load --mode ram --mem-percent 50 --timeout 200 --
# 200M memory is reserved
blade create k8s container-mem load --mode ram --reserve 200 --rate 100 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default`)
case *exec.FileAppendActionSpec:
case *file.FileAppendActionSpec:
action.SetLongDesc("The file append experiment scenario in container")
action.SetExample(
`# Appends the content "HELLO WORLD" to the /home/logs/nginx.log file
Expand All @@ -155,7 +168,7 @@ blade create k8s container-file append --filepath=/home/logs/nginx.log --content
# mock interface timeout exception
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
`)
case *exec.FileAddActionSpec:
case *file.FileAddActionSpec:
action.SetLongDesc("The file add experiment scenario in container")
action.SetExample(
`# Create a file named nginx.log in the /home directory
Expand All @@ -171,12 +184,12 @@ blade create k8s container-file add --filepath /temp/nginx.log --auto-create-dir
blade create k8s container-file add --directory --filepath /temp/nginx --auto-create-dir --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
`)

case *exec.FileChmodActionSpec:
case *file.FileChmodActionSpec:
action.SetLongDesc("The file permission modification scenario in container")
action.SetExample(`# Modify /home/logs/nginx.log file permissions to 777
blade create k8s container-file chmod --filepath /home/logs/nginx.log --mark=777 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
`)
case *exec.FileDeleteActionSpec:
case *file.FileDeleteActionSpec:
action.SetLongDesc("The file delete scenario in container")
action.SetExample(
`# Delete the file /home/logs/nginx.log
Expand All @@ -185,7 +198,7 @@ blade create k8s container-file delete --filepath /home/logs/nginx.log --names n
# Force delete the file /home/logs/nginx.log unrecoverable
blade create k8s container-file delete --filepath /home/logs/nginx.log --force --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
`)
case *exec.FileMoveActionSpec:
case *file.FileMoveActionSpec:
action.SetExample("The file move scenario in container")
action.SetExample(`# Move the file /home/logs/nginx.log to /tmp
blade create k8s container-file delete --filepath /home/logs/nginx.log --target /tmp --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
Expand All @@ -196,7 +209,7 @@ blade create k8s container-file delete --filepath /home/logs/nginx.log --target
# Move the file /home/logs/nginx.log to /temp/ and automatically create directories that don't exist
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
`)
case *exec.DelayActionSpec:
case *tc.DelayActionSpec:
action.SetExample(
`# Access to native 8080 and 8081 ports is delayed by 3 seconds, and the delay time fluctuates by 1 second
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
Expand All @@ -206,15 +219,15 @@ blade create k8s container-network delay --time 3000 --interface eth0 --remote-p
# Do a 5 second delay for the entire network card eth0, excluding ports 22 and 8000 to 8080
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`)
case *exec.DropActionSpec:
case *network.DropActionSpec:
action.SetExample(
`# Experimental scenario of network shielding
blade create k8s container-network drop --source-port 80 --network-traffic in --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default`)
case *exec.DnsActionSpec:
case *network.DnsActionSpec:
action.SetExample(
`# The domain name www.baidu.com is not accessible
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`)
case *exec.LossActionSpec:
case *tc.LossActionSpec:
action.SetExample(`# Access to native 8080 and 8081 ports lost 70% of packets
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
Expand All @@ -226,26 +239,26 @@ blade create k8s container-network loss --percent 60 --interface eth0 --exclude-
# 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
blade create k8s container-network loss --percent 100 --interface eth0 --timeout 20 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default`)
case *exec.DuplicateActionSpec:
case *tc.DuplicateActionSpec:
action.SetExample(`# Specify the network card eth0 and repeat the packet by 10%
blade create k8s container-network duplicate --percent=10 --interface=eth0 --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default`)
case *exec.CorruptActionSpec:
case *tc.CorruptActionSpec:
action.SetExample(`# Access to the specified IP request packet is corrupted, 80% of the time
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`)
case *exec.ReorderActionSpec:
case *tc.ReorderActionSpec:
action.SetExample(`# Access the specified IP request packet disorder
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`)
case *exec.OccupyActionSpec:
case *network.OccupyActionSpec:
action.SetExample(`#Specify port 8080 occupancy
blade create k8s container-network occupy --port 8080 --force --names nginx-app --container-ids f1de335b4eeaf --kubeconfig ~/.kube/config --namespace default
# The machine accesses external 14.215.177.39 machine (ping www.baidu.com) 80 port packet loss rate 100%
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`)
case *exec.ScriptDelayActionCommand:
case *script.ScriptDelayActionCommand:
action.SetExample(`
# Add commands to the script "start0() { sleep 10.000000 ...}"
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`)
case *exec.ScriptExitActionCommand:
case *script.ScriptExitActionCommand:
action.SetExample(`
# Add commands to the script "start0() { echo this-is-error-message; exit 1; ... }"
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`)
Expand Down
Loading

0 comments on commit b574e20

Please sign in to comment.