Skip to content
Snippets Groups Projects
Commit 04c11714 authored by Sebastien Merle's avatar Sebastien Merle
Browse files

Add TE service skeleton

parent 80d1e119
No related branches found
No related tags found
2 merge requests!142Release TeraFlowSDN 2.1,!133Integration of TE component
......@@ -168,5 +168,8 @@ delete_local_deployment.sh
local_docker_deployment.sh
local_k8s_deployment.sh
# asdf configuration
.tool-versions
# Other logs
**/logs/*.log.*
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# 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.
apiVersion: apps/v1
kind: Deployment
metadata:
name: teservice
spec:
selector:
matchLabels:
app: teservice
template:
metadata:
labels:
app: teservice
spec:
terminationGracePeriodSeconds: 5
shareProcessNamespace: true
containers:
- name: server
image: registry.gitlab.com/teraflow-h2020/controller/te:latest
imagePullPolicy: Always
ports:
- containerPort: 11010
env:
- name: ERLANG_LOGGER_LEVEL
value: "debug"
- name: ERLANG_COOKIE
value: "tfte-unsafe-cookie"
- name: ERLANG_NODE_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: ERLANG_NODE_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
readinessProbe:
initialDelaySeconds: 10
periodSeconds: 10
exec:
command: ["/tfte/bin/tfte", "status"]
livenessProbe:
initialDelaySeconds: 10
periodSeconds: 10
exec:
command: ["/tfte/bin/tfte", "status"]
resources:
requests:
cpu: 250m
memory: 512Mi
limits:
cpu: 700m
memory: 1024Mi
---
apiVersion: v1
kind: Service
metadata:
name: teservice
spec:
type: ClusterIP
selector:
app: teservice
ports:
- name: grpc
protocol: TCP
port: 11010
targetPort: 11010
Dockerfile
_build
README.md
.tool-versions
.tool-versions
.rebar3
_*
.eunit
*.o
*.beam
*.plt
*.swp
*.swo
.erlang.cookie
ebin
log
erl_crash.dump
.rebar
logs
_build
.idea
*.iml
rebar3.crashdump
*~
config/dev.config
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# 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.
# Multi-stage Docker image build
# Build stage 0
FROM erlang:24.3-alpine
RUN mkdir /buildroot
WORKDIR /buildroot
# Copy our Erlang application
COPY . tfte
# And build the release
WORKDIR tfte
RUN rebar3 as prod release
# Build stage 1
FROM alpine
# Install some libs
RUN apk add --no-cache libgcc libstdc++ && \
apk add --no-cache openssl && \
apk add --no-cache ncurses-libs
# Install the released application
COPY --from=0 /buildroot/tfte/_build/prod/rel/tfte /tfte
# Expose relevant ports
#EXPOSE ????
ARG ERLANG_LOGGER_LEVEL_DEFAULT=debug
ARG ERLANG_COOKIE_DEFAULT=tfte-unsafe-cookie
ARG ERLANG_NODE_IP_DEFAULT=127.0.0.1
ARG ERLANG_NODE_NAME_DEFAULT=tfte
ENV ERLANG_LOGGER_LEVEL=$ERLANG_LOGGER_LEVEL_DEFAULT
ENV ERLANG_COOKIE=$ERLANG_COOKIE_DEFAULT
ENV ERLANG_NODE_IP=$ERLANG_NODE_IP_DEFAULT
ENV ERLANG_NODE_NAME=$ERLANG_NODE_NAME_DEFAULT
ENTRYPOINT ["/tfte/bin/tfte"]
CMD ["foreground"]
TeraFlow Traffic Engineering Service
====================================
The Traffic Engineering service is tested on Ubuntu 20.04. Follow the instructions below to build, test, and run this service on your local environment.
## Build
$ rebar3 compile
## Execute Unit Tests
$ rebar3 eunit
## Run Service Console
First you need to crete a configuration file if not already done, and customize it if required:
$ cp config/dev.config.template config/dev.config
Then you can start the service in console mode:
$ rebar3 shell
## Build Docker Image
$ docker build -t te:dev .
## Run Docker Container
$ docker run -d --name te --init te:dev
## Open a Console to a Docker Container
$ docker exec -it te /tfte/bin/tfte remote_console
## Open a Console to a Kubernetes Pod
$ kubectl --namespace tfs exec -ti $(kubectl --namespace tfs get pods --selector=app=teservice -o name) -- /tfte/bin/tfte remote_console
## Show Logs
$ docker logs te
\ No newline at end of file
{application, tfte,
[{description, "Teraflow Traffic Engineering Service"},
{vsn, "0.1.0"},
{registered, []},
{mod, {tfte_app, []}},
{applications,
[kernel,
stdlib
]},
{env,[]},
{modules, []},
{licenses, ["Apache 2.0"]},
{links, []}
]}.
%%%-------------------------------------------------------------------
%% @doc tfte public API
%% @end
%%%-------------------------------------------------------------------
-module(tfte_app).
-behaviour(application).
-export([start/2, stop/1]).
start(_StartType, _StartArgs) ->
tfte_sup:start_link().
stop(_State) ->
ok.
%% internal functions
%%%-------------------------------------------------------------------
%% @doc tfte top level supervisor.
%% @end
%%%-------------------------------------------------------------------
-module(tfte_sup).
-behaviour(supervisor).
-export([start_link/0]).
-export([init/1]).
-define(SERVER, ?MODULE).
start_link() ->
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
%% sup_flags() = #{strategy => strategy(), % optional
%% intensity => non_neg_integer(), % optional
%% period => pos_integer()} % optional
%% child_spec() = #{id => child_id(), % mandatory
%% start => mfargs(), % mandatory
%% restart => restart(), % optional
%% shutdown => shutdown(), % optional
%% type => worker(), % optional
%% modules => modules()} % optional
init([]) ->
SupFlags = #{strategy => one_for_all,
intensity => 0,
period => 1},
ChildSpecs = [],
{ok, {SupFlags, ChildSpecs}}.
%% internal functions
[
{tfte, [
]},
{kernel, [
{logger_level, debug},
{logger, [
{handler, default, logger_std_h, #{
level => debug,
filter_default => log,
config => #{type => standard_io},
formatter => {logger_formatter, #{
legacy_header => false,
single_line => true
}}
}}
]}
]}
].
\ No newline at end of file
[
{tfte, [
]},
{kernel, [
{logger_level, ${ERLANG_LOGGER_LEVEL}},
{logger, [
{handler, default, logger_std_h, #{
level => info,
filter_default => log,
config => #{type => standard_io},
formatter => {logger_formatter, #{
legacy_header => false,
single_line => true
}}
}}
]}
]}
].
\ No newline at end of file
+C multi_time_warp
+sbwt none
-name ${ERLANG_NODE_NAME}@${ERLANG_NODE_IP}
-setcookie ${ERLANG_COOKIE}
{erl_opts, [debug_info]}.
{deps, [
]}.
{shell, [
{config, "config/dev.config"},
{apps, [tfte]}
]}.
{relx, [
{release, {tfte, "1.0.0"}, [tfte]},
{vm_args_src, "config/vm.args.src"},
{sys_config_src, "config/sys.config.src"},
{dev_mode, true},
{include_erts, false},
{extended_start_script, true}
]}.
{profiles, [
{prod, [
{relx, [
{dev_mode, false},
{include_erts, true},
{include_src, false}
]}
]}
]}.
[].
# 1.5. Setup Erlang Environment
First we need to install Erlang. There is multiple way, for development we will be using asdf.
## 1.5.1. Setup Erlang using asdf
First, install any missing dependencies:
sudo apt install curl git autoconf libncurses-dev build-essential m4 libssl-dev
Download asdf:
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.2
Make asdf activate on login by adding these lines at the end of the `~/.bashrc` file:
. $HOME/.asdf/asdf.sh
. $HOME/.asdf/completions/asdf.bash
Logout and log back in to activate asdf.
Install asdf plugin for Erlang:
asdf plugin add erlang https://github.com/asdf-vm/asdf-erlang.git
Install Erlang:
asdf install erlang 24.3.4.2
Activate Erlang locally for TFS controller:
cd tfs-ctrl/
asdf local erlang 24.3.4.2
Install rebar3:
cd ~
git clone https://github.com/erlang/rebar3.git
cd rebar3
asdf local erlang 24.3.4.2
./bootstrap
./rebar3 local install
Update `~/.bashrc` to use rebar3 by adding this line at the end:
export PATH=$HOME/.cache/rebar3/bin:$PATH
Logout and log back in.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment