-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
284e5e8
commit 0db99dc
Showing
10 changed files
with
154 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
build | ||
output | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
function loadYAMLs() { | ||
namespaceYAML=' | ||
namespaceYAMLContent | ||
' | ||
if [ -f ${BASH_SOURCE%/*}/namespace.yml ]; then | ||
namespaceYAML="`cat ${BASH_SOURCE%/*}/namespace.yml`" | ||
fi | ||
|
||
saYAML=' | ||
saYAMLContent | ||
' | ||
if [ -f ${BASH_SOURCE%/*}/service-account.yml ]; then | ||
saYAML="`cat ${BASH_SOURCE%/*}/service-account.yml`" | ||
fi | ||
|
||
flowAgentYAML=' | ||
flowAgentYAMLContent | ||
' | ||
if [ -f ${BASH_SOURCE%/*}/flow-capture.yml ]; then | ||
flowAgentYAML="`cat ${BASH_SOURCE%/*}/flow-capture.yml`" | ||
fi | ||
|
||
packetAgentYAML=' | ||
packetAgentYAMLContent | ||
' | ||
if [ -f ${BASH_SOURCE%/*}/packet-capture.yml ]; then | ||
packetAgentYAML="`cat ${BASH_SOURCE%/*}/packet-capture.yml`" | ||
fi | ||
|
||
collectorServiceYAML=' | ||
collectorServiceYAMLContent | ||
' | ||
if [ -f ${BASH_SOURCE%/*}/collector-service.yml ]; then | ||
collectorServiceYAML="`cat ${BASH_SOURCE%/*}/collector-service.yml`" | ||
fi | ||
} | ||
|
||
function setup { | ||
echo "Setting up... " | ||
|
||
# check for mandatory arguments | ||
if ! [[ $1 =~ flows|packets ]]; then | ||
echo "invalid setup argument" | ||
return | ||
fi | ||
|
||
# check if cluster is reachable | ||
if ! output=$(oc whoami 2>&1); then | ||
printf 'You must be connected using oc login command first\n' >&2 | ||
exit 1 | ||
fi | ||
|
||
# load yaml files | ||
loadYAMLs | ||
|
||
# apply yamls | ||
echo "creating netobserv-cli namespace" | ||
echo "$namespaceYAML" | oc apply -f - | ||
|
||
echo "creating service account" | ||
echo "$saYAML" | oc apply -f - | ||
|
||
if [ $1 = "flows" ]; then | ||
echo "creating flow-capture agents" | ||
echo "${flowAgentYAML/"{{FLOW_FILTER_VALUE}}"/$2}" | oc apply -f - | ||
oc rollout status daemonset netobserv-cli -n netobserv-cli --timeout 60s | ||
|
||
echo "creating collector service" | ||
echo "$collectorServiceYAML" | oc apply -f - | ||
elif [ $1 = "packets" ]; then | ||
echo "creating packet-capture agents" | ||
echo "${packetAgentYAML/"{{PCA_FILTER_VALUE}}"/$2}" | oc apply -f - | ||
oc rollout status daemonset netobserv-cli -n netobserv-cli --timeout 60s | ||
|
||
# TODO: remove that part once pcap moved to gRPC | ||
echo "forwarding agents ports" | ||
pods=$(oc get pods -n netobserv-cli -l app=netobserv-cli -o name) | ||
port=9900 | ||
nodes="" | ||
ports="" | ||
for pod in $pods | ||
do | ||
echo "forwarding $pod:9999 to local port $port" | ||
pkill --oldest --full "$port:9999" | ||
oc port-forward $pod $port:9999 -n netobserv-cli & # run in background | ||
node=$(oc get $pod -n netobserv-cli -o jsonpath='{.spec.nodeName}') | ||
if [ -z "$ports" ] | ||
then | ||
nodes="$node" | ||
ports="$port" | ||
else | ||
nodes="$nodes,$node" | ||
ports="$ports,$port" | ||
fi | ||
port=$((port+1)) | ||
done | ||
|
||
# TODO: find a better way to ensure port forward are running | ||
sleep 2 | ||
fi | ||
} | ||
|
||
function cleanup { | ||
# TODO: copy output folder from collector before destroying | ||
if output=$(oc whoami 2>&1); then | ||
printf "\nCleaning up... " | ||
oc delete namespace netobserv-cli | ||
else | ||
echo "Cleanup namespace skipped" | ||
return | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
cp -a ./oc/. ./tmp | ||
cp ./scripts/functions.sh ./tmp/functions.sh | ||
|
||
# inject YAML files to functions.sh | ||
sed -i -e '/namespaceYAMLContent/{r ./res/namespace.yml' -e 'd}' ./tmp/functions.sh | ||
sed -i -e '/saYAMLContent/{r ./res/service-account.yml' -e 'd}' ./tmp/functions.sh | ||
sed -i -e '/flowAgentYAMLContent/{r ./res/flow-capture.yml' -e 'd}' ./tmp/functions.sh | ||
sed -i -e '/packetAgentYAMLContent/{r ./res/packet-capture.yml' -e 'd}' ./tmp/functions.sh | ||
sed -i -e '/collectorServiceYAMLContent/{r ./res/collector-service.yml' -e 'd}' ./tmp/functions.sh | ||
|
||
# inject updated functions to oc commands | ||
sed -i -e '/source.*/{r ./tmp/functions.sh' -e 'd}' ./tmp/oc-netobserv-flows | ||
sed -i -e '/source.*/{r ./tmp/functions.sh' -e 'd}' ./tmp/oc-netobserv-packets | ||
sed -i -e '/source.*/{r ./tmp/functions.sh' -e 'd}' ./tmp/oc-netobserv-cleanup | ||
|
||
rm ./tmp/functions.sh | ||
|
||
if [ -z "$1" ] | ||
then | ||
echo "output generated in tmp folder" | ||
else | ||
echo "output generated in $1 folder" | ||
cp -a ./tmp/. ./$1 | ||
rm -rf ./tmp | ||
fi | ||
|