Skip to content

Commit

Permalink
fix: fix the JVM failure ClASSPATH dependency problem; fix the unders…
Browse files Browse the repository at this point in the history
…core self-adaptation problem of multi-word args; Support domestic mirror registry
  • Loading branch information
KingsonKai committed May 30, 2023
1 parent 845db91 commit 99ec0ec
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 26 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,14 @@ The currently supported failure capabilities are as follows:
# Getting Started
#### Quick Start
```shell
# download docker mirror
docker pull ghcr.io/traas-stack/chaosmetad-demo:v0.1.0

# Run and enter the docker container
docker run --privileged -it ghcr.io/traas-stack/chaosmetad-demo:v0.1.0 /bin/bash
# download docker mirror and run container
docker run --privileged -it registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmetad-demo:v0.1.1 /bin/bash

# make the environment variable take effect
source /etc/profile

# Start the test service
cd /home/demo && python -m SimpleHTTPServer 8080 > server.log 2>&1 &
cd /tmp && python -m SimpleHTTPServer 8080 > server.log 2>&1 &
curl 127.0.0.1:8080

# Create an experiment to inject a 2s network delay into the lo network card, and it will automatically recover after 10 minutes
Expand Down
10 changes: 3 additions & 7 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,14 @@ ChaosMeta 是一个致力于支撑完整故障演练生命周期的平台,提
# 使用指引
#### 快速试用单机注入能力
```shell
# 下载镜像
docker pull ghcr.io/traas-stack/chaosmetad-demo:v0.1.0

# 特权级运行并进入容器
docker run --privileged -it ghcr.io/traas-stack/chaosmetad-demo:v0.1.0 /bin/bash
# 下载镜像并运行容器
docker run --privileged -it registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmetad-demo:v0.1.1 /bin/bash

# 使环境变量生效
source /etc/profile

# 启动测试服务
cd /home/demo
python -m SimpleHTTPServer 8080 > server.log 2>&1 &
cd /tmp && python -m SimpleHTTPServer 8080 > server.log 2>&1 &
curl 127.0.0.1:8080

# 创建一个实验,给lo网卡注入2s网络延迟,10分钟后自动恢复
Expand Down
2 changes: 1 addition & 1 deletion chaosmeta-inject-operator/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

# Image URL to use all building/pushing image targets
IMG ?= ghcr.io/traas-stack/chaosmeta-inject-controller:v0.0.2
IMG ?= registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-inject-controller:v0.0.3
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.26.0

Expand Down
2 changes: 1 addition & 1 deletion chaosmeta-inject-operator/build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ kubectl create configmap chaosmeta-inject-config --from-file="${ROOT_PATH}"/conf

