Skip to content

Commit 137575d

Browse files
committed
Using jq to parse the default CNI for improved script robustness
1 parent 3895e33 commit 137575d

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

charts/spiderpool/templates/configmap.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,14 @@ data:
172172
cat /host/etc/cni/net.d/${DEFAULT_CNI_FILEPATH}
173173
174174
echo ""
175-
DEFAULT_CNI_NAME=$(grep '"name":' ${CNI_CONF_DIR}/${DEFAULT_CNI_FILEPATH} | awk '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | tr -d ',' | tr -d '"')
175+
176+
DEFAULT_CNI_NAME=$(jq -r '.name' ${CNI_CONF_DIR}/${DEFAULT_CNI_FILEPATH})
176177
if [ -z "$DEFAULT_CNI_NAME" ] ; then
177178
error "The name fleid shouldn't be empty, please check the default cni: ${DEFAULT_CNI_FILEPATH}" && exit 1
178179
fi
179180
180181
log "Updating the clusterNetwork of the multus-cni config to $DEFAULT_CNI_NAME"
181-
sed -i "s?\"clusterNetwork\": \"\"?\"clusterNetwork\": \"${DEFAULT_CNI_NAME}\"?g" /tmp/00-multus.conf
182+
jq ".clusterNetwork=\"${DEFAULT_CNI_NAME}\"" /tmp/00-multus.conf > /tmp/00-multus.conf.tmp && mv /tmp/00-multus.conf.tmp /tmp/00-multus.conf
182183
else
183184
log "User set multus ClusterNetwork: $MULTUS_CLUSTER_NETWORK"
184185
fi

images/spiderpool-base/install-others.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ packages=(
1414
libmnl0
1515
bash-completion
1616
iptables
17+
jq
1718
)
1819

1920

0 commit comments

Comments
 (0)