diff --git a/README.md b/README.md index dec32a9..9986880 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/README_CN.md b/README_CN.md index 2973c39..1cf286a 100644 --- a/README_CN.md +++ b/README_CN.md @@ -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分钟后自动恢复 diff --git a/chaosmeta-inject-operator/Makefile b/chaosmeta-inject-operator/Makefile index 403c8fa..4384271 100644 --- a/chaosmeta-inject-operator/Makefile +++ b/chaosmeta-inject-operator/Makefile @@ -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 diff --git a/chaosmeta-inject-operator/build/build.sh b/chaosmeta-inject-operator/build/build.sh index 296c3ad..1b4e768 100644 --- a/chaosmeta-inject-operator/build/build.sh +++ b/chaosmeta-inject-operator/build/build.sh @@ -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}"'"}]' diff --git a/chaosmeta-inject-operator/build/chaosmeta-daemonset.Dockerfile b/chaosmeta-inject-operator/build/chaosmeta-daemonset.Dockerfile index b1fba13..19b3821 100644 --- a/chaosmeta-inject-operator/build/chaosmeta-daemonset.Dockerfile +++ b/chaosmeta-inject-operator/build/chaosmeta-daemonset.Dockerfile @@ -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 diff --git a/chaosmeta-inject-operator/build/yamls/chaosmeta-daemonset.yaml b/chaosmeta-inject-operator/build/yamls/chaosmeta-daemonset.yaml index 86619ae..f3fd637 100644 --- a/chaosmeta-inject-operator/build/yamls/chaosmeta-daemonset.yaml +++ b/chaosmeta-inject-operator/build/yamls/chaosmeta-daemonset.yaml @@ -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: diff --git a/chaosmeta-inject-operator/build/yamls/chaosmeta.yaml b/chaosmeta-inject-operator/build/yamls/chaosmeta.yaml index d929f8e..ab46aa3 100644 --- a/chaosmeta-inject-operator/build/yamls/chaosmeta.yaml +++ b/chaosmeta-inject-operator/build/yamls/chaosmeta.yaml @@ -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 diff --git a/chaosmeta-inject-operator/config/chaosmeta-inject.json b/chaosmeta-inject-operator/config/chaosmeta-inject.json index 16651ad..55e6020 100644 --- a/chaosmeta-inject-operator/config/chaosmeta-inject.json +++ b/chaosmeta-inject-operator/config/chaosmeta-inject.json @@ -8,7 +8,7 @@ "executor": { "mode": "daemonset", "executor": "chaosmetad", - "version": "0.1.0", + "version": "0.1.1", "agentConfig": { "agentPort": 29595 }, diff --git a/chaosmeta-inject-operator/config/manager/kustomization.yaml b/chaosmeta-inject-operator/config/manager/kustomization.yaml index 7177c37..d6ab04a 100644 --- a/chaosmeta-inject-operator/config/manager/kustomization.yaml +++ b/chaosmeta-inject-operator/config/manager/kustomization.yaml @@ -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 diff --git a/chaosmeta-inject-operator/config/manager/manager.yaml b/chaosmeta-inject-operator/config/manager/manager.yaml index fefd26d..84b6548 100644 --- a/chaosmeta-inject-operator/config/manager/manager.yaml +++ b/chaosmeta-inject-operator/config/manager/manager.yaml @@ -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 diff --git a/chaosmeta-inject-operator/pkg/executor/remoteexecutor/agentexecutor/agentexecutor.go b/chaosmeta-inject-operator/pkg/executor/remoteexecutor/agentexecutor/agentexecutor.go index 3fe45b3..8f7a9b1 100644 --- a/chaosmeta-inject-operator/pkg/executor/remoteexecutor/agentexecutor/agentexecutor.go +++ b/chaosmeta-inject-operator/pkg/executor/remoteexecutor/agentexecutor/agentexecutor.go @@ -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 { @@ -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 { diff --git a/chaosmeta-inject-operator/pkg/executor/remoteexecutor/daemonsetexecutor/daemonsetexecutor.go b/chaosmeta-inject-operator/pkg/executor/remoteexecutor/daemonsetexecutor/daemonsetexecutor.go index 21eb465..cc5d8d2 100644 --- a/chaosmeta-inject-operator/pkg/executor/remoteexecutor/daemonsetexecutor/daemonsetexecutor.go +++ b/chaosmeta-inject-operator/pkg/executor/remoteexecutor/daemonsetexecutor/daemonsetexecutor.go @@ -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 { @@ -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) } diff --git a/chaosmetad/build/Dockerfile b/chaosmetad/build/Dockerfile new file mode 100644 index 0000000..beae203 --- /dev/null +++ b/chaosmetad/build/Dockerfile @@ -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 diff --git a/chaosmetad/build/ci/build.sh b/chaosmetad/build/ci/build.sh index f7d3758..0332c76 100644 --- a/chaosmetad/build/ci/build.sh +++ b/chaosmetad/build/ci/build.sh @@ -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 @@ -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}/ diff --git a/chaosmetad/pkg/injector/jvm/methoddelay.go b/chaosmetad/pkg/injector/jvm/methoddelay.go index 6461425..3361fb3 100644 --- a/chaosmetad/pkg/injector/jvm/methoddelay.go +++ b/chaosmetad/pkg/injector/jvm/methoddelay.go @@ -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 { diff --git a/chaosmetad/pkg/utils/cmdexec/cmd.go b/chaosmetad/pkg/utils/cmdexec/cmd.go index 709b7ab..7896283 100644 --- a/chaosmetad/pkg/utils/cmdexec/cmd.go +++ b/chaosmetad/pkg/utils/cmdexec/cmd.go @@ -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) } diff --git a/chaosmetad/tools/jvm/MANIFEST.MF b/chaosmetad/tools/jvm/MANIFEST.MF index b6c022b..2212d6a 100644 --- a/chaosmetad/tools/jvm/MANIFEST.MF +++ b/chaosmetad/tools/jvm/MANIFEST.MF @@ -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