From: Author Name Date: Mon, 2 Mar 2020 04:34:42 +0000 (+0000) Subject: Adding the ovn containerization X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=commitdiff_plain;ds=sidebyside;h=7f01772cdf3916026a93e9e9ac5ce54d57401476;p=ovn4nfv-k8s-plugin.git Adding the ovn containerization Referred multiple works on ovs and ovn ovs: https://github.com/openvswitch/ovs/tree/master/utilities/docker ovn: https://github.com/ovn-org/ovn/tree/master/utilities/docker ovn-kubernetes: https://github.com/ovn-org/ovn-kubernetes/tree/master/dist/images kube-ovn:https://github.com/alauda/kube-ovn/tree/master/dist/images Co-authored-by: Aliasgar Ginwala Signed-off-by: Kuralamudhan Ramakrishnan Change-Id: I3aee1a9f4ebce702ca22ec2ecba35463523af892 --- diff --git a/build/bin/entrypoint b/build/bin/entrypoint index 77084a3..c9646a0 100755 --- a/build/bin/entrypoint +++ b/build/bin/entrypoint @@ -1,32 +1,101 @@ -#!/bin/sh -e +#!/bin/bash +set -e +CNI_VERSION=${CNI_VERSION:-"v0.8.5"} +IMAGE_ARC=${IMAGE_ARC:-"amd64"} + +create_kubeconfig() { + # Make a ovn4nfv.d directory (for our kubeconfig) + # Inspired from t.ly/Xgbbe + mkdir -p $CNI_CONF_DIR/ovn4nfv-k8s.d + OVN4NFV_KUBECONFIG=$CNI_CONF_DIR/ovn4nfv-k8s.d/ovn4nfv-k8s.kubeconfig + 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 + error "KUBERNETES_SERVICE_HOST not set"; exit 1; + fi + if [ -z ${KUBERNETES_SERVICE_PORT} ]; then + error "KUBERNETES_SERVICE_PORT not set"; exit 1; + 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. + touch $OVN4NFV_KUBECONFIG + chmod ${KUBECONFIG_MODE:-600} $OVN4NFV_KUBECONFIG + cat > $OVN4NFV_KUBECONFIG < Packages.gz; \ +popd; \ +" +RUN ls -lt /opt/ovn4nfv-k8s-plugin/dist/ubuntu/deb +RUN echo "deb [trusted=yes] file:///opt/ovn4nfv-k8s-plugin/dist/ubuntu/deb ./" | tee -a /etc/apt/sources.list > /dev/null +RUN apt-get update +RUN apt-get install -y openvswitch-switch=2.12.0-1 openvswitch-common=2.12.0-1 ovn-central=2.12.0-1 ovn-common=2.12.0-1 ovn-host=2.12.0-1 +RUN mkdir -p /var/run/openvswitch && \ + mkdir -p /var/run/ovn + +COPY ovn4nfv-k8s.sh /usr/local/bin/ovn4nfv-k8s + +ENTRYPOINT ["ovn4nfv-k8s"] diff --git a/utilities/docker/debian/ovn4nfv-k8s.sh b/utilities/docker/debian/ovn4nfv-k8s.sh new file mode 100755 index 0000000..ee60e2b --- /dev/null +++ b/utilities/docker/debian/ovn4nfv-k8s.sh @@ -0,0 +1,158 @@ +#!/usr/bin/env bash +OVS_RUNDIR=/var/run/openvswitch +OVS_LOGDIR=/var/log/openvswitch + +DB_NB_ADDR=${DB_NB_ADDR:-::} +DB_NB_PORT=${DB_NB_PORT:-6641} +DB_SB_ADDR=${DB_SB_ADDR:-::} +DB_SB_PORT=${DB_SB_PORT:-6642} +cmd=${1:-""} + +if [[ -f /usr/bin/ovn-appctl ]] ; then + # ovn-appctl is present. Use new ovn run dir path. + OVN_RUNDIR=/var/run/ovn + OVNCTL_PATH=/usr/share/ovn/scripts/ovn-ctl + OVN_LOGDIR=/var/log/ovn + OVN_ETCDIR=/etc/ovn +else + # ovn-appctl is not present. Use openvswitch run dir path. + OVN_RUNDIR=/var/run/openvswitch + OVNCTL_PATH=/usr/share/openvswitch/scripts/ovn-ctl + OVN_LOGDIR=/var/log/openvswitch + OVN_ETCDIR=/etc/openvswitch +fi + +check_ovn_control_plane() { + /usr/share/ovn/scripts/ovn-ctl status_northd + /usr/share/ovn/scripts/ovn-ctl status_ovnnb + /usr/share/ovn/scripts/ovn-ctl status_ovnsb +} + +check_ovn_controller() { + /usr/share/ovn/scripts/ovn-ctl status_controller +} + +# wait for ovn-sb ready +wait_ovn_sb() { + if [[ -z "${OVN_SB_TCP_SERVICE_HOST}" ]]; then + echo "env OVN_SB_SERVICE_HOST not exists" + exit 1 + fi + if [[ -z "${OVN_SB_TCP_SERVICE_PORT}" ]]; then + echo "env OVN_SB_SERVICE_PORT not exists" + exit 1 + fi + while ! nc -z "${OVN_SB_TCP_SERVICE_HOST}" "${OVN_SB_TCP_SERVICE_PORT}"