Hyunsun Moon | 81c8e23 | 2019-05-21 03:40:22 -0600 | [diff] [blame] | 1 | SHELL := /bin/bash |
| 2 | BUILD ?= /tmp/build |
| 3 | M ?= $(BUILD)/milestones |
| 4 | MAKEDIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) |
| 5 | SCRIPTDIR := $(MAKEDIR)../scripts |
| 6 | RESOURCEDIR := $(MAKEDIR)/resources |
| 7 | WORKSPACE ?= $(HOME) |
| 8 | VENV ?= $(BUILD)/venv/ciab |
| 9 | CIABVALUES ?= $(MAKEDIR)/comac-in-a-box-values.yaml |
| 10 | |
| 11 | KUBESPRAY_VERSION ?= release-2.10 |
| 12 | DOCKER_VERSION ?= 18.06 |
| 13 | K8S_VERSION ?= v1.14.3 |
| 14 | HELM_VERSION ?= v2.13.1 |
| 15 | |
| 16 | # used to start logging/monitoring and other infrastructure charts |
| 17 | INFRA_CHARTS ?= |
| 18 | INFRA_PREREQS = $(foreach chart,$(INFRA_CHARTS),$(M)/$(chart)) |
| 19 | |
| 20 | KAFKA_CHART_VERSION ?= 0.13.3 |
| 21 | KAFKA_POD := "pod/cord-kafka-0" |
| 22 | |
| 23 | ETCD_OPERATOR_VERSION ?= 0.8.3 |
| 24 | |
| 25 | HELM_GLOBAL_ARGS ?= |
| 26 | HELM_NEM_ARGS ?= $(HELM_GLOBAL_ARGS) |
| 27 | HELM_ONOS_ARGS ?= $(HELM_GLOBAL_ARGS) |
| 28 | |
| 29 | cpu_family := $(shell lscpu | grep 'CPU family:' | awk '{print $$3}') |
| 30 | cpu_model := $(shell lscpu | grep 'Model:' | awk '{print $$2}') |
| 31 | os_vendor := $(shell lsb_release -i -s) |
Hyunsun Moon | ad70fc1 | 2019-08-02 16:52:19 -0600 | [diff] [blame] | 32 | os_release := $(shell lsb_release -r -s) |
Hyunsun Moon | 81c8e23 | 2019-05-21 03:40:22 -0600 | [diff] [blame] | 33 | |
| 34 | # TODO: include CORD platform |
| 35 | ciab: $(M)/system_check $(M)/omec $(M)/oaisim |
| 36 | |
| 37 | .PHONY: ciab run-test reset-test clean |
| 38 | |
| 39 | $(M): |
| 40 | mkdir -p $(M) |
| 41 | |
| 42 | $(M)/system_check: | $(M) |
| 43 | @if [[ $(cpu_family) -eq 6 ]]; then \ |
| 44 | if [[ $(cpu_model) -lt 60 ]]; then \ |
| 45 | echo "FATAL: haswell CPU or newer is required."; \ |
| 46 | exit 1; \ |
| 47 | fi \ |
| 48 | else \ |
| 49 | echo "FATAL: unsupported CPU family."; \ |
| 50 | exit 1; \ |
| 51 | fi |
| 52 | @if [[ $(os_vendor) =~ (Ubuntu) ]]; then \ |
Hyunsun Moon | ad70fc1 | 2019-08-02 16:52:19 -0600 | [diff] [blame] | 53 | if [[ ! $(os_release) =~ (16.04) ]]; then \ |
| 54 | echo "WARN: $(os_vendor) $(os_release) has not been tested."; \ |
| 55 | fi; \ |
| 56 | if dpkg --compare-versions 4.15 gt $(shell uname -r); then \ |
| 57 | echo "FATAL: kernel 4.15 or later is required."; \ |
| 58 | echo "Please upgrade your kernel by running" \ |
| 59 | "apt install --install-recommends linux-generic-hwe-$(os_release)"; \ |
| 60 | exit 1; \ |
Hyunsun Moon | 81c8e23 | 2019-05-21 03:40:22 -0600 | [diff] [blame] | 61 | fi \ |
| 62 | else \ |
| 63 | echo "FAIL: unsupported OS."; \ |
| 64 | exit 1; \ |
| 65 | fi |
| 66 | touch $@ |
| 67 | |
| 68 | $(M)/setup: | $(M) |
| 69 | sudo $(SCRIPTDIR)/cloudlab-disksetup.sh |
| 70 | sudo apt update; sudo apt install -y software-properties-common python-pip jq httpie ipvsadm |
| 71 | touch $@ |
| 72 | |
| 73 | $(BUILD)/kubespray: | $(M)/setup |
| 74 | mkdir -p $(BUILD) |
| 75 | cd $(BUILD); git clone https://github.com/kubernetes-incubator/kubespray.git -b $(KUBESPRAY_VERSION) |
| 76 | |
| 77 | $(VENV)/bin/activate: | $(M)/setup |
| 78 | sudo pip install virtualenv |
| 79 | virtualenv $(VENV) --no-site-packages |
| 80 | |
| 81 | $(M)/kubespray-requirements: $(BUILD)/kubespray | $(VENV)/bin/activate |
| 82 | source "$(VENV)/bin/activate" && \ |
| 83 | pip install -r $(BUILD)/kubespray/requirements.txt |
| 84 | touch $@ |
| 85 | |
| 86 | $(M)/k8s-ready: | $(M)/setup $(BUILD)/kubespray $(VENV)/bin/activate $(M)/kubespray-requirements |
| 87 | source "$(VENV)/bin/activate" && cd $(BUILD)/kubespray; \ |
| 88 | ansible-playbook -b -i inventory/local/hosts.ini \ |
| 89 | -e "{'override_system_hostname' : False, 'disable_swap' : True}" \ |
| 90 | -e "{'docker_version' : $(DOCKER_VERSION)}" \ |
| 91 | -e "{'docker_iptables_enabled' : True}" \ |
| 92 | -e "{'kube_version' : $(K8S_VERSION)}" \ |
| 93 | -e "{'kube_network_plugin_multus' : True}" \ |
| 94 | -e "{'kube_proxy_mode': iptables}" \ |
| 95 | -e "{'kube_pods_subnet' : 192.168.0.0/17, 'kube_service_addresses' : 192.168.128.0/17}" \ |
| 96 | -e "{'kube_apiserver_node_port_range' : 2000-36767}" \ |
| 97 | -e "{'kubeadm_enabled': True}" \ |
| 98 | -e "{'kube_feature_gates' : [SCTPSupport=True]}" \ |
| 99 | -e "{'kubelet_custom_flags' : [--allowed-unsafe-sysctls=net.*]}" \ |
| 100 | -e "{'dns_min_replicas' : 1}" \ |
| 101 | -e "{'helm_enabled' : True, 'helm_version' : $(HELM_VERSION)}" \ |
| 102 | cluster.yml |
| 103 | mkdir -p $(HOME)/.kube |
| 104 | sudo cp -f /etc/kubernetes/admin.conf $(HOME)/.kube/config |
| 105 | sudo chown $(shell id -u):$(shell id -g) $(HOME)/.kube/config |
| 106 | kubectl wait pod -n kube-system --for=condition=Ready --all |
| 107 | touch $@ |
| 108 | |
| 109 | $(M)/helm-ready: | $(M)/k8s-ready |
| 110 | helm init --wait --client-only |
| 111 | helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/ |
| 112 | helm repo add cord https://charts.opencord.org |
| 113 | touch $@ |
| 114 | |
| 115 | $(WORKSPACE)/cord/helm-charts: | $(M)/setup |
| 116 | mkdir -p $(WORKSPACE)/cord |
| 117 | cd $(WORKSPACE)/cord; git clone https://gerrit.opencord.org/helm-charts |
| 118 | |
| 119 | # TODO: need to connect ONOS |
| 120 | $(M)/ovs-setup: | $(M)/setup |
| 121 | sudo apt install -y openvswitch-switch |
| 122 | sudo ovs-vsctl --may-exist add-br br-s1u-net |
| 123 | sudo ovs-vsctl --may-exist add-port br-s1u-net s1u-enb -- set Interface s1u-enb type=internal |
| 124 | sudo ip link set s1u-enb address 0a:00:00:00:00:01 |
| 125 | sudo ip addr add 119.0.0.253/24 dev s1u-enb || true |
| 126 | sudo ip link set s1u-enb up |
| 127 | touch $@ |
| 128 | |
| 129 | /opt/cni/bin/simpleovs: | $(M)/k8s-ready |
| 130 | sudo cp $(RESOURCEDIR)/simpleovs /opt/cni/bin/ |
| 131 | |
| 132 | $(M)/omec: | $(M)/ovs-setup $(M)/helm-ready $(WORKSPACE)/cord/helm-charts /opt/cni/bin/simpleovs |
| 133 | cd $(WORKSPACE)/cord/helm-charts/mcord-release; \ |
| 134 | helm upgrade --install $(HELM_GLOBAL_ARGS) mcord-services mcord-services -f $(CIABVALUES) |
| 135 | $(WORKSPACE)/cord/helm-charts/scripts/wait_for_pods.sh default |
| 136 | touch $@ |
| 137 | |
| 138 | # UE images includes kernel module, ue_ip.ko |
| 139 | # which should be built in the exactly same kernel version of the host machine |
| 140 | $(BUILD)/openairinterface: | $(M)/setup |
| 141 | mkdir -p $(BUILD) |
| 142 | cd $(BUILD); git clone https://github.com/opencord/openairinterface.git |
| 143 | |
| 144 | $(M)/ue-image: | $(M)/k8s-ready $(BUILD)/openairinterface |
| 145 | cd $(BUILD)/openairinterface; \ |
| 146 | sudo docker build . --target lte-uesoftmodem \ |
| 147 | --build-arg build_base=omecproject/oai-base:1.0.0 \ |
| 148 | --file Dockerfile.ue \ |
| 149 | --tag omecproject/lte-uesoftmodem:1.0.0 |
| 150 | touch $@ |
| 151 | |
| 152 | $(M)/oaisim: | $(M)/omec $(M)/ue-image |
| 153 | sudo ip addr add 127.0.0.2/8 dev lo || true |
| 154 | $(eval mme_iface=$(shell ip -4 route list default | awk -F 'dev' '{ print $$2; exit }' | awk '{ print $$1 }')) |
| 155 | cd $(WORKSPACE)/cord/helm-charts; \ |
| 156 | helm upgrade --install $(HELM_GLOBAL_ARGS) oaisim oaisim -f $(CIABVALUES) \ |
| 157 | --set conf.enb.networks.s1_mme.interface=$(mme_iface) |
| 158 | $(WORKSPACE)/cord/helm-charts/scripts/wait_for_pods.sh default |
| 159 | @timeout 60s bash -c \ |
| 160 | "until ip addr show oip1 | grep -q inet; \ |
| 161 | do \ |
| 162 | echo 'Waiting for UE 1 gets IP address'; \ |
| 163 | sleep 3; \ |
| 164 | done" |
| 165 | touch $@ |
| 166 | |
| 167 | $(M)/router: | /opt/cni/bin/simpleovs $(M)/ovs-setup |
| 168 | kubectl apply -f $(RESOURCEDIR)/quagga.yaml |
| 169 | kubectl wait pod --for=condition=Ready -l app=quagga |
| 170 | $(eval spgwu_ip=$(shell kubectl get pod -ojson spgwu-0 2>/dev/null | \ |
| 171 | jq -r '.metadata.annotations["k8s.v1.cni.cncf.io/networks-status"]' | \ |
| 172 | jq -r '.[] | select(.name=="sgi-net") | .ips[0]')) |
| 173 | kubectl exec router ip route add 16.0.0.0/8 via $(spgwu_ip) |
| 174 | touch $@ |
| 175 | |
| 176 | run-test: | $(M)/router |
| 177 | ping -I oip1 13.1.1.254 -c 5 |
| 178 | |
| 179 | reset-test: |
Hyunsun Moon | ad70fc1 | 2019-08-02 16:52:19 -0600 | [diff] [blame] | 180 | kubectl delete po router || true |
| 181 | helm delete --purge oaisim || true |
| 182 | helm delete --purge mcord-services || true |
Hyunsun Moon | 81c8e23 | 2019-05-21 03:40:22 -0600 | [diff] [blame] | 183 | cd $(M); rm -f router oaisim omec |
| 184 | |
| 185 | clean: reset-test |
| 186 | helm delete --purge $(shell helm ls -q) || true |
| 187 | sudo ovs-vsctl del-br br-s1u-net || true |
| 188 | sudo ovs-vsctl del-br br-sgi-net || true |
| 189 | sudo apt remove --purge openvswitch-switch -y |
| 190 | source "$(VENV)/bin/activate" && cd $(BUILD)/kubespray; \ |
| 191 | ansible-playbook -b -i inventory/local/hosts.ini reset.yml |
| 192 | @if [ -d /usr/local/etc/emulab ]; then \ |
| 193 | mount | grep /mnt/extra/kubelet/pods | cut -d" " -f3 | sudo xargs umount; \ |
| 194 | sudo rm -rf /mnt/extra/kubelet; \ |
| 195 | fi |
| 196 | rm -rf $(M) |