diff --git a/.idea/workspace.xml b/.idea/workspace.xml index bbd6e3e..fd1b36b 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,11 +2,21 @@ + + + + + + + + + - + + + + - - + @@ -41,18 +56,11 @@ - + - - - - - - - @@ -60,8 +68,15 @@ + + + + + + + - + @@ -87,8 +102,15 @@ + + + + + + + @@ -246,87 +268,40 @@ true - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - - - - + + + + - - - - - - - - - - - + + diff --git a/Makefile b/Makefile index c0e87aa..dd5d409 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,23 @@ .PHONE: build clean -export AGENT_VERSION = 1.0.0 +export AGENT_VERSION = 1.0.2 export BLADE_VERSION = 1.5.0 BLADE_SRC_ROOT=$(shell pwd) -BUILD_BINARY_PATH=build/build_binary -BUILD_HELM_PATH=build/helm3/chaos_agent -BUILD_IMAGE_PATH=build/build_image -BUILD_TARGET_PKG_DIR=$(BUILD_IMAGE_PATH) +BUILD_BINARY_MUSL_PATH=build/binary_musl +BUILD_BINARY_ARM64_PATH=build/binary_arm +BUILD_IMAGE_MUSL_PATH=build/image_musl +BUILD_IMAGE_ARM64_PATH=build/image_arm + + +BUILD_HELM_PATH=build/helm3/chaos-agent/ +BUILD_BINARY_PATH=build VERSION_PKG=github.com/chaosblade-io/chaos-agent/version GO_ENV=CGO_ENABLED=1 GO_MODULE=GO111MODULE=on +#GO_PROXY=GOPROXY=https://mirrors.aliyun.com/goproxy/ GO=env $(GO_ENV) $(GO_MODULE) go #GO_X_FLAGS=-X ${VERSION_PKG}.AgentVersion=$(AGENT_VERSION) -X '${VERSION_PKG}.Env=`uname -mv`' -X '${VERSION_PKG}.BuildTime=`date`' GO_FLAGS=-ldflags="-s -w" @@ -23,21 +28,37 @@ endif build: build_binary -build_darwin: pre_build build_binary build_image +build_darwin: pre_build build_binary build_image build_chart build_binary: cmd/chaos_agent.go - $(GO) build $(GO_FLAGS) -o $(BUILD_TARGET_PKG_DIR)/agent $< + $(GO) build $(GO_FLAGS) -o $(BUILD_BINARY_PATH)/agent $< build_linux: - docker build -f $(BUILD_BINARY_PATH)/Dockerfile -t agent-build-musl:latest $(BUILD_BINARY_PATH) + docker build -f $(BUILD_BINARY_MUSL_PATH)/Dockerfile -t agent-build-musl:latest $(BUILD_BINARY_MUSL_PATH) docker run --rm \ -v $(shell echo -n ${GOPATH}):/go \ -w /chaos-agent \ -v $(BLADE_SRC_ROOT):/chaos-agent \ agent-build-musl:latest +build_arm64: + docker build -f $(BUILD_BINARY_ARM64_PATH)/Dockerfile -t agent-build-arm:latest $(BUILD_BINARY_ARM64_PATH) + docker run --rm \ + -v $(shell echo -n ${GOPATH}):/go \ + -w /chaos-agent \ + -v $(BLADE_SRC_ROOT):/chaos-agent \ + agent-build-arm:latest -build_image: +build_chart: helm package $(BUILD_HELM_PATH) - cd $(BUILD_IMAGE_PATH) - docker build --pull --build-arg BLADE_VERSION=${BLADE_VERSION} -f $(BUILD_IMAGE_PATH)/Dockerfile \ - -t chaos-agent:$(AGENT_VERSION) $(BLADE_SRC_ROOT)/$(BUILD_IMAGE_PATH) + +build_image: + rm -rf $(BUILD_IMAGE_MUSL_PATH)/agent + cp $(BUILD_BINARY_PATH)/agent $(BUILD_IMAGE_MUSL_PATH) + docker build --pull --build-arg BLADE_VERSION=${BLADE_VERSION} -f $(BUILD_IMAGE_MUSL_PATH)/Dockerfile \ + -t chaosbladeio/chaosblade-agent:$(AGENT_VERSION) $(BLADE_SRC_ROOT)/$(BUILD_IMAGE_MUSL_PATH) + +build_image_arm: + rm -rf $(BUILD_IMAGE_ARM64_PATH)/agent + cp $(BUILD_BINARY_PATH)/agent $(BUILD_IMAGE_ARM64_PATH) + docker build --pull --build-arg BLADE_VERSION=${BLADE_VERSION} -f $(BUILD_IMAGE_ARM64_PATH)/Dockerfile \ + -t chaosbladeio/chaosblade-agent-arm64:$(AGENT_VERSION) $(BLADE_SRC_ROOT)/$(BUILD_IMAGE_ARM64_PATH) diff --git a/build/binary_arm/Dockerfile b/build/binary_arm/Dockerfile new file mode 100644 index 0000000..21a65e0 --- /dev/null +++ b/build/binary_arm/Dockerfile @@ -0,0 +1,28 @@ +FROM multiarch/ubuntu-debootstrap:arm64-bionic +LABEL maintainer="Mingxia Cai" + +# install gcc make git +RUN apt-get update \ + && apt-get install -y build-essential git + +# The image is used to build chaosblade for musl +RUN wget http://www.musl-libc.org/releases/musl-1.1.21.tar.gz \ + && tar -zxvf musl-1.1.21.tar.gz \ + && rm musl-1.1.21.tar.gz \ + && cd musl* \ + && ./configure \ + && make \ + && make install \ + && rm -rf musl* + +# install go +RUN wget https://dl.google.com/go/go1.13.10.linux-arm64.tar.gz \ + && tar -C /usr/local -xzf go1.13.10.linux-arm64.tar.gz \ + && rm -rf go1.13.10.linux-arm64.tar.gz + +ENV CC /usr/local/musl/bin/musl-gcc +ENV GOOS linux +ENV PATH /usr/local/go/bin:$PATH + + +ENTRYPOINT [ "make" ] diff --git a/build/build_binary/Dockerfile b/build/binary_musl/Dockerfile similarity index 100% rename from build/build_binary/Dockerfile rename to build/binary_musl/Dockerfile diff --git a/build/helm3/chaos-agent-arm/.helmignore b/build/helm3/chaos-agent-arm/.helmignore new file mode 100644 index 0000000..f0c1319 --- /dev/null +++ b/build/helm3/chaos-agent-arm/.helmignore @@ -0,0 +1,21 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj diff --git a/build/helm3/chaos-agent-arm/Chart.yaml b/build/helm3/chaos-agent-arm/Chart.yaml new file mode 100644 index 0000000..e03db3c --- /dev/null +++ b/build/helm3/chaos-agent-arm/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +appVersion: "1.0.2" +description: A SaaS-based service that aims to improve the high availability of your applications. +name: chaosblade-box-agent +version: 1.0.2 +home: https://www.alibabacloud.com/products/chaos diff --git a/build/helm3/chaos-agent-arm/templates/NOTES.txt b/build/helm3/chaos-agent-arm/templates/NOTES.txt new file mode 100644 index 0000000..576c4b8 --- /dev/null +++ b/build/helm3/chaos-agent-arm/templates/NOTES.txt @@ -0,0 +1,2 @@ +Thank you for using the {{ .Release.Name }} service, you can check the service installation status by the following command: + kubectl get pods -n {{ .Release.Namespace }}. \ No newline at end of file diff --git a/build/helm3/chaos-agent-arm/templates/_helpers.tpl b/build/helm3/chaos-agent-arm/templates/_helpers.tpl new file mode 100644 index 0000000..28fade8 --- /dev/null +++ b/build/helm3/chaos-agent-arm/templates/_helpers.tpl @@ -0,0 +1 @@ +{{/* vim: set filetype=mustache: */}} \ No newline at end of file diff --git a/build/helm3/chaos-agent-arm/templates/ahas_deployment.yaml b/build/helm3/chaos-agent-arm/templates/ahas_deployment.yaml new file mode 100644 index 0000000..cf6cd99 --- /dev/null +++ b/build/helm3/chaos-agent-arm/templates/ahas_deployment.yaml @@ -0,0 +1,121 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: chaos-agent + labels: + name: chaos-agent + app: chaos-agent +spec: + selector: + matchLabels: + name: chaos-agent + template: + metadata: + labels: + name: chaos-agent + spec: + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: type + operator: NotIn + values: + - virtual-kubelet + containers: + - name: chaos-agent + image: {{ .Values.images.chaos.repository }}:{{ .Values.images.chaos.version }} + imagePullPolicy: {{ .Values.images.chaos.pullPolicy }} + env: + - name: KUBERNETES_NODENAME + valueFrom: + fieldRef: + fieldPath: spec.nodeName + - name: DOCKER_API_VERSION + value: "1.14.0" + args: + {{- if .Values.license }} + - '--license={{ .Values.license }}' + {{- end }} + {{- if .Values.env.mode }} + - '--agent.mode={{ .Values.env.mode }}' + {{- end }} + {{- if .Values.env.name }} + - '--namespace={{ .Values.env.name }}' + {{- end }} + {{- if .Values.env.debug }} + - '--debug' + {{- end }} + {{- if .Values.controller.cluster_id }} + - '--kubernetes.cluster.id={{ .Values.controller.cluster_id }}' + {{- end }} + {{- if .Values.controller.cluster_name }} + - '--kubernetes.cluster.name={{ .Values.controller.cluster_name }}' + {{- end }} + {{- if .Values.controller.cluster_type }} + - '--kubernetes.cluster.type={{ .Values.controller.cluster_type }}' + {{- end }} + {{- if .Values.transport.endpoint }} + - '--transport.endpoint={{ .Values.transport.endpoint }}' + {{ end }} + - '--kubernetes.pod.report=true' + - '--kubernetes.externalIp.enable={{ .Values.controller.externalIp_enable }}' + securityContext: + privileged: true + resources: + requests: + cpu: 0.05 + memory: 200Mi + limits: + cpu: 0.2 + memory: 300Mi + volumeMounts: + - mountPath: /var/run/docker.sock + name: docker-socket + - mountPath: /etc/hosts + name: hosts + - mountPath: /run/containerd + name: containerd + - mountPath: /var/lib/containerd + name: containerd-lib + - mountPath: /etc/containerd + name: containerd-etc + + dnsPolicy: ClusterFirstWithHostNet + hostNetwork: true + hostPID: true + tolerations: + - effect: NoSchedule + operator: Exists + volumes: + - hostPath: + path: /var/run/docker.sock + name: docker-socket + - hostPath: + path: /etc/hosts + name: hosts + - hostPath: + path: /run/containerd + name: containerd + - hostPath: + path: /var/lib/containerd + name: containerd-lib + - hostPath: + path: /etc/containerd + name: containerd-etc + serviceAccountName: chaos-agent + +--- +kind: Service +apiVersion: v1 +metadata: + name: chaos-agent +spec: + type: LoadBalancer + ports: + - name: http + port: {{ .Values.transport.port }} + targetPort: {{ .Values.transport.port }} + selector: + name: chaos-agent \ No newline at end of file diff --git a/build/helm3/chaos-agent-arm/templates/rbac.yaml b/build/helm3/chaos-agent-arm/templates/rbac.yaml new file mode 100644 index 0000000..3f9d445 --- /dev/null +++ b/build/helm3/chaos-agent-arm/templates/rbac.yaml @@ -0,0 +1,134 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + labels: + name: chaos-agent + +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + labels: + name: chaos-agent +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: chaos-agent +subjects: + - kind: ServiceAccount + name: chaos-agent + namespace: {{ .Release.Namespace }} + +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: chaos-agent +rules: + - apiGroups: + - '' + resources: + - pods + - pods/exec + - services + - endpoints + - configmaps + - secrets + - nodes + - namespaces + - persistentvolumes + - persistentvolumeclaims + - events + - serviceaccounts + - chaosexperiments + - chaosengines + verbs: + - "*" + - apiGroups: + - apps + resources: + - deployments + - daemonsets + - replicasets + - statefulsets + verbs: + - "*" + - apiGroups: + - batch + resources: + - cronjobs + - jobs + verbs: + - get + - list + - watch + - apiGroups: + - extensions + resources: + - deployments + - daemonsets + - replicasets + - statefulsets + - ingresses + verbs: + - "*" + - apiGroups: + - networking.k8s.io + resources: + - ingresses + verbs: + - get + - list + - watch + - apiGroups: + - storage.k8s.io + resources: + - storageclasses + verbs: + - get + - list + - watch + - apiGroups: + - chaosblade.io + resources: + - chaosblades + - chaosblades/status + verbs: + - "*" + - apiGroups: + - litmuschaos.io + resources: + - chaosexperiments + - chaosengines + - chaosresults + verbs: + - "*" + - apiGroups: + - apiextensions.k8s.io + resources: + - customresourcedefinitions + verbs: + - "*" + - apiGroups: + - rbac.authorization.k8s.io + resources: + - clusterroles + - clusterrolebindings + - roles + - rolebindings + verbs: + - "*" + - nonResourceURLs: + - /api + - /api/* + - /apis + - /apis/* + - /healthz + - /openapi + - /openapi/* + - /version + - /version/ + verbs: + - post + - delete + - get \ No newline at end of file diff --git a/build/helm3/chaos-agent-arm/values.yaml b/build/helm3/chaos-agent-arm/values.yaml new file mode 100644 index 0000000..ab6cf26 --- /dev/null +++ b/build/helm3/chaos-agent-arm/values.yaml @@ -0,0 +1,33 @@ +# Default values for chaos. +controller: + # controller.region_id: The region where the cluster is located, currently only support cn-hangzhou, cn-beijing, cn-shenzhen, cn-shanghai and cn-public(public region) + cluster_type: "" + # supported since 1.5.2 version + cluster_id: "" + cluster_name: "" + externalIp_enable: false + +# the image repository is related to the running env" +images: + # chaos agent image named chaos-agent + chaos: + version: 1.0.2 + repository: chaosbladeio/chaosblade-agent-arm64 + # images.chaos.pullPolicy: must be Always|IfNotPresent|Never + pullPolicy: Always + +env: + # env.name: the cluster environment that is running + name: default + type: prod + mode: k8s_helm + debug: "" + qps: 50 + reconcileCount: 50 + logLevel: info + +transport: + endpoint: "" + port: 19527 + +license: "" diff --git a/build/helm3/chaos-agent/Chart.yaml b/build/helm3/chaos-agent/Chart.yaml index 813e885..e03db3c 100644 --- a/build/helm3/chaos-agent/Chart.yaml +++ b/build/helm3/chaos-agent/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v1 -appVersion: "1.0.0" +appVersion: "1.0.2" description: A SaaS-based service that aims to improve the high availability of your applications. name: chaosblade-box-agent -version: 1.0.0 +version: 1.0.2 home: https://www.alibabacloud.com/products/chaos diff --git a/build/helm3/chaos-agent/values.yaml b/build/helm3/chaos-agent/values.yaml index 119ff38..02320e9 100644 --- a/build/helm3/chaos-agent/values.yaml +++ b/build/helm3/chaos-agent/values.yaml @@ -11,8 +11,8 @@ controller: images: # chaos agent image named chaos-agent chaos: - version: 1.0.0 - repository: + version: 1.0.2 + repository: chaosbladeio/chaosblade-agent # images.chaos.pullPolicy: must be Always|IfNotPresent|Never pullPolicy: Always diff --git a/build/image_arm/Dockerfile b/build/image_arm/Dockerfile new file mode 100644 index 0000000..1025fa1 --- /dev/null +++ b/build/image_arm/Dockerfile @@ -0,0 +1,24 @@ +FROM multiarch/alpine:arm64-edge +LABEL maintainer="Mingxia Cai" + +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories + +RUN apk add --update bash iproute2 util-linux curl openssl gcc musl-dev libpcap-dev audit coreutils \ + && mkdir -p /lib/modules/$(uname -r) \ + && rm -rf /var/cache/apk/* + +RUN curl -L https://get.helm.sh/helm-v3.6.0-linux-arm64.tar.gz | tar xz \ + && mv linux-arm64/helm /bin/helm && rm -rf linux-arm64 + +ENV HELM_EXPERIMENTAL_OCI 1 + +WORKDIR /opt +WORKDIR /root/chaos + +COPY ./agent /root/chaos +ARG BLADE_VERSION=0.0.1 + +RUN curl -L https://chaosblade.oss-cn-hangzhou.aliyuncs.com/agent/github/${BLADE_VERSION}/chaosblade-${BLADE_VERSION}-linux-arm64.tar.gz | tar xz \ + && mv chaosblade-${BLADE_VERSION} /opt/chaosblade + +ENTRYPOINT ["/root/chaos/agent"] diff --git a/build/build_image/Dockerfile b/build/image_musl/Dockerfile similarity index 100% rename from build/build_image/Dockerfile rename to build/image_musl/Dockerfile diff --git a/pkg/options/options.go b/pkg/options/options.go index fea6af1..9690768 100644 --- a/pkg/options/options.go +++ b/pkg/options/options.go @@ -208,7 +208,7 @@ func (o *Options) SetOthersByFlags() { o.Ip = o.GetPrivateIp() o.HostName = o.GetHostName() o.InstanceId = o.GetHostName() - o.Version = "1.0.0" + o.Version = "1.0.2" o.InitApplicationInfo(o.ApplicationInstance, o.ApplicationGroup) var err error