Skip to content

Commit

Permalink
multus: entrypoint: disallow using cni version <= 0.3.1 with >= 0.4.0
Browse files Browse the repository at this point in the history
When nested CNI version is 0.3.1 or less while the top level CNI version
is 0.4.0, error out. Version 0.3.1 or less doesn't support the CHECK
command. This closes issue #737.
  • Loading branch information
bn222 committed Dec 14, 2021
1 parent 4d9731b commit a374543
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions images/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,24 @@ if ! type python3 &> /dev/null; then
alias python=python3
fi

function checkCniVersion {
cniversion_python_tmpfile=$(mktemp)
cat << EOF > $cniversion_python_tmpfile
import json, sys
def version(v):
return [int(x) for x in v.split(".")]
top_level = sys.argv[2]
with open(sys.argv[1], "r") as f:
nested = json.load(f)["cniVersion"]
if version(nested) <= version("0.3.1") and version(top_level) >= version("0.4.0"):
msg = "Multus cni version is %s while master plugin cni version is %s"
print(msg % (top_level, nested))
EOF
python $cniversion_python_tmpfile $1 $2
}

# Parse parameters given as arguments to this script.
while [ "$1" != "" ]; do
PARAM=`echo $1 | awk -F= '{print $1}'`
Expand Down Expand Up @@ -374,6 +392,12 @@ EOF
MASTER_PLUGIN_LOCATION=$MULTUS_AUTOCONF_DIR/$MASTER_PLUGIN
MASTER_PLUGIN_JSON="$(cat $MASTER_PLUGIN_LOCATION)"
log "Using $MASTER_PLUGIN_LOCATION as a source to generate the Multus configuration"
CHECK_CNI_VERSION=$(checkCniVersion $MASTER_PLUGIN_LOCATION $CNI_VERSION)
if [ "$CHECK_CNI_VERSION" != "" ] ; then
error "$CHECK_CNI_VERSION"
exit 1
fi

CONF=$(cat <<-EOF
{
$CNI_VERSION_STRING
Expand Down

0 comments on commit a374543

Please sign in to comment.