-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMakefile
More file actions
208 lines (176 loc) · 7.53 KB
/
Copy pathMakefile
File metadata and controls
208 lines (176 loc) · 7.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# Copyright 2018-present Open Networking Foundation
#
# SPDX-License-Identifier: Apache-2.0
SHELL := /bin/bash
MAKEDIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
BUILD ?= $(MAKEDIR)/build
M ?= $(BUILD)/milestones
SCRIPTDIR := $(MAKEDIR)/scripts
RESOURCEDIR := $(MAKEDIR)/resources
WORKSPACE ?= $(HOME)
VENV ?= $(BUILD)/venv/aiab
NS?=hexa
HELM_ARGS?=--create-namespace
HELM_ACTION?=install
GET_HELM = get_helm.sh
# KUBESPRAY_VERSION ?= release-2.17
DOCKER_VERSION ?= '20.10'
HELM_VERSION ?= v3.10.3
KUBECTL_VERSION ?= v1.23.15
RKE2_K8S_VERSION ?= v1.25.15+rke2r2
K8S_VERSION ?= v1.25.6
LPP_VERSION ?= v0.0.24
# OAISIM_UE_IMAGE ?= andybavier/lte-uesoftmodem:1.1.0-$(shell uname -r)
ENABLE_ROUTER ?= true
ENABLE_OAISIM ?= true
ENABLE_GNBSIM ?= false
ENABLE_SUBSCRIBER_PROXY ?= false
GNBSIM_COLORS ?= true
K8S_INSTALL ?= rke2
CTR_CMD := sudo /var/lib/rancher/rke2/bin/ctr --address /run/k3s/containerd/containerd.sock --namespace k8s.io
PROXY_ENABLED ?= false
HTTP_PROXY ?= ${http_proxy}
HTTPS_PROXY ?= ${https_proxy}
NO_PROXY ?= ${no_proxy}
ONECLOUD ?= false
NODE_IP ?= $(shell ip route get 8.8.8.8 | grep -oP 'src \K\S+')
ifndef NODE_IP
$(error NODE_IP is not set)
endif
HELM_GLOBAL_ARGS ?=
cpu_family := $(shell lscpu | grep 'CPU family:' | awk '{print $$3}')
cpu_model := $(shell lscpu | grep 'Model:' | awk '{print $$2}')
os_vendor := $(shell lsb_release -i -s)
os_release := $(shell lsb_release -r -s)
USER := $(shell whoami)
.PHONY: node-prep clean
$(M):
mkdir -p $(M)
$(M)/system-check: | $(M)
@if [[ $(cpu_family) -eq 6 ]]; then \
if [[ $(cpu_model) -lt 60 ]]; then \
echo "FATAL: haswell CPU or newer is required."; \
exit 1; \
fi \
else \
echo "FATAL: unsupported CPU family."; \
exit 1; \
fi
@if [[ $(os_vendor) =~ (Ubuntu) ]]; then \
if [[ ! $(os_release) =~ (18.04) ]]; then \
echo "WARN: $(os_vendor) $(os_release) has not been tested."; \
fi; \
if dpkg --compare-versions 4.15 gt $(shell uname -r); then \
echo "FATAL: kernel 4.15 or later is required."; \
echo "Please upgrade your kernel by running" \
"apt install --install-recommends linux-generic-hwe-$(os_release)"; \
exit 1; \
fi \
else \
echo "FAIL: unsupported OS."; \
exit 1; \
fi
touch $@
ifeq ($(K8S_INSTALL),rke2)
$(M)/initial-setup: | $(M)
# sudo $(SCRIPTDIR)/cloudlab-disksetup.sh
sudo apt update; sudo apt install -y software-properties-common python3 python3-pip python3-venv jq httpie ipvsadm apparmor apparmor-utils
systemctl list-units --full -all | grep "docker.service" || sudo apt install -y docker.io
sudo adduser $(USER) docker || true
touch $(M)/initial-setup
ifeq ($(PROXY_ENABLED),true)
$(M)/proxy-setting: | $(M)
echo "Defaults env_keep += \"HTTP_PROXY HTTPS_PROXY NO_PROXY http_proxy https_proxy no_proxy\"" | sudo EDITOR='tee -a' visudo -f /etc/sudoers.d/proxy
echo "HTTP_PROXY=$(HTTP_PROXY)" >> rke2-server
echo "HTTPS_PROXY=$(HTTPS_PROXY)" >> rke2-server
echo "NO_PROXY=$(NO_PROXY),.cluster.local,.svc,$(NODE_IP),192.168.84.0/24,192.168.85.0/24,$(RAN_SUBNET)" >> rke2-server
sudo mv rke2-server /etc/default/
echo "[Service]" >> http-proxy.conf
echo "Environment='HTTP_PROXY=$(HTTP_PROXY)'" >> http-proxy.conf
echo "Environment='HTTPS_PROXY=$(HTTPS_PROXY)'" >> http-proxy.conf
echo "Environment='NO_PROXY=$(NO_PROXY)'" >> http-proxy.conf
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo mv http-proxy.conf /etc/systemd/system/docker.service.d
sudo systemctl daemon-reload
sudo systemctl restart docker
touch $(M)/proxy-setting
else
$(M)/proxy-setting: | $(M)
@echo -n ""
touch $(M)/proxy-setting
endif
$(M)/setup: | $(M)/initial-setup $(M)/proxy-setting
touch $@
endif
ifeq ($(K8S_INSTALL),rke2)
$(M)/k8s-ready: | $(M)/setup
sudo mkdir -p /etc/rancher/rke2/
[ -d /usr/local/etc/emulab ] && [ ! -e /var/lib/rancher ] && sudo ln -s /var/lib/rancher /mnt/extra/rancher || true # that link gets deleted on cleanup
echo "cni: multus,calico" >> config.yaml
echo "cluster-cidr: 192.168.84.0/24" >> config.yaml
echo "service-cidr: 192.168.85.0/24" >> config.yaml
echo "kubelet-arg:" >> config.yaml
echo "- --allowed-unsafe-sysctls="net.*"" >> config.yaml
echo "- --node-ip="$(NODE_IP)"" >> config.yaml
echo "pause-image: k8s.gcr.io/pause:3.3" >> config.yaml
echo "kube-proxy-arg:" >> config.yaml
echo "- --metrics-bind-address="0.0.0.0:10249"" >> config.yaml
echo "- --proxy-mode="ipvs"" >> config.yaml
echo "kube-apiserver-arg:" >> config.yaml
echo "- --service-node-port-range="2000-36767"" >> config.yaml
sudo mv config.yaml /etc/rancher/rke2/
curl -sfL https://get.rke2.io | sudo INSTALL_RKE2_VERSION=$(RKE2_K8S_VERSION) sh -
sudo systemctl enable rke2-server.service
sudo systemctl start rke2-server.service
sudo /var/lib/rancher/rke2/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml wait nodes --for=condition=Ready --all --timeout=300s
sudo /var/lib/rancher/rke2/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml wait deployment -n kube-system --for=condition=available --all --timeout=300s
@$(eval STORAGE_CLASS := $(shell /var/lib/rancher/rke2/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml get storageclass -o name))
@echo "STORAGE_CLASS: ${STORAGE_CLASS}"
if [ "$(STORAGE_CLASS)" == "" ]; then \
sudo /var/lib/rancher/rke2/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/$(LPP_VERSION)/deploy/local-path-storage.yaml --wait=true; \
sudo /var/lib/rancher/rke2/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml patch storageclass local-path -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'; \
fi
curl -LO "https://dl.k8s.io/release/$(KUBECTL_VERSION)/bin/linux/amd64/kubectl"
sudo chmod +x kubectl
sudo mv kubectl /usr/local/bin/
kubectl version --client
mkdir -p $(HOME)/.kube
sudo cp /etc/rancher/rke2/rke2.yaml $(HOME)/.kube/config
sudo chown -R $(shell id -u):$(shell id -g) $(HOME)/.kube
touch $@
kubectl apply -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.72.0/example/prometheus-operator-crd/monitoring.coreos.com_servicemonitors.yaml
$(M)/helm-ready: | $(M)/k8s-ready
curl -fsSL -o ${GET_HELM} https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 ${GET_HELM}
sudo DESIRED_VERSION=$(HELM_VERSION) ./${GET_HELM}
touch $@
endif
/opt/cni/bin/static: | $(M)/k8s-ready
mkdir -p $(BUILD)/cni-plugins; cd $(BUILD)/cni-plugins; \
wget https://github.com/containernetworking/plugins/releases/download/v0.8.2/cni-plugins-linux-amd64-v0.8.2.tgz && \
tar xvfz cni-plugins-linux-amd64-v0.8.2.tgz
sudo cp $(BUILD)/cni-plugins/static /opt/cni/bin/
node-prep: | $(M)/helm-ready /opt/cni/bin/static
clean-systemd:
cd /etc/systemd/network && sudo rm -f */macvlan.conf
cd /etc/systemd/system && sudo rm -f && sudo systemctl daemon-reload
ifeq ($(K8S_INSTALL),rke2)
clean: | clean-systemd
sudo /usr/local/bin/rke2-uninstall.sh || true
sudo rm -rf /usr/local/bin/kubectl
rm -rf $(M)
rm -rf $(BUILD)
rm -rf $(MAKEDIR)/get_helm.sh
endif
# Target to set up Kubernetes resources
setup_k8s_resources:
@echo "Creating namespace 'hexa'..."
kubectl create ns hexa || echo "Namespace 'hexa' already exists."
@echo "Applying IPPool configuration..."
kubectl apply -f $(MAKEDIR)/src/cli/eupf-ippool.yaml
sudo apt install tmux -y
touch $(M)/setup_k8s_resources-done
# Target to run HEXAeBPF CLI
run_hexaebpf: node-prep setup_k8s_resources
@echo "Running HEXAeBPF CLI in a new tmux session..."
tmux new-session -d -s hexaebpf "python3 $(MAKEDIR)/src/cli/hexaebpf_cli.py; tmux kill-session -t hexaebpf" \; attach