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

OKG Network Information Getting Shell Script Update #212

Merged
merged 1 commit into from
Sep 25, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,33 @@ func getNetwork() {

```

在获取网络信息时,可能面临着网络状态未准备好的情况,可以在程序中加入一个循环,持续检测网络状态,直至网络状态为Ready后获取网络信息数据。以下是相应的shell脚本。

```shell
# 初始化JSON字符串为空
json=''

# 循环直到拿到数据
while [ -z "$json" ]; do
# 从文件中读取JSON字符串
json=$(cat /etc/podinfo/network)

# 检查currentNetworkState是否为Ready
currentNetworkState=$(echo $json | jq -r '.currentNetworkState')
if [ "$currentNetworkState" != "Ready" ]; then
echo "currentNetworkState is not Ready, sleeping 1 second..."
sleep 1
json=''
fi
done

# 解析externalAddresses的ip和port
echo "externalAddresses:"
ip=$(echo $json | jq -r '.externalAddresses[0].ip')
port=$(echo $json | jq -r '.externalAddresses[0].ports[0].port')
echo " IP: $ip, Port: $port"
```

## FAQ

Q: 如何更改网络插件配置?
Expand Down
27 changes: 27 additions & 0 deletions kruisegame/user-manuals/network.md
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,33 @@ func getNetwork() {

```

When getting network information, you may face the situation that the network status is not ready, you can add a loop in the programme to continuously detect the network status until the network status is Ready and then get the network information data. The following is the corresponding shell script.

```shell
# Initialise JSON string to empty
json=''

# Loop until you get the data
while [ -z "$json" ]; do
# Reading a JSON string from a file
json=$(cat /etc/podinfo/network)

# Check if currentNetworkState is Ready
currentNetworkState=$(echo $json | jq -r '.currentNetworkState')
if [ "$currentNetworkState" != "Ready" ]; then
echo "currentNetworkState is not Ready, sleeping 1 second..."
sleep 1
json=''
fi
done

# Parsing the ip and port of externalAddresses
echo "externalAddresses:"
ip=$(echo $json | jq -r '.externalAddresses[0].ip')
port=$(echo $json | jq -r '.externalAddresses[0].ports[0].port')
echo " IP: $ip, Port: $port"
```

## FAQ

Q: How to change the network plugin configuration?
Expand Down
Loading