mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-08-25 03:22:00 +00:00
Add the option to auto generate 00-multus.conf
When `--multus-conf-file=auto` is used, 00-multus.conf will be automatically generated from the CNI configuration file of the master plugin (the first file in lexicographical order in cni-conf-dir).
This commit is contained in:
parent
e9aa18319d
commit
bae3adf158
@ -31,10 +31,12 @@ You can get get help with the `--help` flag.
|
|||||||
```
|
```
|
||||||
$ ./entrypoint.sh --help
|
$ ./entrypoint.sh --help
|
||||||
|
|
||||||
This is an entrypoint script for Multus CNI to overlay its
|
This is an entrypoint script for Multus CNI to overlay its binary and
|
||||||
binary and configuration into locations in a filesystem.
|
configuration into locations in a filesystem. The configuration & binary file
|
||||||
The configuration & binary file will be copied to the
|
will be copied to the corresponding configuration directory. When
|
||||||
corresponding configuration directory.
|
`--multus-conf-file=auto` is used, 00-multus.conf will be automatically
|
||||||
|
generated from the CNI configuration file of the master plugin (the first file
|
||||||
|
in lexicographical order in cni-conf-dir).
|
||||||
|
|
||||||
./entrypoint.sh
|
./entrypoint.sh
|
||||||
-h --help
|
-h --help
|
||||||
@ -42,6 +44,7 @@ corresponding configuration directory.
|
|||||||
--cni-bin-dir=/host/opt/cni/bin
|
--cni-bin-dir=/host/opt/cni/bin
|
||||||
--multus-conf-file=/usr/src/multus-cni/images/70-multus.conf
|
--multus-conf-file=/usr/src/multus-cni/images/70-multus.conf
|
||||||
--multus-bin-file=/usr/src/multus-cni/bin/multus
|
--multus-bin-file=/usr/src/multus-cni/bin/multus
|
||||||
|
--multus-kubeconfig-file-host=/etc/cni/net.d/multus.d/multus.kubeconfig
|
||||||
```
|
```
|
||||||
|
|
||||||
You must use an `=` to delimit the parameter name and the value. For example you may set a custom `cni-conf-dir` like so:
|
You must use an `=` to delimit the parameter name and the value. For example you may set a custom `cni-conf-dir` like so:
|
||||||
@ -59,7 +62,7 @@ Note: You'll noticed that there's a `/host/...` directory from the root for the
|
|||||||
Example docker run command:
|
Example docker run command:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ docker run -it -v /opt/cni/bin/:/host/opt/cni/bin/ -v /etc/cni/net.d/:/host/etc/cni/net.d/ --entrypoint=/bin/bash dougbtv/multus
|
$ docker run -it -v /opt/cni/bin/:/host/opt/cni/bin/ -v /etc/cni/net.d/:/host/etc/cni/net.d/ --entrypoint=/bin/bash dougbtv/multus
|
||||||
```
|
```
|
||||||
|
|
||||||
Originally inspired by and is a portmanteau of the [Flannel daemonset](https://github.com/coreos/flannel/blob/master/Documentation/kube-flannel.yml), the [Calico Daemonset](https://github.com/projectcalico/calico/blob/master/v2.0/getting-started/kubernetes/installation/hosted/k8s-backend-addon-manager/calico-daemonset.yaml), and the [Calico CNI install bash script](https://github.com/projectcalico/cni-plugin/blob/be4df4db2e47aa7378b1bdf6933724bac1f348d0/k8s-install/scripts/install-cni.sh#L104-L153).
|
Originally inspired by and is a portmanteau of the [Flannel daemonset](https://github.com/coreos/flannel/blob/master/Documentation/kube-flannel.yml), the [Calico Daemonset](https://github.com/projectcalico/calico/blob/master/v2.0/getting-started/kubernetes/installation/hosted/k8s-backend-addon-manager/calico-daemonset.yaml), and the [Calico CNI install bash script](https://github.com/projectcalico/cni-plugin/blob/be4df4db2e47aa7378b1bdf6933724bac1f348d0/k8s-install/scripts/install-cni.sh#L104-L153).
|
||||||
|
@ -8,14 +8,17 @@ CNI_CONF_DIR="/host/etc/cni/net.d"
|
|||||||
CNI_BIN_DIR="/host/opt/cni/bin"
|
CNI_BIN_DIR="/host/opt/cni/bin"
|
||||||
MULTUS_CONF_FILE="/usr/src/multus-cni/images/70-multus.conf"
|
MULTUS_CONF_FILE="/usr/src/multus-cni/images/70-multus.conf"
|
||||||
MULTUS_BIN_FILE="/usr/src/multus-cni/bin/multus"
|
MULTUS_BIN_FILE="/usr/src/multus-cni/bin/multus"
|
||||||
|
MULTUS_KUBECONFIG_FILE_HOST="/etc/cni/net.d/multus.d/multus.kubeconfig"
|
||||||
|
|
||||||
# Give help text for parameters.
|
# Give help text for parameters.
|
||||||
function usage()
|
function usage()
|
||||||
{
|
{
|
||||||
echo -e "This is an entrypoint script for Multus CNI to overlay its"
|
echo -e "This is an entrypoint script for Multus CNI to overlay its binary and "
|
||||||
echo -e "binary and configuration into locations in a filesystem."
|
echo -e "configuration into locations in a filesystem. The configuration & binary file "
|
||||||
echo -e "The configuration & binary file will be copied to the "
|
echo -e "will be copied to the corresponding configuration directory. When "
|
||||||
echo -e "corresponding configuration directory."
|
echo -e "`--multus-conf-file=auto` is used, 00-multus.conf will be automatically "
|
||||||
|
echo -e "generated from the CNI configuration file of the master plugin (the first file "
|
||||||
|
echo -e "in lexicographical order in cni-conf-dir)."
|
||||||
echo -e ""
|
echo -e ""
|
||||||
echo -e "./entrypoint.sh"
|
echo -e "./entrypoint.sh"
|
||||||
echo -e "\t-h --help"
|
echo -e "\t-h --help"
|
||||||
@ -23,6 +26,7 @@ function usage()
|
|||||||
echo -e "\t--cni-bin-dir=$CNI_BIN_DIR"
|
echo -e "\t--cni-bin-dir=$CNI_BIN_DIR"
|
||||||
echo -e "\t--multus-conf-file=$MULTUS_CONF_FILE"
|
echo -e "\t--multus-conf-file=$MULTUS_CONF_FILE"
|
||||||
echo -e "\t--multus-bin-file=$MULTUS_BIN_FILE"
|
echo -e "\t--multus-bin-file=$MULTUS_BIN_FILE"
|
||||||
|
echo -e "\t--multus-kubeconfig-file-host=$MULTUS_KUBECONFIG_FILE_HOST"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parse parameters given as arguments to this script.
|
# Parse parameters given as arguments to this script.
|
||||||
@ -46,6 +50,9 @@ while [ "$1" != "" ]; do
|
|||||||
--multus-bin-file)
|
--multus-bin-file)
|
||||||
MULTUS_BIN_FILE=$VALUE
|
MULTUS_BIN_FILE=$VALUE
|
||||||
;;
|
;;
|
||||||
|
--multus-kubeconfig-file-host)
|
||||||
|
MULTUS_KUBECONFIG_FILE_HOST=$VALUE
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "ERROR: unknown parameter \"$PARAM\""
|
echo "ERROR: unknown parameter \"$PARAM\""
|
||||||
usage
|
usage
|
||||||
@ -57,7 +64,11 @@ done
|
|||||||
|
|
||||||
|
|
||||||
# Create array of known locations
|
# Create array of known locations
|
||||||
declare -a arr=($CNI_CONF_DIR $CNI_BIN_DIR $MULTUS_CONF_FILE $MULTUS_BIN_FILE)
|
declare -a arr=($CNI_CONF_DIR $CNI_BIN_DIR $MULTUS_BIN_FILE)
|
||||||
|
if [ "$MULTUS_CONF_FILE" != "auto" ]; then
|
||||||
|
arr+=($MULTUS_BIN_FILE)
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Loop through and verify each location each.
|
# Loop through and verify each location each.
|
||||||
for i in "${arr[@]}"
|
for i in "${arr[@]}"
|
||||||
@ -69,8 +80,10 @@ do
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Copy files into proper places.
|
# Copy files into proper places.
|
||||||
cp -f $MULTUS_CONF_FILE $CNI_CONF_DIR
|
|
||||||
cp -f $MULTUS_BIN_FILE $CNI_BIN_DIR
|
cp -f $MULTUS_BIN_FILE $CNI_BIN_DIR
|
||||||
|
if [ "$MULTUS_CONF_FILE" != "auto" ]; then
|
||||||
|
cp -f $MULTUS_CONF_FILE $CNI_CONF_DIR
|
||||||
|
fi
|
||||||
|
|
||||||
# Make a multus.d directory (for our kubeconfig)
|
# Make a multus.d directory (for our kubeconfig)
|
||||||
|
|
||||||
@ -134,6 +147,35 @@ fi
|
|||||||
|
|
||||||
# ---------------------- end Generate a "kube-config".
|
# ---------------------- end Generate a "kube-config".
|
||||||
|
|
||||||
|
# ------------------------------- Generate "00-multus.conf"
|
||||||
|
|
||||||
|
if [ "$MULTUS_CONF_FILE" == "auto" ]; then
|
||||||
|
echo "Generating Multus configuration file ..."
|
||||||
|
MASTER_PLUGIN="$(ls $CNI_CONF_DIR | grep .conf | head -1)"
|
||||||
|
if [ "$MASTER_PLUGIN" == "" ]; then
|
||||||
|
echo "Error: Multus could not be configured: no master plugin was found."
|
||||||
|
exit 1;
|
||||||
|
elif [ "$MASTER_PLUGIN" == "00-multus.conf" ]; then
|
||||||
|
echo "Warning: Multus is already configured: auto configuration skipped."
|
||||||
|
else
|
||||||
|
MASTER_PLUGIN_JSON="$(cat $CNI_CONF_DIR/$MASTER_PLUGIN)"
|
||||||
|
CONF=$(cat <<-EOF
|
||||||
|
{
|
||||||
|
"name": "multus-cni-network",
|
||||||
|
"type": "multus",
|
||||||
|
"kubeconfig": "$MULTUS_KUBECONFIG_FILE_HOST",
|
||||||
|
"delegates": [
|
||||||
|
$MASTER_PLUGIN_JSON
|
||||||
|
]
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
echo $CONF > $CNI_CONF_DIR/00-multus.conf
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ---------------------- end Generate "00-multus.conf".
|
||||||
|
|
||||||
echo "Entering sleep... (success)"
|
echo "Entering sleep... (success)"
|
||||||
|
|
||||||
# Sleep forever.
|
# Sleep forever.
|
||||||
|
Loading…
Reference in New Issue
Block a user