BUILD_DIR="/tmp/chaosmeta_build"
mkdir -p ${BUILD_DIR}/ssl && cd ${BUILD_DIR}/ssl
docker run --mount type=bind,source=$(pwd),destination=/data ghcr.io/traas-stack/chaosmeta-openssl:v1.0.0 openssl req -x509 -newkey rsa:4096 -keyout /data/tls.key -out /data/tls.crt -days 3650 -nodes -subj "/CN=chaosmeta-inject-webhook-service.chaosmeta.svc" -addext "subjectAltName=DNS:chaosmeta-inject-webhook-service.chaosmeta.svc"
docker run --mount type=bind,source=$(pwd),destination=/data registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-openssl:v1.0.0 openssl req -x509 -newkey rsa:4096 -keyout /data/tls.key -out /data/tls.crt -days 3650 -nodes -subj "/CN=chaosmeta-inject-webhook-service.chaosmeta.svc" -addext "subjectAltName=DNS:chaosmeta-inject-webhook-service.chaosmeta.svc"
caBundle=$(cat tls.crt | base64 -w 0)
kubectl create secret tls webhook-server-cert --cert=tls.crt --key=tls.key -n chaosmeta
kubectl patch MutatingWebhookConfiguration chaosmeta-inject-mutating-webhook-configuration --type='json' -p='[{"op": "add", "path": "/webhooks/0/clientConfig/caBundle", "value": "'"${caBundle}"'"}]'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# docker build -t ghcr.io/traas-stack/chaosmeta-daemon:v0.1.0 -f chaosmeta-daemonset.Dockerfile .
# docker build -t registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-daemon:v0.1.1 -f chaosmeta-daemonset.Dockerfile .
From centos:centos7
ENV CHAOSMETAD_VERSION=0.1.0
ENV CHAOSMETAD_VERSION=0.1.1
ADD ./chaosmetad-$CHAOSMETAD_VERSION.tar.gz /opt/chaosmeta
CMD while true; do if [ ! -d "/tmp/chaosmetad-$CHAOSMETAD_VERSION" ]; then cp -r /opt/chaosmeta/chaosmetad-$CHAOSMETAD_VERSION /tmp/chaosmetad-$CHAOSMETAD_VERSION; fi; sleep 600; done
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spec:
# chaos-role.chaosmeta.io: chaosmeta-daemon
containers:
- name: chaosmeta-daemon
image: ghcr.io/traas-stack/chaosmeta-daemon:v0.1.0
image: registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-daemon:v0.1.1
securityContext:
privileged: true
volumeMounts:
Expand Down
2 changes: 1 addition & 1 deletion chaosmeta-inject-operator/build/yamls/chaosmeta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ spec:
- --leader-elect
command:
- /manager
image: ghcr.io/traas-stack/chaosmeta-inject-controller:v0.0.2
image: registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-inject-controller:v0.0.3
livenessProbe:
httpGet:
path: /healthz
Expand Down
2 changes: 1 addition & 1 deletion chaosmeta-inject-operator/config/chaosmeta-inject.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"executor": {
"mode": "daemonset",
"executor": "chaosmetad",
"version": "0.1.0",
"version": "0.1.1",
"agentConfig": {
"agentPort": 29595
},
Expand Down
4 changes: 2 additions & 2 deletions chaosmeta-inject-operator/config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: ghcr.io/traas-stack/chaosmeta-inject-controller
newTag: v0.0.2
newName: registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-inject-controller
newTag: v0.0.3
2 changes: 1 addition & 1 deletion chaosmeta-inject-operator/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ spec:
- /manager
args:
- --leader-elect
image: ghcr.io/traas-stack/chaosmeta-inject-controller:v0.0.2
image: registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-inject-controller:v0.0.3
name: manager
securityContext:
allowPrivilegeEscalation: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
httpclient "github.com/traas-stack/chaosmeta/chaosmeta-inject-operator/pkg/http"
"github.com/traas-stack/chaosmeta/chaosmeta-inject-operator/pkg/model"
"strconv"
"strings"
)

