summaryrefslogtreecommitdiff
path: root/recipes-networking
diff options
context:
space:
mode:
authorTravis McCollum <x85446@yahoo.com>2020-07-19 23:45:44 -0500
committerTravis McCollum <x85446@yahoo.com>2020-07-19 23:45:44 -0500
commitd8cea9d1b07c76a2638c1dd751bbe586ae776229 (patch)
tree55e4227e949ca8eb045248d76ac5376676f9cf2a /recipes-networking
parentf29eb2d90443727dac821d748d149e3c5131a2c5 (diff)
adds container orchestration
Diffstat (limited to 'recipes-networking')
-rw-r--r--recipes-networking/cni/cni_git.bb79
-rw-r--r--recipes-networking/cni/files/c2d40
-rw-r--r--recipes-networking/cni/files/c2d-inner90
3 files changed, 209 insertions, 0 deletions
diff --git a/recipes-networking/cni/cni_git.bb b/recipes-networking/cni/cni_git.bb
new file mode 100644
index 0000000..e98da8c
--- /dev/null
+++ b/recipes-networking/cni/cni_git.bb
@@ -0,0 +1,79 @@
+HOMEPAGE = "https://github.com/containernetworking/cni"
+SUMMARY = "Container Network Interface - networking for Linux containers"
+DESCRIPTION = "CNI (Container Network Interface), a Cloud Native Computing \
+Foundation project, consists of a specification and libraries for writing \
+plugins to configure network interfaces in Linux containers, along with a \
+number of supported plugins. CNI concerns itself only with network connectivity \
+of containers and removing allocated resources when the container is deleted. \
+Because of this focus, CNI has a wide range of support and the specification \
+is simple to implement. \
+"
+
+SRCREV_cni = "4cfb7b568922a3c79a23e438dc52fe537fc9687e"
+# Version 0.8.5
+SRCREV_plugins = "1f33fb729ae2b8900785f896df2dc1f6fe5e8239"
+SRC_URI = "\
+ git://github.com/containernetworking/cni.git;nobranch=1;name=cni \
+ git://github.com/containernetworking/plugins.git;nobranch=1;destsuffix=${S}/src/github.com/containernetworking/plugins;name=plugins \
+ file://c2d \
+ file://c2d-inner \
+ "
+
+RPROVIDES_${PN} += "kubernetes-cni"
+RDEPENDS_${PN} += "bash"
+
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://src/import/LICENSE;md5=fa818a259cbed7ce8bc2a22d35a464fc"
+
+GO_IMPORT = "import"
+
+PV = "0.7.1+git${SRCREV_cni}"
+
+inherit go
+inherit goarch
+
+do_compile() {
+ mkdir -p ${S}/src/github.com/containernetworking
+ ln -sfr ${S}/src/import ${S}/src/github.com/containernetworking/cni
+
+ cd ${B}/src/github.com/containernetworking/cni/libcni
+ ${GO} build
+
+ cd ${B}/src/github.com/containernetworking/cni/cnitool
+ ${GO} build
+
+ cd ${B}/src/github.com/containernetworking/plugins
+ PLUGINS="$(ls -d plugins/meta/*; ls -d plugins/ipam/*; ls -d plugins/main/* | grep -v windows)"
+ mkdir -p ${B}/plugins/bin/
+ for p in $PLUGINS; do
+ plugin="$(basename "$p")"
+ echo "building: $p"
+ ${GO} build -mod=vendor -o ${B}/plugins/bin/$plugin github.com/containernetworking/plugins/$p
+ done
+}
+
+do_install() {
+ localbindir="/wigwag/system/opt/cni/bin"
+
+ install -d ${D}${localbindir}
+ install -d ${D}/${sysconfdir}/cni/net.d
+
+ install -m 755 ${S}/src/import/cnitool/cnitool ${D}/${localbindir}
+ install -m 755 -D ${B}/plugins/bin/* ${D}/${localbindir}
+
+ # Parts of k8s expect the cni binaries to be available in /opt/cni
+ install -d ${D}/opt/cni
+ ln -sf /wigag/system/opt/cni/ ${D}/opt/cni/bin
+ # re-linking to the origional recipeies location
+ install -d ${D}${libexecdir}/cni
+ ln -sf /wigwag/system/opt/cni ${D}${libexecdir}/cni
+ #extra features needed by pe
+ install -m 755 -o root -g root ${WORKDIR}/c2d ${D}/${localbindir}
+ install -m 755 -o root -g root ${WORKDIR}/c2d-inner ${D}/${localbindir}
+}
+
+FILES_${PN} += "${libexecdir}cni/* /opt/cni/* /wigwag/system/opt/cni/bin"
+
+INSANE_SKIP_${PN} += "ldflags already-stripped"
+
+deltask compile_ptest_base
diff --git a/recipes-networking/cni/files/c2d b/recipes-networking/cni/files/c2d
new file mode 100644
index 0000000..2a9581a
--- /dev/null
+++ b/recipes-networking/cni/files/c2d
@@ -0,0 +1,40 @@
+#!/bin/bash
+# Copyright 2016 The Kubernetes Authors All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This is a wrapper that converts the stdin/stdout part of the CNI
+# calling convention into an input-file & output-file calling
+# convention. All the stuff written to stdout and stderr by the inner
+# script is saved to a file in /tmp/.
+
+INPUT=/tmp/c2d-$$-in
+RESULT=/tmp/c2d-$$-out
+LOG=/tmp/c2d-$$-log
+cat > "${INPUT}"
+"${0}-inner" "${INPUT}" "${RESULT}" &> "${LOG}"
+RC=$?
+if [ "${RC}" == "0" ]; then
+ cat "${RESULT}"
+ rm ${INPUT} ${RESULT} ${LOG}
+else
+ cat <<EOF
+{
+ "cniVersion": "0.1.0",
+ "code": "${RC}",
+ "msg": "${0}-inner returned ${RC}",
+ "details": $(jq -R -s . < "${LOG}")
+}
+EOF
+ exit "${RC}"
+fi
diff --git a/recipes-networking/cni/files/c2d-inner b/recipes-networking/cni/files/c2d-inner
new file mode 100644
index 0000000..ed28adc
--- /dev/null
+++ b/recipes-networking/cni/files/c2d-inner
@@ -0,0 +1,90 @@
+#!/bin/bash
+# Copyright 2016 The Kubernetes Authors All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+if [ $# -ne 2 ]; then
+ echo Usage: $0 INPUT_FILE_NAME OUTPUT_FILE_NAME >& 2
+ exit 1
+fi
+INPFN="$1"
+OUTFN="$2"
+
+# Look for the "debug" setting in the config file and turn on
+# debugging if requested.
+if jq .debug < "${INPFN}" | grep -i true &> /dev/null; then
+ echo
+ printenv | grep CNI
+ set -x
+fi
+
+# Extract a container name from the k8s POD name. This will used as the discoverable DNS name
+# for the container
+PN=$(mapfile -d ';' -t array <<<${CNI_ARGS}; for i in ${array[@]}; do echo $i | grep K8S_POD_NAME= | cut -d "=" -f 2-; done)
+
+# From here on, any failed command is a fatal error.
+set -e
+
+case "${CNI_COMMAND}" in
+ (ADD)
+
+ # Pick the desired network name out of the config.
+ thenet="$(jq -r .name < "${INPFN}")"
+
+ # When the kubelet is configured to use a CNI plugin, the
+ # infrastructure container (the one running "/pause") starts
+ # out connected to the Docker network named "none". Docker
+ # does not allow a container to be connected to both "none"
+ # and another network, so remove that pain.
+ docker network disconnect none "${CNI_CONTAINERID}"
+
+ # Connect to the desired Docker network
+ HOSTNAME_ALIAS=$(docker inspect --format='{{.Config.Hostname}}' ${CNI_CONTAINERID})
+ docker network connect --alias "${HOSTNAME_ALIAS}" "${thenet}" "${CNI_CONTAINERID}"
+
+ # Extract the needed output info from the container
+ CTR_INFO=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} {{range .NetworkSettings.Networks}}{{.Gateway}}{{end}} {{range .NetworkSettings.Networks}}{{.IPPrefixLen}}{{end}}' ${CNI_CONTAINERID})
+ PN=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} {{range .NetworkSettings.Networks}}{{.Gateway}}{{end}} {{range .NetworkSettings.Networks}}{{.IPPrefixLen}}{{end}}' ${CNI_CONTAINERID})
+ CTR_IP=$(echo "${CTR_INFO}" | cut '-d ' -f1)
+ CTR_GW=$(echo "${CTR_INFO}" | cut '-d ' -f2)
+ CTR_PF=$(echo "${CTR_INFO}" | cut '-d ' -f3)
+
+ # Produce the proper CNI output
+ cat > "${OUTFN}" <<EOF
+{
+ "cniVersion": "0.2.0",
+ "ip4": {
+ "ip": "${CTR_IP}/${CTR_PF}",
+ "gateway": "${CTR_GW}"
+ }
+}
+EOF
+ ;;
+
+ (DEL)
+
+ # Nothing needs to be done, the Docker container delete will
+ # handle it all.
+
+ cat > "${OUTFN}" <<EOF
+{
+ "cniVersion": "0.1.0"
+}
+EOF
+ ;;
+
+ (*)
+ echo "Unexpected CNI_COMMAND ($CNI_COMMAND)!" >& 2
+ exit 2
+ ;;
+esac