Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(debug): change IOMesh_DATA_CIDR to HOST_NETWORK_CIDR #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/debugtool.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions image/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
38 changes: 38 additions & 0 deletions image/debugtool_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions pkg/fixture/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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: "",
},
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/network/hostnetwork/host_network_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
},
},
Expand Down