type AgentRemoteExecutor struct {
Expand Down Expand Up @@ -71,6 +72,7 @@ func (r *AgentRemoteExecutor) Inject(ctx context.Context, injectObject string, t
continue
}

unitArgs.Key = strings.ReplaceAll(unitArgs.Key, "-", "_")
if unitArgs.ValueType == v1alpha1.IntVType {
argsInt, err := strconv.Atoi(unitArgs.Value)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/remotecommand"
"sigs.k8s.io/controller-runtime/pkg/log"
"strings"
)

type DaemonsetRemoteExecutor struct {
Expand Down Expand Up @@ -101,6 +102,7 @@ func (r *DaemonsetRemoteExecutor) Inject(ctx context.Context, injectObject strin
continue
}

unitArgs.Key = strings.ReplaceAll(unitArgs.Key, "_", "-")
executeCmd = fmt.Sprintf("%s --%s %s", executeCmd, unitArgs.Key, unitArgs.Value)
}

Expand Down
7 changes: 7 additions & 0 deletions chaosmetad/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# docker build -t registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmetad-demo:v0.1.1 .
From centos:centos7
ADD ./jdk-8u361-linux-x64.tar.gz /usr/local
RUN yum install -y iproute && yum clean all
ENV CHAOSMETAD_VERSION=0.1.1
ADD ./chaosmetad-$CHAOSMETAD_VERSION.tar.gz /opt/chaosmeta
RUN echo 'export JAVA_HOME=/usr/local/jdk1.8.0_361' >> /etc/profile && echo 'export PATH=$PATH:$JAVA_HOME/bin' >> /etc/profile && echo 'export PATH=$PATH:/opt/chaosmeta/chaosmetad-'${CHAOSMETAD_VERSION} >> /etc/profile
5 changes: 4 additions & 1 deletion chaosmetad/build/ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fi

# base info
BUILD_NAME="chaosmetad"
VERSION="0.1.0"
VERSION="0.1.1"
BUILD_DATE=$(date "+%Y-%m-%d %H:%M:%S")

# env var
Expand Down Expand Up @@ -113,6 +113,9 @@ javac -d ${PACKAGE_DIR}/${OS_NAME}/tools ${PROJECT_DIR}/tools/jvm/${JVM_METHOD_R
javac -d ${PACKAGE_DIR}/${OS_NAME}/tools ${PROJECT_DIR}/tools/jvm/${JVM_TRANSFORMER}.java -cp ${PROJECT_DIR}/tools/jvm/lib/tools.jar:${PROJECT_DIR}/tools/jvm/lib/javassist.jar:${PACKAGE_DIR}/${OS_NAME}/tools
javac -d ${PACKAGE_DIR}/${OS_NAME}/tools ${PROJECT_DIR}/tools/jvm/${JVM_AGENT}.java -cp ${PROJECT_DIR}/tools/jvm/lib/tools.jar:${PROJECT_DIR}/tools/jvm/lib/json-20190722.jar:${PACKAGE_DIR}/${OS_NAME}/tools
cp ${PROJECT_DIR}/tools/jvm/MANIFEST.MF ${PACKAGE_DIR}/${OS_NAME}/tools
cp ${PROJECT_DIR}/tools/jvm/lib/tools.jar ${PACKAGE_DIR}/${OS_NAME}/tools
cp ${PROJECT_DIR}/tools/jvm/lib/javassist.jar ${PACKAGE_DIR}/${OS_NAME}/tools
cp ${PROJECT_DIR}/tools/jvm/lib/json-20190722.jar ${PACKAGE_DIR}/${OS_NAME}/tools
cd ${PACKAGE_DIR}/${OS_NAME}/tools
jar cvfm ${JVM_AGENT}.jar MANIFEST.MF ${JVM_AGENT}.class ${JVM_TRANSFORMER}.class ${JVM_METHOD_RULE}.class
cp -R ${PACKAGE_DIR}/${OS_NAME}/tools ${OUTPUT_DIR}/
2 changes: 1 addition & 1 deletion chaosmetad/pkg/injector/jvm/methoddelay.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func getRuleConfig(methodListMap map[string][]*MethodJVMRule, timeout int64) *JV
}

func getCmd(pid int) string {
return fmt.Sprintf("cd %s && java %s %d %s %s", utils.GetToolDir(), AttacherTool, pid, utils.GetToolPath(JVMAgentTool), getRuleFile(pid))
return fmt.Sprintf("cd %s && java -cp .:tools.jar %s %d %s %s", utils.GetToolDir(), AttacherTool, pid, utils.GetToolPath(JVMAgentTool), getRuleFile(pid))
}

func writeRule(ctx context.Context, pid int, ruleBytes []byte) error {
Expand Down
2 changes: 1 addition & 1 deletion chaosmetad/pkg/utils/cmdexec/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func waitProExec(ctx context.Context, stdout, stderr *bytes.Buffer, timeoutSec i

log.GetLogger(ctx).Debugf(msg)

if strings.Index(msg, "error") >= 0 {
if strings.Index(msg, "error") >= 0 || strings.Index(msg, "Error") >= 0 {
return fmt.Errorf("inject error: %s", msg)
}

Expand Down
1 change: 1 addition & 0 deletions chaosmetad/tools/jvm/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Manifest-Version: 1.0
Can-Redefine-Classes: true
Can-Retransform-Classes: true
Agent-Class: ChaosMetaJVMAgent
Class-Path: javassist.jar json-20190722.jar

0 comments on commit 99ec0ec

Please sign in to comment.