diff --git a/docs/debugtool.gif b/docs/debugtool.gif new file mode 100644 index 0000000..0e76ec6 Binary files /dev/null and b/docs/debugtool.gif differ diff --git a/go.mod b/go.mod index 1aa2435..d696dab 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/briandowns/spinner v1.15.0 github.com/enescakir/emoji v1.0.0 github.com/go-logr/logr v0.4.0 - github.com/iomesh/operator v0.9.8 + github.com/iomesh/operator v0.9.8 // indirect github.com/spf13/cobra v1.1.1 k8s.io/api v0.20.2 k8s.io/apimachinery v0.20.2 diff --git a/image/Dockerfile b/image/Dockerfile new file mode 100644 index 0000000..0934a15 --- /dev/null +++ b/image/Dockerfile @@ -0,0 +1,7 @@ +FROM alpine:latest + +RUN apk add --no-cache iperf3 bash bind-tools + +COPY debugtool_entrypoint.sh /usr/bin/debugtool_entrypoint.sh + +ENTRYPOINT ["bash","-x","/usr/bin/debugtool_entrypoint.sh"] diff --git a/image/debugtool_entrypoint.sh b/image/debugtool_entrypoint.sh new file mode 100755 index 0000000..b02e160 --- /dev/null +++ b/image/debugtool_entrypoint.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +set -xeuo + +select_ip_by_cidr() { + cidr=$1 + cidr_network=$(ipcalc -n "$cidr" | cut -f2 -d=) + cidr_prefix=$(ipcalc -p "$cidr" | cut -f2 -d=) + + IFS=' ' read -r -a ips <<<"$(echo $(ip addr show | grep inet | grep -v inet6 | awk '{print $2}'))" + results=() + for ip in ${ips[@]}; do + ip_network="$(ipcalc -n $(echo ${ip} | awk -F'/' '{print $1}')/${cidr_prefix} | cut -f2 -d=)" + + if [ "$ip_network" = "$cidr_network" ]; then + results+=("$(echo ${ip} | awk -F'/' '{print $1}')") + fi + done + if [ "${#results[@]}" -gt 1 ]; then + echo "[ERROR] get more than 1 ip with cidr ${cidr}" >&2 + return + fi + echo "${results[0]}" +} + +if [[ -z $HOST_NETWORK_CIDR ]]; then + IPERF_BIND_ADDR="0.0.0.0" +else + IPERF_BIND_ADDR=$(select_ip_by_cidr "$HOST_NETWORK_CIDR") + if [[ -z "$IPERF_BIND_ADDR" ]]; then + echo "warning IPERF_BIND_ADDR is empty" + fi +fi + +echo $IPERF_BIND_ADDR > /opt/iperf_bind_addr + +export IPERF_BIND_ADDR + +iperf3 -s -B $IPERF_BIND_ADDR diff --git a/pkg/fixture/fixture.go b/pkg/fixture/fixture.go index 9a1a1fe..fa41abd 100644 --- a/pkg/fixture/fixture.go +++ b/pkg/fixture/fixture.go @@ -116,10 +116,10 @@ func (f Fixture) Cleanup() error { } func (f Fixture) BasicCheckerDaemonSet(namespace, name string) (*appsv1.DaemonSet, error) { - dataCIRD := os.Getenv("IOMESH_DATA_CIDR") + dataCIRD := os.Getenv("HOST_NETWORK_CIDR") _, _, err := net.ParseCIDR(dataCIRD) if err != nil { - return nil, errors.New("IOMESH_DATA_CIDR is not the correct cidr format. example: IOMESH_DATA_CIDR=192.168.1.0/24") + return nil, errors.New("HOST_NETWORK_CIDR is not the correct cidr format. example: HOST_NETWORK_CIDR=192.168.1.0/24") } ds := kutils.NewDaemonSet(namespace, name) labels := map[string]string{ @@ -135,7 +135,7 @@ func (f Fixture) BasicCheckerDaemonSet(namespace, name string) (*appsv1.DaemonSe Image: constant.DebugToolsImage, Env: []corev1.EnvVar{ { - Name: "DATA_CIDR", + Name: "HOST_NETWORK_CIDR", Value: "", }, }, diff --git a/pkg/network/hostnetwork/host_network_checker.go b/pkg/network/hostnetwork/host_network_checker.go index 30d46fc..a561fc3 100644 --- a/pkg/network/hostnetwork/host_network_checker.go +++ b/pkg/network/hostnetwork/host_network_checker.go @@ -124,10 +124,10 @@ func (hc HostNetworkChecker) GetBandwidth() error { } func (hc HostNetworkChecker) HostNetworkCheckerDaemonSet(namespace, name string) (*appsv1.DaemonSet, error) { - dataCIRD := os.Getenv("IOMESH_DATA_CIDR") + dataCIRD := os.Getenv("HOST_NETWORK_CIDR") _, _, err := net.ParseCIDR(dataCIRD) if err != nil { - return nil, errors.New("IOMESH_DATA_CIDR is not the correct cidr format. example: IOMESH_DATA_CIDR=192.168.1.0/24") + return nil, errors.New("HOST_NETWORK_CIDR is not the correct cidr format. example: HOST_NETWORK_CIDR=192.168.1.0/24") } ds := kutils.NewDaemonSet(namespace, name) labels := map[string]string{ @@ -144,7 +144,7 @@ func (hc HostNetworkChecker) HostNetworkCheckerDaemonSet(namespace, name string) Image: constant.DebugToolsImage, Env: []corev1.EnvVar{ { - Name: "DATA_CIDR", + Name: "HOST_NETWORK_CIDR", Value: dataCIRD, }, },