2018-07-27 06:51:51 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Always exit on errors.
|
|
|
|
set -e
|
|
|
|
|
2021-02-09 13:28:33 -05:00
|
|
|
# Trap sigterm
|
|
|
|
function exitonsigterm() {
|
|
|
|
echo "Trapped sigterm, exiting."
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
trap exitonsigterm SIGTERM
|
|
|
|
|
2018-07-27 06:51:51 -04:00
|
|
|
# Set our known directories.
|
|
|
|
CNI_CONF_DIR="/host/etc/cni/net.d"
|
2021-11-08 12:06:12 -05:00
|
|
|
CNI_BIN_DIR="/host/opt/cni/bin"
|
2019-09-18 12:17:43 -04:00
|
|
|
ADDITIONAL_BIN_DIR=""
|
2018-07-27 06:51:51 -04:00
|
|
|
MULTUS_CONF_FILE="/usr/src/multus-cni/images/70-multus.conf"
|
2019-04-30 15:10:39 -04:00
|
|
|
MULTUS_AUTOCONF_DIR="/host/etc/cni/net.d"
|
2021-11-08 12:06:12 -05:00
|
|
|
MULTUS_BIN_FILE="/usr/src/multus-cni/bin/multus"
|
2018-10-03 11:28:15 -07:00
|
|
|
MULTUS_KUBECONFIG_FILE_HOST="/etc/cni/net.d/multus.d/multus.kubeconfig"
|
2021-04-29 15:55:58 -04:00
|
|
|
MULTUS_TEMP_KUBECONFIG="/tmp/multus.kubeconfig"
|
2021-05-29 15:29:37 +08:00
|
|
|
MULTUS_MASTER_CNI_FILE_NAME=""
|
2019-01-15 11:21:18 -05:00
|
|
|
MULTUS_NAMESPACE_ISOLATION=false
|
2020-10-29 13:10:12 -04:00
|
|
|
MULTUS_GLOBAL_NAMESPACES=""
|
2021-02-23 15:01:58 -08:00
|
|
|
MULTUS_LOG_TO_STDERR=true
|
2019-03-07 11:01:03 -05:00
|
|
|
MULTUS_LOG_LEVEL=""
|
|
|
|
MULTUS_LOG_FILE=""
|
2020-02-18 15:15:44 -05:00
|
|
|
MULTUS_READINESS_INDICATOR_FILE=""
|
2019-06-27 15:50:28 +09:00
|
|
|
OVERRIDE_NETWORK_NAME=false
|
2019-08-19 15:23:34 -04:00
|
|
|
MULTUS_CLEANUP_CONFIG_ON_EXIT=false
|
2019-08-19 15:31:07 -04:00
|
|
|
RESTART_CRIO=false
|
2019-08-28 13:23:28 -04:00
|
|
|
CRIO_RESTARTED_ONCE=false
|
2019-08-30 18:03:48 -04:00
|
|
|
RENAME_SOURCE_CONFIG_FILE=false
|
2019-11-06 14:08:39 -05:00
|
|
|
SKIP_BINARY_COPY=false
|
2022-03-02 01:55:23 +09:00
|
|
|
FORCE_CNI_VERSION=false # force-cni-version is only for e2e-kind.
|
2018-07-27 06:51:51 -04:00
|
|
|
|
|
|
|
# Give help text for parameters.
|
|
|
|
function usage()
|
|
|
|
{
|
Replace entrypoint script with initcontainers (#718)
* build: install the multus binary in an init container
Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
* build: generate kubeconfig via go
Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
* build: generate multus cni configuration via golang
Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
* build: provide a docker img for daemon based deployments
We will have 2 different images (only on amd64 archs):
- legacy entrypoint script based
- daemonized process
The `image-build` docker action is updated, to build these 2 images.
There will be 2 different deployment specs, along with e2e test
lanes, one for each of the aforementioned alternatives.
Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
* build: delegate CNI config watch loop via golang
For the thick-plugin alternative, provide the watch loop for
configuration regeneration via a golang binary.
Over time, this binary is expected to run the control loop to watch
out for pod updates.
To enable current multus users to chose when they upgrade to this new
deployment setup, these changes are provided in separate multus images,
having a different yaml spec files. Both of these alternatives are
tested e2e, since a new lane is introduced.
The following libraries are introduced, along with the motivation for
adding them:
- dproxy: allows traversing the default network configuration arbitrarily,
similar to what an X path / JSON path tool provides.
Repo is available at [0].
- fsnotify: watch for changes in the default CNI configuration file.
Repo is available at [1].
The config map providing the default network CNI configuration is not
copied over, since originally, the user was not required to install a
default network CNI plugin first, but, nowadays, this is a required
step of multus.
As such, it is no longer required to provide a default CNI
configuration.
[0] - https://github.com/koron/go-dproxy
[1] - https://github.com/fsnotify/fsnotify
Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
* run gofmt
Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
* refactor: make the builder pattern more idiomatic to golang
Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
* build: update github actions to release new imgs
Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
2021-10-27 14:42:37 +02:00
|
|
|
echo -e "This is an entrypoint script for Multus CNI to overlay its configuration into"
|
|
|
|
echo -e "locations in a filesystem. The configuration file will be copied to the"
|
|
|
|
echo -e "corresponding configuration directory. When '--multus-conf-file=auto' is used,"
|
|
|
|
echo -e "00-multus.conf will be automatically generated from the CNI configuration file"
|
|
|
|
echo -e "of the master plugin (the first file in lexicographical order in cni-conf-dir)."
|
|
|
|
echo -e "When '--multus-master-cni-file-name' is used, 00-multus.conf will be"
|
|
|
|
echo -e "automatically generated from the specific file rather than the first file."
|
2018-07-27 06:51:51 -04:00
|
|
|
echo -e ""
|
|
|
|
echo -e "./entrypoint.sh"
|
|
|
|
echo -e "\t-h --help"
|
2021-11-08 17:40:54 +09:00
|
|
|
echo -e "\t--cni-bin-dir=$CNI_BIN_DIR"
|
2018-07-27 06:51:51 -04:00
|
|
|
echo -e "\t--cni-conf-dir=$CNI_CONF_DIR"
|
2019-06-14 17:03:16 +09:00
|
|
|
echo -e "\t--cni-version=<cniVersion (e.g. 0.3.1)>"
|
2018-07-27 06:51:51 -04:00
|
|
|
echo -e "\t--multus-conf-file=$MULTUS_CONF_FILE"
|
2021-11-08 17:40:54 +09:00
|
|
|
echo -e "\t--multus-bin-file=$MULTUS_BIN_FILE"
|
2019-11-06 14:08:39 -05:00
|
|
|
echo -e "\t--skip-multus-binary-copy=$SKIP_BINARY_COPY"
|
2018-10-03 11:28:15 -07:00
|
|
|
echo -e "\t--multus-kubeconfig-file-host=$MULTUS_KUBECONFIG_FILE_HOST"
|
2021-05-29 15:29:37 +08:00
|
|
|
echo -e "\t--multus-master-cni-file-name=$MULTUS_MASTER_CNI_FILE_NAME (empty by default, example: 10-calico.conflist)"
|
2019-01-15 11:21:18 -05:00
|
|
|
echo -e "\t--namespace-isolation=$MULTUS_NAMESPACE_ISOLATION"
|
2020-10-29 13:10:12 -04:00
|
|
|
echo -e "\t--global-namespaces=$MULTUS_GLOBAL_NAMESPACES (used only with --namespace-isolation=true)"
|
2019-04-30 15:10:39 -04:00
|
|
|
echo -e "\t--multus-autoconfig-dir=$MULTUS_AUTOCONF_DIR (used only with --multus-conf-file=auto)"
|
2021-02-23 15:01:58 -08:00
|
|
|
echo -e "\t--multus-log-to-stderr=$MULTUS_LOG_TO_STDERR (empty by default, used only with --multus-conf-file=auto)"
|
2019-03-07 11:01:03 -05:00
|
|
|
echo -e "\t--multus-log-level=$MULTUS_LOG_LEVEL (empty by default, used only with --multus-conf-file=auto)"
|
|
|
|
echo -e "\t--multus-log-file=$MULTUS_LOG_FILE (empty by default, used only with --multus-conf-file=auto)"
|
2019-06-27 15:50:28 +09:00
|
|
|
echo -e "\t--override-network-name=false (used only with --multus-conf-file=auto)"
|
2019-08-19 15:23:34 -04:00
|
|
|
echo -e "\t--cleanup-config-on-exit=false (used only with --multus-conf-file=auto)"
|
2019-08-30 18:03:48 -04:00
|
|
|
echo -e "\t--rename-conf-file=false (used only with --multus-conf-file=auto)"
|
2020-02-18 15:15:44 -05:00
|
|
|
echo -e "\t--readiness-indicator-file=$MULTUS_READINESS_INDICATOR_FILE (used only with --multus-conf-file=auto)"
|
2019-09-18 12:17:43 -04:00
|
|
|
echo -e "\t--additional-bin-dir=$ADDITIONAL_BIN_DIR (adds binDir option to configuration, used only with --multus-conf-file=auto)"
|
2019-08-19 15:31:07 -04:00
|
|
|
echo -e "\t--restart-crio=false (restarts CRIO after config file is generated)"
|
2018-07-27 06:51:51 -04:00
|
|
|
}
|
|
|
|
|
entrypoint.sh: add timestamps to log messages; log autogenerated config file
Example:
2019-05-09T15:41:20-05:00 Generating Multus configuration file ...
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 0
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 1
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 10
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 15
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 20
2019-05-09T15:41:20-05:00 Config file created @ /host/etc/cni/net.d/00-multus.conf
{ "name": "multus-cni-network", "type": "multus", "namespaceIsolation": true, "logLevel": "verbose", "kubeconfig": "/etc/kubernetes/cni/net.d/multus.d/multus.kubeconfig", "delegates": [ { "cniVersion": "0.3.1", "name": "openshift-sdn", "type": "openshift-sdn" } ] }
2019-05-09T15:41:20-05:00 Entering sleep... (success)
2019-05-09 14:38:02 -05:00
|
|
|
function log()
|
|
|
|
{
|
|
|
|
echo "$(date --iso-8601=seconds) ${1}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function error()
|
|
|
|
{
|
|
|
|
log "ERR: {$1}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function warn()
|
|
|
|
{
|
|
|
|
log "WARN: {$1}"
|
|
|
|
}
|
|
|
|
|
2021-02-18 01:40:33 -05:00
|
|
|
if ! type python3 &> /dev/null; then
|
|
|
|
alias python=python3
|
|
|
|
fi
|
|
|
|
|
2022-02-28 22:04:23 +09:00
|
|
|
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(".")]
|
|
|
|
|
|
|
|
v_040 = version("0.4.0")
|
|
|
|
v_top_level = sys.argv[2]
|
|
|
|
with open(sys.argv[1], "r") as f:
|
|
|
|
v_nested = json.load(f)["cniVersion"]
|
|
|
|
if version(v_top_level) >= v_040 and version(v_nested) < v_040:
|
|
|
|
msg = "Multus cni version is %s while master plugin cni version is %s"
|
|
|
|
print(msg % (v_top_level, v_nested))
|
|
|
|
EOF
|
|
|
|
python $cniversion_python_tmpfile $1 $2
|
|
|
|
}
|
|
|
|
|
2018-07-27 06:51:51 -04:00
|
|
|
# Parse parameters given as arguments to this script.
|
|
|
|
while [ "$1" != "" ]; do
|
|
|
|
PARAM=`echo $1 | awk -F= '{print $1}'`
|
|
|
|
VALUE=`echo $1 | awk -F= '{print $2}'`
|
|
|
|
case $PARAM in
|
|
|
|
-h | --help)
|
|
|
|
usage
|
|
|
|
exit
|
|
|
|
;;
|
2019-05-30 16:36:13 +09:00
|
|
|
--cni-version)
|
|
|
|
CNI_VERSION=$VALUE
|
|
|
|
;;
|
2022-03-02 01:55:23 +09:00
|
|
|
# force-cni-version is only for e2e-kind testing
|
|
|
|
--force-cni-version)
|
|
|
|
FORCE_CNI_VERSION=$VALUE
|
|
|
|
;;
|
2021-11-08 17:40:54 +09:00
|
|
|
--cni-bin-dir)
|
|
|
|
CNI_BIN_DIR=$VALUE
|
|
|
|
;;
|
2018-07-27 06:51:51 -04:00
|
|
|
--cni-conf-dir)
|
|
|
|
CNI_CONF_DIR=$VALUE
|
|
|
|
;;
|
2021-11-08 17:40:54 +09:00
|
|
|
--cni-bin-dir)
|
|
|
|
CNI_BIN_DIR=$VALUE
|
|
|
|
;;
|
2018-07-27 06:51:51 -04:00
|
|
|
--multus-conf-file)
|
|
|
|
MULTUS_CONF_FILE=$VALUE
|
|
|
|
;;
|
2018-10-03 11:28:15 -07:00
|
|
|
--multus-kubeconfig-file-host)
|
|
|
|
MULTUS_KUBECONFIG_FILE_HOST=$VALUE
|
|
|
|
;;
|
2021-05-29 15:29:37 +08:00
|
|
|
--multus-master-cni-file-name)
|
|
|
|
MULTUS_MASTER_CNI_FILE_NAME=$VALUE
|
|
|
|
;;
|
2019-01-15 11:21:18 -05:00
|
|
|
--namespace-isolation)
|
|
|
|
MULTUS_NAMESPACE_ISOLATION=$VALUE
|
|
|
|
;;
|
2020-10-29 13:10:12 -04:00
|
|
|
--global-namespaces)
|
|
|
|
MULTUS_GLOBAL_NAMESPACES=$VALUE
|
|
|
|
;;
|
2021-02-23 15:01:58 -08:00
|
|
|
--multus-log-to-stderr)
|
|
|
|
MULTUS_LOG_TO_STDERR=$VALUE
|
|
|
|
;;
|
2019-03-07 11:01:03 -05:00
|
|
|
--multus-log-level)
|
|
|
|
MULTUS_LOG_LEVEL=$VALUE
|
|
|
|
;;
|
|
|
|
--multus-log-file)
|
|
|
|
MULTUS_LOG_FILE=$VALUE
|
|
|
|
;;
|
2019-04-30 15:10:39 -04:00
|
|
|
--multus-autoconfig-dir)
|
|
|
|
MULTUS_AUTOCONF_DIR=$VALUE
|
|
|
|
;;
|
2019-06-27 15:50:28 +09:00
|
|
|
--override-network-name)
|
|
|
|
OVERRIDE_NETWORK_NAME=$VALUE
|
|
|
|
;;
|
2019-08-19 15:23:34 -04:00
|
|
|
--cleanup-config-on-exit)
|
|
|
|
MULTUS_CLEANUP_CONFIG_ON_EXIT=$VALUE
|
|
|
|
;;
|
2019-08-19 15:31:07 -04:00
|
|
|
--restart-crio)
|
|
|
|
RESTART_CRIO=$VALUE
|
|
|
|
;;
|
2019-08-30 18:03:48 -04:00
|
|
|
--rename-conf-file)
|
|
|
|
RENAME_SOURCE_CONFIG_FILE=$VALUE
|
|
|
|
;;
|
2019-09-18 12:17:43 -04:00
|
|
|
--additional-bin-dir)
|
|
|
|
ADDITIONAL_BIN_DIR=$VALUE
|
|
|
|
;;
|
2019-11-06 14:08:39 -05:00
|
|
|
--skip-multus-binary-copy)
|
|
|
|
SKIP_BINARY_COPY=$VALUE
|
|
|
|
;;
|
2020-02-18 15:15:44 -05:00
|
|
|
--readiness-indicator-file)
|
|
|
|
MULTUS_READINESS_INDICATOR_FILE=$VALUE
|
|
|
|
;;
|
2018-07-27 06:51:51 -04:00
|
|
|
*)
|
entrypoint.sh: add timestamps to log messages; log autogenerated config file
Example:
2019-05-09T15:41:20-05:00 Generating Multus configuration file ...
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 0
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 1
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 10
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 15
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 20
2019-05-09T15:41:20-05:00 Config file created @ /host/etc/cni/net.d/00-multus.conf
{ "name": "multus-cni-network", "type": "multus", "namespaceIsolation": true, "logLevel": "verbose", "kubeconfig": "/etc/kubernetes/cni/net.d/multus.d/multus.kubeconfig", "delegates": [ { "cniVersion": "0.3.1", "name": "openshift-sdn", "type": "openshift-sdn" } ] }
2019-05-09T15:41:20-05:00 Entering sleep... (success)
2019-05-09 14:38:02 -05:00
|
|
|
warn "unknown parameter \"$PARAM\""
|
2018-07-27 06:51:51 -04:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
# Create array of known locations
|
2021-11-08 17:40:54 +09:00
|
|
|
declare -a arr=($CNI_CONF_DIR $CNI_BIN_DIR $MULTUS_BIN_FILE)
|
2018-10-03 11:28:15 -07:00
|
|
|
if [ "$MULTUS_CONF_FILE" != "auto" ]; then
|
2018-12-17 10:54:16 -08:00
|
|
|
arr+=($MULTUS_CONF_FILE)
|
2018-10-03 11:28:15 -07:00
|
|
|
fi
|
|
|
|
|
2018-07-27 06:51:51 -04:00
|
|
|
|
|
|
|
# Loop through and verify each location each.
|
|
|
|
for i in "${arr[@]}"
|
|
|
|
do
|
|
|
|
if [ ! -e "$i" ]; then
|
entrypoint.sh: add timestamps to log messages; log autogenerated config file
Example:
2019-05-09T15:41:20-05:00 Generating Multus configuration file ...
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 0
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 1
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 10
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 15
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 20
2019-05-09T15:41:20-05:00 Config file created @ /host/etc/cni/net.d/00-multus.conf
{ "name": "multus-cni-network", "type": "multus", "namespaceIsolation": true, "logLevel": "verbose", "kubeconfig": "/etc/kubernetes/cni/net.d/multus.d/multus.kubeconfig", "delegates": [ { "cniVersion": "0.3.1", "name": "openshift-sdn", "type": "openshift-sdn" } ] }
2019-05-09T15:41:20-05:00 Entering sleep... (success)
2019-05-09 14:38:02 -05:00
|
|
|
warn "Location $i does not exist"
|
2018-07-27 06:51:51 -04:00
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2021-11-08 17:40:54 +09:00
|
|
|
# Copy files into place and atomically move into final binary name
|
|
|
|
if [ "$SKIP_BINARY_COPY" = false ]; then
|
|
|
|
cp -f $MULTUS_BIN_FILE $CNI_BIN_DIR/_multus
|
|
|
|
mv -f $CNI_BIN_DIR/_multus $CNI_BIN_DIR/multus
|
|
|
|
else
|
|
|
|
log "Entrypoint skipped copying Multus binary."
|
|
|
|
fi
|
|
|
|
|
2018-10-03 11:28:15 -07:00
|
|
|
if [ "$MULTUS_CONF_FILE" != "auto" ]; then
|
|
|
|
cp -f $MULTUS_CONF_FILE $CNI_CONF_DIR
|
|
|
|
fi
|
2018-07-27 06:51:51 -04:00
|
|
|
|
|
|
|
# Make a multus.d directory (for our kubeconfig)
|
|
|
|
|
|
|
|
mkdir -p $CNI_CONF_DIR/multus.d
|
|
|
|
MULTUS_KUBECONFIG=$CNI_CONF_DIR/multus.d/multus.kubeconfig
|
|
|
|
|
|
|
|
# ------------------------------- Generate a "kube-config"
|
|
|
|
# Inspired by: https://tinyurl.com/y7r2knme
|
|
|
|
SERVICE_ACCOUNT_PATH=/var/run/secrets/kubernetes.io/serviceaccount
|
|
|
|
KUBE_CA_FILE=${KUBE_CA_FILE:-$SERVICE_ACCOUNT_PATH/ca.crt}
|
|
|
|
SERVICEACCOUNT_TOKEN=$(cat $SERVICE_ACCOUNT_PATH/token)
|
|
|
|
SKIP_TLS_VERIFY=${SKIP_TLS_VERIFY:-false}
|
|
|
|
|
|
|
|
|
|
|
|
# Check if we're running as a k8s pod.
|
|
|
|
if [ -f "$SERVICE_ACCOUNT_PATH/token" ]; then
|
|
|
|
# We're running as a k8d pod - expect some variables.
|
|
|
|
if [ -z ${KUBERNETES_SERVICE_HOST} ]; then
|
entrypoint.sh: add timestamps to log messages; log autogenerated config file
Example:
2019-05-09T15:41:20-05:00 Generating Multus configuration file ...
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 0
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 1
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 10
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 15
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 20
2019-05-09T15:41:20-05:00 Config file created @ /host/etc/cni/net.d/00-multus.conf
{ "name": "multus-cni-network", "type": "multus", "namespaceIsolation": true, "logLevel": "verbose", "kubeconfig": "/etc/kubernetes/cni/net.d/multus.d/multus.kubeconfig", "delegates": [ { "cniVersion": "0.3.1", "name": "openshift-sdn", "type": "openshift-sdn" } ] }
2019-05-09T15:41:20-05:00 Entering sleep... (success)
2019-05-09 14:38:02 -05:00
|
|
|
error "KUBERNETES_SERVICE_HOST not set"; exit 1;
|
2018-07-27 06:51:51 -04:00
|
|
|
fi
|
|
|
|
if [ -z ${KUBERNETES_SERVICE_PORT} ]; then
|
entrypoint.sh: add timestamps to log messages; log autogenerated config file
Example:
2019-05-09T15:41:20-05:00 Generating Multus configuration file ...
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 0
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 1
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 10
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 15
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 20
2019-05-09T15:41:20-05:00 Config file created @ /host/etc/cni/net.d/00-multus.conf
{ "name": "multus-cni-network", "type": "multus", "namespaceIsolation": true, "logLevel": "verbose", "kubeconfig": "/etc/kubernetes/cni/net.d/multus.d/multus.kubeconfig", "delegates": [ { "cniVersion": "0.3.1", "name": "openshift-sdn", "type": "openshift-sdn" } ] }
2019-05-09T15:41:20-05:00 Entering sleep... (success)
2019-05-09 14:38:02 -05:00
|
|
|
error "KUBERNETES_SERVICE_PORT not set"; exit 1;
|
2018-07-27 06:51:51 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$SKIP_TLS_VERIFY" == "true" ]; then
|
|
|
|
TLS_CFG="insecure-skip-tls-verify: true"
|
|
|
|
elif [ -f "$KUBE_CA_FILE" ]; then
|
|
|
|
TLS_CFG="certificate-authority-data: $(cat $KUBE_CA_FILE | base64 | tr -d '\n')"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Write a kubeconfig file for the CNI plugin. Do this
|
|
|
|
# to skip TLS verification for now. We should eventually support
|
|
|
|
# writing more complete kubeconfig files. This is only used
|
|
|
|
# if the provided CNI network config references it.
|
2021-04-29 15:55:58 -04:00
|
|
|
touch $MULTUS_TEMP_KUBECONFIG
|
|
|
|
chmod ${KUBECONFIG_MODE:-600} $MULTUS_TEMP_KUBECONFIG
|
|
|
|
# Write the kubeconfig to a temp file first.
|
|
|
|
cat > $MULTUS_TEMP_KUBECONFIG <<EOF
|
2018-07-27 06:51:51 -04:00
|
|
|
# Kubeconfig file for Multus CNI plugin.
|
|
|
|
apiVersion: v1
|
|
|
|
kind: Config
|
|
|
|
clusters:
|
|
|
|
- name: local
|
|
|
|
cluster:
|
2019-11-13 17:56:59 -05:00
|
|
|
server: ${KUBERNETES_SERVICE_PROTOCOL:-https}://[${KUBERNETES_SERVICE_HOST}]:${KUBERNETES_SERVICE_PORT}
|
2018-07-27 06:51:51 -04:00
|
|
|
$TLS_CFG
|
|
|
|
users:
|
|
|
|
- name: multus
|
|
|
|
user:
|
|
|
|
token: "${SERVICEACCOUNT_TOKEN}"
|
|
|
|
contexts:
|
|
|
|
- name: multus-context
|
|
|
|
context:
|
|
|
|
cluster: local
|
|
|
|
user: multus
|
|
|
|
current-context: multus-context
|
|
|
|
EOF
|
|
|
|
|
2021-04-29 15:55:58 -04:00
|
|
|
# Atomically move the temp kubeconfig to its permanent home.
|
|
|
|
mv -f $MULTUS_TEMP_KUBECONFIG $MULTUS_KUBECONFIG
|
|
|
|
|
2018-07-27 06:51:51 -04:00
|
|
|
else
|
entrypoint.sh: add timestamps to log messages; log autogenerated config file
Example:
2019-05-09T15:41:20-05:00 Generating Multus configuration file ...
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 0
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 1
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 10
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 15
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 20
2019-05-09T15:41:20-05:00 Config file created @ /host/etc/cni/net.d/00-multus.conf
{ "name": "multus-cni-network", "type": "multus", "namespaceIsolation": true, "logLevel": "verbose", "kubeconfig": "/etc/kubernetes/cni/net.d/multus.d/multus.kubeconfig", "delegates": [ { "cniVersion": "0.3.1", "name": "openshift-sdn", "type": "openshift-sdn" } ] }
2019-05-09T15:41:20-05:00 Entering sleep... (success)
2019-05-09 14:38:02 -05:00
|
|
|
warn "Doesn't look like we're running in a kubernetes environment (no serviceaccount token)"
|
2018-07-27 06:51:51 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# ---------------------- end Generate a "kube-config".
|
|
|
|
|
2018-10-03 11:28:15 -07:00
|
|
|
# ------------------------------- Generate "00-multus.conf"
|
|
|
|
|
2019-08-19 15:23:34 -04:00
|
|
|
function generateMultusConf {
|
2018-10-03 11:28:15 -07:00
|
|
|
if [ "$MULTUS_CONF_FILE" == "auto" ]; then
|
2019-08-19 15:23:34 -04:00
|
|
|
log "Generating Multus configuration file using files in $MULTUS_AUTOCONF_DIR..."
|
2019-02-28 13:56:08 -05:00
|
|
|
found_master=false
|
|
|
|
tries=0
|
|
|
|
while [ $found_master == false ]; do
|
2021-05-29 15:29:37 +08:00
|
|
|
if [ "$MULTUS_MASTER_CNI_FILE_NAME" != "" ]; then
|
2021-07-12 10:30:20 -07:00
|
|
|
MASTER_PLUGIN="$MULTUS_MASTER_CNI_FILE_NAME"
|
2021-05-29 15:29:37 +08:00
|
|
|
else
|
|
|
|
MASTER_PLUGIN="$(ls $MULTUS_AUTOCONF_DIR | grep -E '\.conf(list)?$' | grep -Ev '00-multus\.conf' | head -1)"
|
|
|
|
fi
|
2019-02-28 13:56:08 -05:00
|
|
|
if [ "$MASTER_PLUGIN" == "" ]; then
|
|
|
|
if [ $tries -lt 600 ]; then
|
|
|
|
if ! (($tries % 5)); then
|
2021-05-29 14:52:39 +08:00
|
|
|
log "Attempting to find master plugin configuration, attempt $tries"
|
2019-02-28 13:56:08 -05:00
|
|
|
fi
|
|
|
|
let "tries+=1"
|
2021-02-09 15:14:06 -05:00
|
|
|
sleep 1;
|
2019-02-28 13:56:08 -05:00
|
|
|
else
|
entrypoint.sh: add timestamps to log messages; log autogenerated config file
Example:
2019-05-09T15:41:20-05:00 Generating Multus configuration file ...
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 0
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 1
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 10
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 15
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 20
2019-05-09T15:41:20-05:00 Config file created @ /host/etc/cni/net.d/00-multus.conf
{ "name": "multus-cni-network", "type": "multus", "namespaceIsolation": true, "logLevel": "verbose", "kubeconfig": "/etc/kubernetes/cni/net.d/multus.d/multus.kubeconfig", "delegates": [ { "cniVersion": "0.3.1", "name": "openshift-sdn", "type": "openshift-sdn" } ] }
2019-05-09T15:41:20-05:00 Entering sleep... (success)
2019-05-09 14:38:02 -05:00
|
|
|
error "Multus could not be configured: no master plugin was found."
|
2019-02-28 13:56:08 -05:00
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
else
|
2021-07-12 10:30:20 -07:00
|
|
|
log "Using MASTER_PLUGIN: $MASTER_PLUGIN"
|
2019-03-07 11:01:03 -05:00
|
|
|
|
2019-02-28 13:56:08 -05:00
|
|
|
found_master=true
|
2019-03-07 11:01:03 -05:00
|
|
|
|
|
|
|
ISOLATION_STRING=""
|
|
|
|
if [ "$MULTUS_NAMESPACE_ISOLATION" == true ]; then
|
|
|
|
ISOLATION_STRING="\"namespaceIsolation\": true,"
|
|
|
|
fi
|
|
|
|
|
2020-10-29 13:10:12 -04:00
|
|
|
GLOBAL_NAMESPACES_STRING=""
|
|
|
|
if [ ! -z "${MULTUS_GLOBAL_NAMESPACES// }" ]; then
|
|
|
|
GLOBAL_NAMESPACES_STRING="\"globalNamespaces\": \"$MULTUS_GLOBAL_NAMESPACES\","
|
|
|
|
fi
|
|
|
|
|
2021-02-23 15:01:58 -08:00
|
|
|
LOG_TO_STDERR_STRING=""
|
|
|
|
if [ "$MULTUS_LOG_TO_STDERR" == false ]; then
|
|
|
|
LOG_TO_STDERR_STRING="\"logToStderr\": false,"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2019-03-07 11:01:03 -05:00
|
|
|
LOG_LEVEL_STRING=""
|
|
|
|
if [ ! -z "${MULTUS_LOG_LEVEL// }" ]; then
|
|
|
|
case "$MULTUS_LOG_LEVEL" in
|
|
|
|
debug)
|
|
|
|
;;
|
|
|
|
error)
|
|
|
|
;;
|
|
|
|
panic)
|
|
|
|
;;
|
|
|
|
verbose)
|
|
|
|
;;
|
|
|
|
*)
|
entrypoint.sh: add timestamps to log messages; log autogenerated config file
Example:
2019-05-09T15:41:20-05:00 Generating Multus configuration file ...
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 0
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 1
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 10
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 15
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 20
2019-05-09T15:41:20-05:00 Config file created @ /host/etc/cni/net.d/00-multus.conf
{ "name": "multus-cni-network", "type": "multus", "namespaceIsolation": true, "logLevel": "verbose", "kubeconfig": "/etc/kubernetes/cni/net.d/multus.d/multus.kubeconfig", "delegates": [ { "cniVersion": "0.3.1", "name": "openshift-sdn", "type": "openshift-sdn" } ] }
2019-05-09T15:41:20-05:00 Entering sleep... (success)
2019-05-09 14:38:02 -05:00
|
|
|
error "Log levels should be one of: debug/verbose/error/panic, did not understand $MULTUS_LOG_LEVEL"
|
2019-03-07 11:01:03 -05:00
|
|
|
usage
|
2022-02-28 22:04:23 +09:00
|
|
|
exit 1
|
2019-03-07 11:01:03 -05:00
|
|
|
esac
|
|
|
|
LOG_LEVEL_STRING="\"logLevel\": \"$MULTUS_LOG_LEVEL\","
|
|
|
|
fi
|
|
|
|
|
|
|
|
LOG_FILE_STRING=""
|
|
|
|
if [ ! -z "${MULTUS_LOG_FILE// }" ]; then
|
|
|
|
LOG_FILE_STRING="\"logFile\": \"$MULTUS_LOG_FILE\","
|
|
|
|
fi
|
|
|
|
|
2019-05-30 16:36:13 +09:00
|
|
|
CNI_VERSION_STRING=""
|
|
|
|
if [ ! -z "${CNI_VERSION// }" ]; then
|
|
|
|
CNI_VERSION_STRING="\"cniVersion\": \"$CNI_VERSION\","
|
|
|
|
fi
|
|
|
|
|
2019-09-18 12:17:43 -04:00
|
|
|
ADDITIONAL_BIN_DIR_STRING=""
|
|
|
|
if [ ! -z "${ADDITIONAL_BIN_DIR// }" ]; then
|
|
|
|
ADDITIONAL_BIN_DIR_STRING="\"binDir\": \"$ADDITIONAL_BIN_DIR\","
|
|
|
|
fi
|
|
|
|
|
2020-02-18 15:15:44 -05:00
|
|
|
|
|
|
|
READINESS_INDICATOR_FILE_STRING=""
|
|
|
|
if [ ! -z "${MULTUS_READINESS_INDICATOR_FILE// }" ]; then
|
|
|
|
READINESS_INDICATOR_FILE_STRING="\"readinessindicatorfile\": \"$MULTUS_READINESS_INDICATOR_FILE\","
|
|
|
|
fi
|
|
|
|
|
2019-06-27 15:50:28 +09:00
|
|
|
if [ "$OVERRIDE_NETWORK_NAME" == "true" ]; then
|
|
|
|
MASTER_PLUGIN_NET_NAME="$(cat $MULTUS_AUTOCONF_DIR/$MASTER_PLUGIN | \
|
2021-02-18 01:40:33 -05:00
|
|
|
python -c 'import json,sys;print(json.load(sys.stdin)["name"])')"
|
2019-06-27 15:50:28 +09:00
|
|
|
else
|
|
|
|
MASTER_PLUGIN_NET_NAME="multus-cni-network"
|
|
|
|
fi
|
|
|
|
|
2020-08-05 10:29:05 +02:00
|
|
|
capabilities_python_filter_tmpfile=$(mktemp)
|
|
|
|
cat << EOF > $capabilities_python_filter_tmpfile
|
|
|
|
import json,sys
|
|
|
|
conf = json.load(sys.stdin)
|
|
|
|
capabilities = {}
|
2020-12-14 10:29:08 +02:00
|
|
|
if 'plugins' in conf:
|
|
|
|
for capa in [p['capabilities'] for p in conf['plugins'] if 'capabilities' in p]:
|
|
|
|
capabilities.update({capability:enabled for (capability,enabled) in capa.items() if enabled})
|
|
|
|
elif 'capabilities' in conf:
|
|
|
|
capabilities.update({capability:enabled for (capability,enabled) in conf['capabilities'] if enabled})
|
2020-08-05 10:29:05 +02:00
|
|
|
if len(capabilities) > 0:
|
|
|
|
print("""\"capabilities\": """ + json.dumps(capabilities) + ",")
|
|
|
|
else:
|
|
|
|
print("")
|
|
|
|
EOF
|
|
|
|
|
|
|
|
NESTED_CAPABILITIES_STRING="$(cat $MULTUS_AUTOCONF_DIR/$MASTER_PLUGIN | \
|
|
|
|
python $capabilities_python_filter_tmpfile)"
|
|
|
|
rm $capabilities_python_filter_tmpfile
|
2022-02-28 22:04:23 +09:00
|
|
|
log "Nested capabilities string: $NESTED_CAPABILITIES_STRING"
|
2020-08-05 10:29:05 +02:00
|
|
|
|
2019-08-19 15:23:34 -04:00
|
|
|
MASTER_PLUGIN_LOCATION=$MULTUS_AUTOCONF_DIR/$MASTER_PLUGIN
|
2022-03-02 01:55:23 +09:00
|
|
|
if [ "$FORCE_CNI_VERSION" == true ]; then
|
|
|
|
MASTER_PLUGIN_JSON="$(cat $MASTER_PLUGIN_LOCATION | sed -e "s/\"cniVersion.*/\"cniVersion\": \"$CNI_VERSION\",/g")"
|
|
|
|
else
|
|
|
|
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
|
2022-02-28 22:04:23 +09:00
|
|
|
fi
|
|
|
|
|
2019-02-28 13:56:08 -05:00
|
|
|
CONF=$(cat <<-EOF
|
2019-08-19 15:23:34 -04:00
|
|
|
{
|
2019-05-30 16:36:13 +09:00
|
|
|
$CNI_VERSION_STRING
|
2019-08-19 15:23:34 -04:00
|
|
|
"name": "$MASTER_PLUGIN_NET_NAME",
|
|
|
|
"type": "multus",
|
2020-08-05 10:29:05 +02:00
|
|
|
$NESTED_CAPABILITIES_STRING
|
2019-03-07 11:01:03 -05:00
|
|
|
$ISOLATION_STRING
|
2020-10-29 13:10:12 -04:00
|
|
|
$GLOBAL_NAMESPACES_STRING
|
2021-02-23 15:01:58 -08:00
|
|
|
$LOG_TO_STDERR_STRING
|
2019-03-07 11:01:03 -05:00
|
|
|
$LOG_LEVEL_STRING
|
|
|
|
$LOG_FILE_STRING
|
2019-09-18 12:17:43 -04:00
|
|
|
$ADDITIONAL_BIN_DIR_STRING
|
2020-02-18 15:15:44 -05:00
|
|
|
$READINESS_INDICATOR_FILE_STRING
|
2019-08-19 15:23:34 -04:00
|
|
|
"kubeconfig": "$MULTUS_KUBECONFIG_FILE_HOST",
|
|
|
|
"delegates": [
|
|
|
|
$MASTER_PLUGIN_JSON
|
|
|
|
]
|
|
|
|
}
|
2019-02-28 13:56:08 -05:00
|
|
|
EOF
|
2019-08-19 15:23:34 -04:00
|
|
|
)
|
2020-01-17 16:10:46 -05:00
|
|
|
tmpfile=$(mktemp)
|
|
|
|
echo $CONF > $tmpfile
|
|
|
|
mv $tmpfile $CNI_CONF_DIR/00-multus.conf
|
entrypoint.sh: add timestamps to log messages; log autogenerated config file
Example:
2019-05-09T15:41:20-05:00 Generating Multus configuration file ...
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 0
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 1
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 10
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 15
2019-05-09T15:41:20-05:00 Attemping to find master plugin configuration, attempt 20
2019-05-09T15:41:20-05:00 Config file created @ /host/etc/cni/net.d/00-multus.conf
{ "name": "multus-cni-network", "type": "multus", "namespaceIsolation": true, "logLevel": "verbose", "kubeconfig": "/etc/kubernetes/cni/net.d/multus.d/multus.kubeconfig", "delegates": [ { "cniVersion": "0.3.1", "name": "openshift-sdn", "type": "openshift-sdn" } ] }
2019-05-09T15:41:20-05:00 Entering sleep... (success)
2019-05-09 14:38:02 -05:00
|
|
|
log "Config file created @ $CNI_CONF_DIR/00-multus.conf"
|
|
|
|
echo $CONF
|
2022-02-28 22:04:23 +09:00
|
|
|
|
2019-08-28 13:23:28 -04:00
|
|
|
# If we're not performing the cleanup on exit, we can safely rename the config file.
|
2019-08-30 18:03:48 -04:00
|
|
|
if [ "$RENAME_SOURCE_CONFIG_FILE" == true ]; then
|
2019-08-28 13:23:28 -04:00
|
|
|
mv ${MULTUS_AUTOCONF_DIR}/${MASTER_PLUGIN} ${MULTUS_AUTOCONF_DIR}/${MASTER_PLUGIN}.old
|
|
|
|
log "Original master file moved to ${MULTUS_AUTOCONF_DIR}/${MASTER_PLUGIN}.old"
|
|
|
|
fi
|
2019-08-19 15:31:07 -04:00
|
|
|
|
|
|
|
if [ "$RESTART_CRIO" == true ]; then
|
2019-08-28 13:23:28 -04:00
|
|
|
# Restart CRIO only once.
|
|
|
|
if [ "$CRIO_RESTARTED_ONCE" == false ]; then
|
|
|
|
log "Restarting crio"
|
|
|
|
systemctl restart crio
|
|
|
|
CRIO_RESTARTED_ONCE=true
|
|
|
|
fi
|
2019-08-19 15:31:07 -04:00
|
|
|
fi
|
2019-01-15 11:21:18 -05:00
|
|
|
fi
|
2019-02-28 13:56:08 -05:00
|
|
|
done
|
2018-10-03 11:28:15 -07:00
|
|
|
fi
|
2019-08-19 15:23:34 -04:00
|
|
|
}
|
|
|
|
generateMultusConf
|
2018-10-03 11:28:15 -07:00
|
|
|
|
|
|
|
# ---------------------- end Generate "00-multus.conf".
|
|
|
|
|
2019-08-19 15:23:34 -04:00
|
|
|
# Enter either sleep loop, or watch loop...
|
|
|
|
if [ "$MULTUS_CLEANUP_CONFIG_ON_EXIT" == true ]; then
|
|
|
|
log "Entering watch loop..."
|
|
|
|
while true; do
|
|
|
|
# Check and see if the original master plugin configuration exists...
|
|
|
|
if [ ! -f "$MASTER_PLUGIN_LOCATION" ]; then
|
2020-02-18 15:15:44 -05:00
|
|
|
log "Master plugin @ $MASTER_PLUGIN_LOCATION has been deleted. Allowing 45 seconds for its restoration..."
|
2021-02-09 15:14:06 -05:00
|
|
|
sleep 10
|
2020-02-18 15:15:44 -05:00
|
|
|
for i in {1..35}
|
|
|
|
do
|
|
|
|
if [ -f "$MASTER_PLUGIN_LOCATION" ]; then
|
|
|
|
log "Master plugin @ $MASTER_PLUGIN_LOCATION was restored. Regenerating given configuration."
|
|
|
|
break
|
|
|
|
fi
|
2021-02-09 15:14:06 -05:00
|
|
|
sleep 1
|
2020-02-18 15:15:44 -05:00
|
|
|
done
|
|
|
|
|
2019-08-19 15:23:34 -04:00
|
|
|
generateMultusConf
|
|
|
|
log "Continuing watch loop after configuration regeneration..."
|
|
|
|
fi
|
2021-02-09 15:14:06 -05:00
|
|
|
sleep 1
|
2019-08-19 15:23:34 -04:00
|
|
|
done
|
|
|
|
else
|
|
|
|
log "Entering sleep (success)..."
|
2021-02-25 08:48:12 +09:00
|
|
|
if tty -s; then
|
|
|
|
read
|
|
|
|
else
|
|
|
|
sleep infinity
|
|
|
|
fi
|
2019-11-13 14:10:23 -05:00
|
|
|
fi
|