Skip to content

Commit

Permalink
Update template ovls
Browse files Browse the repository at this point in the history
  • Loading branch information
uablrek authored and sriramy committed May 31, 2024
1 parent 8696726 commit 54b6400
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 149 deletions.
51 changes: 31 additions & 20 deletions ovl/template-k8s/template-k8s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## Some influential environment variables:
##
## xcluster_TZ="EST+5EDT,M3.2.0/2,M11.1.0/2"
## xcluster_PREFIX=fd00:
## xcluster_BASE_FAMILY=IPv6
## xcluster_FEATURE_GATES=NFTablesProxyMode=true
## xcluster_PROXY_MODE=iptables
## xcluster_DOMAIN=cluster.local
Expand Down Expand Up @@ -40,20 +40,23 @@ log() {
## env
## Print environment.
cmd_env() {
test "$envset" = "yes" && return 0
envset=yes

test -n "$__nvm" || __nvm=4
test -n "$__nrouters" || __nrouters=1
test -n "$__replicas" || __replicas=4
test -n "$__e2e" || __e2e=$GOPATH/src/k8s.io/kubernetes/_output/bin/e2e.test
test -n "$xcluster_DOMAIN" || export xcluster_DOMAIN=xcluster
test -n "$xcluster_PREFIX" || export xcluster_PREFIX=fd00:

if test "$cmd" = "env"; then
local opt="nvm|nrouters|replicas|log|e2e"
local xenv="DOMAIN|PREFIX"
local opt="nvm|nrouters|replicas|cni|log"
local xenv="DOMAIN|PREFIX|BASE_FAMILY"
set | grep -E "^(__($opt)|xcluster_($xenv))="
exit 0
fi

test -n "$long_opts" && export $long_opts
test -n "$XCLUSTER" || die 'Not set [$XCLUSTER]'
test -x "$XCLUSTER" || die "Not executable [$XCLUSTER]"
eval $($XCLUSTER env)
Expand All @@ -64,6 +67,7 @@ cmd_env() {
## test [--log=] [--xterm] [--no-stop] <test-suite> [ovls...] > logfile
## Exec tests
cmd_test() {
cd $dir
start=starts
test "$__xterm" = "yes" && start=start
rm -f $XCLUSTER_TMP/cdrom.iso
Expand All @@ -75,6 +79,7 @@ cmd_test() {
fi

if test -n "$__log"; then
mkdir -p $(dirname "$__log")
date > $__log || die "Can't write to log [$__log]"
test_$t $@ >> $__log
else
Expand All @@ -84,17 +89,33 @@ cmd_test() {
now=$(date +%s)
log "Xcluster test ended. Total time $((now-begin)) sec"
}
## test [--wait] start_empty
## test default
## A combo test that setup an environment and execute selected tests.
## Intended for regression or CI testing
test_default() {
$me test connectivity $@ || die "test connectivity"
}
## test [--wait] [--taint] [--cni=] start_empty
## Start empty cluster
test_start_empty() {
cd $dir
if test -n "$TOPOLOGY"; then
tlog "Using TOPOLOGY=$TOPOLOGY"
. $($XCLUSTER ovld network-topology)/$TOPOLOGY/Envsettings
fi
xcluster_start network-topology . $@
local cni
test -n "$__cni" && cni=k8s-cni-$__cni
if test "$__cni" = "cilium"; then
# Cilium is a memory-hog and replaces kube-proxy
export __mem=$((__mem + 1024))
export __mem1=$((__mem1 + 1024))
test -n "$xcluster_PROXY_MODE" || export xcluster_PROXY_MODE=disabled
fi

xcluster_start network-topology $cni . $@
otc 1 check_namespaces
otc 1 check_nodes
test "$__taint" = "yes" && kubectl taint nodes vm-001 \
node-role.kubernetes.io/control-plane:NoSchedule
test "$__wait" = "yes" && otc 1 wait
}
## test [--replicas=] start
Expand All @@ -113,18 +134,6 @@ test_start_alpine() {
otc 1 "svc alpine 10.0.0.1"
otc 1 "deployment --replicas=$__replicas alpine"
}
## test default
## A combo test that setup an environment and execute selected tests.
## Intended for regression or CI testing
test_default() {
unset __no_start
test_start $@
__no_start=yes
__no_stop=yes
test_connectivity
unset __no_stop
xcluster_stop
}
## test connectivity
## Basic connectivity via a service
test_connectivity() {
Expand All @@ -134,6 +143,8 @@ test_connectivity() {
otc 2 "mconnect mconnect.default.svc $nconn $__replicas"
otc 2 "mconnect 10.0.0.0 $nconn $__replicas"
otc 2 "mconnect $xcluster_PREFIX:10.0.0.0 $nconn $__replicas"
otc 201 "mconnect 10.0.0.0 $nconn $__replicas"
otc 201 "mconnect $xcluster_PREFIX:10.0.0.0 $nconn $__replicas"
xcluster_stop
}

Expand Down Expand Up @@ -162,10 +173,10 @@ while echo "$1" | grep -q '^--'; do
o=$(echo "$1" | sed -e 's,-,_,g')
eval "$o=yes"
fi
long_opts="$long_opts $o"
shift
done
unset o v
long_opts=`set | grep '^__' | cut -d= -f1`

# Execute command
trap "die Interrupted" INT TERM
Expand Down
87 changes: 54 additions & 33 deletions ovl/template/template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,53 +26,71 @@ test -n "$1" || help
echo "$1" | grep -qi "^help\|-h" && help

log() {
echo "$prg: $*" >&2
}
dbg() {
test -n "$__verbose" && echo "$prg: $*" >&2
echo "$*" >&2
}

## env
## Print environment.
cmd_env() {
test "$envset" = "yes" && return 0
envset=yes

test -n "$PREFIX" || PREFIX=fd00:
test -n "$__nvm" || __nvm=4
test -n "$__nrouters" || __nrouters=1
export xcluster_PREFIX=$PREFIX

if test "$cmd" = "env"; then
set | grep -E '^(__.*)='
retrun 0
local opt="nvm|nrouters|log"
local xenv="PREFIX"
set | grep -E "^(__($opt)|xcluster_($xenv))="
exit 0
fi

test -n "$long_opts" && export $long_opts
test -n "$XCLUSTER" || die 'Not set [$XCLUSTER]'
test -x "$XCLUSTER" || die "Not executable [$XCLUSTER]"
eval $($XCLUSTER env)
}

##
## test [--xterm] [--no-stop] test <test-name> [ovls...] > $log
## test [--xterm] [--no-stop] > $log # default test
## test [--xterm] [--no-stop] [opts...] <test-name> [ovls...]
## test # default test
## Exec tests
##
cmd_test() {
cmd_env
start=starts
test "$__xterm" = "yes" && start=start
rm -f $XCLUSTER_TMP/cdrom.iso
cd $dir
start=starts
test "$__xterm" = "yes" && start=start
rm -f $XCLUSTER_TMP/cdrom.iso

if test -n "$1"; then
t=$1
local t=default
if test -n "$1"; then
local t=$1
shift
test_$t $@
else
test_basic
fi
fi

now=$(date +%s)
tlog "Xcluster test ended. Total time $((now-begin)) sec"
}
if test -n "$__log"; then
mkdir -p $(dirname "$__log")
date > $__log || die "Can't write to log [$__log]"
test_$t $@ >> $__log
else
test_$t $@
fi

now=$(date +%s)
log "Xcluster test ended. Total time $((now-begin)) sec"
}
## test default
## Execute the default test-suite. Intended for CI
test_default() {
$me test basic $@ || die "basic"
}
## test start_empty
## Start cluster
test_start_empty() {
export __image=$XCLUSTER_HOME/hd.img
test -r $__image || die "Not readable [$__image]"
test -r $__kbin || die "Not readable [$__kbin]"
echo "$XOVLS" | grep -q private-reg && unset XOVLS
test -n "$TOPOLOGY" && \
. $($XCLUSTER ovld network-topology)/$TOPOLOGY/Envsettings
Expand All @@ -84,14 +102,16 @@ test_start_empty() {
test_start() {
test_start_empty $@
}
## test basic (default)
## test basic
## Just start and stop
test_basic() {
test_start $@
xcluster_stop
}

test -z "$__nvm" && __nvm=X
. $($XCLUSTER ovld test)/default/usr/lib/xctest
test "$__nvm" = "X" && unset __nvm
indent=''

##
Expand All @@ -101,21 +121,22 @@ shift
grep -q "^cmd_$cmd()" $0 $hook || die "Invalid command [$cmd]"

while echo "$1" | grep -q '^--'; do
if echo $1 | grep -q =; then
o=$(echo "$1" | cut -d= -f1 | sed -e 's,-,_,g')
v=$(echo "$1" | cut -d= -f2-)
eval "$o=\"$v\""
else
o=$(echo "$1" | sed -e 's,-,_,g')
eval "$o=yes"
fi
shift
if echo $1 | grep -q =; then
o=$(echo "$1" | cut -d= -f1 | sed -e 's,-,_,g')
v=$(echo "$1" | cut -d= -f2-)
eval "$o=\"$v\""
else
o=$(echo "$1" | sed -e 's,-,_,g')
eval "$o=yes"
fi
long_opts="$long_opts $o"
shift
done
unset o v
long_opts=`set | grep '^__' | cut -d= -f1`

# Execute command
trap "die Interrupted" INT TERM
cmd_env
cmd_$cmd "$@"
status=$?
rm -rf $tmp
Expand Down
Loading

0 comments on commit 54b6400

Please sign in to comment.