Skip to content

Commit

Permalink
add testscripts for persistent volume and service in k8scluster
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-github-robot authored Aug 12, 2024
2 parents 52e800d + 139aafe commit 8a1618e
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 9 deletions.
2 changes: 2 additions & 0 deletions assets/k8sclusterinfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ k8scluster:
id: 1.28.9
- name: 1.27
id: 1.27.13
- region: [westindia]
# no available version
- region: [common]
available:
- name: 1.29
Expand Down
2 changes: 1 addition & 1 deletion conf/cloud_conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ cloud:
timeout: "9"
threshold: "3"
k8scluster:
enable: "n"
enable: "y"
gcp:
enable: "y"
nlb:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

echo "####################################################################"
echo "## 13. K8SCLUSTER: Get Available Version"
echo "####################################################################"

source ../init.sh

K8SCLUSTERID_ADD=${OPTION03:-1}

K8SCLUSTERID=${K8SCLUSTERID_PREFIX}${INDEX}${REGION}${K8SCLUSTERID_ADD}

echo "NSID: "${NSID}
echo "K8SCLUSTERID=${K8SCLUSTERID}"

PROVIDERNAME="alibaba"
#REGIONNAME="me-east-1"
REGIONNAME="ap-south-1"

resp=$(
curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/availableK8sClusterVersion?providerName=${PROVIDERNAME}\&regionName=${REGIONNAME}
); echo ${resp} | jq ''
echo ""
16 changes: 10 additions & 6 deletions src/testclient/scripts/conf.env
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,12 @@ CommonSpec[$IX]=${CommonSpecMedium[$IX]} # ${CommonSpecLarge[$IX]} # Standar
CommonDiskType[$IX]=default
CommonDiskSize[$IX]=default

CommonK8sVersion[$IX]=1.29.0
CommonK8sUpgradeVersion[$IX]=1.29.2
CommonK8sVersion[$IX]=1.28.10
CommonK8sUpgradeVersion[$IX]=1.29.5

SpecialK8sVersion[$IX]=1.28.9
SpecialK8sUpgradeVersion[$IX]=1.29.4

K8sCreateType[$IX]=type1


Expand Down Expand Up @@ -1197,8 +1201,8 @@ IMAGE_TYPE[$IX,$IY]=${CommonImageType[$IX]}
SPEC_NAME[$IX,$IY]=${CommonSpec[$IX]}
DISK_TYPE[$IX,$IY]=${CommonDiskType[$IX]}
DISK_SIZE[$IX,$IY]=${CommonDiskSize[$IX]}
K8S_VERSION[$IX,$IY]=${CommonK8sVersion[$IX]}
K8S_UPGRADE_VERSION[$IX,$IY]=${CommonK8sUpgradeVersion[$IX]}
K8S_VERSION[$IX,$IY]=${SpecialK8sVersion[$IX]}
K8S_UPGRADE_VERSION[$IX,$IY]=${SpecialK8sUpgradeVersion[$IX]}

# region10
IY=$AzureSouthcentralus
Expand Down Expand Up @@ -1239,8 +1243,8 @@ IMAGE_TYPE[$IX,$IY]=${CommonImageType[$IX]}
SPEC_NAME[$IX,$IY]=${CommonSpec[$IX]}
DISK_TYPE[$IX,$IY]=${CommonDiskType[$IX]}
DISK_SIZE[$IX,$IY]=${CommonDiskSize[$IX]}
K8S_VERSION[$IX,$IY]=${CommonK8sVersion[$IX]}
K8S_UPGRADE_VERSION[$IX,$IY]=${CommonK8sUpgradeVersion[$IX]}
K8S_VERSION[$IX,$IY]=${SpecialK8sVersion[$IX]}
K8S_UPGRADE_VERSION[$IX,$IY]=${SpecialK8sUpgradeVersion[$IX]}

# region13
IY=$AzureJapanwest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash

# From https://aweirdimagination.net/2020/06/28/kill-child-jobs-on-script-exit/
cleanup() {
# kill all processes whose parent is this process
pkill -P $$
}

for sig in INT QUIT HUP TERM; do
trap "
cleanup
trap - $sig EXIT
kill -s $sig "'"$$"' "$sig"
done
trap cleanup EXIT

# From https://www.grepper.com/answers/215915/regex+for+url+in+bash
readonly ENDPOINT_REGEX='^[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]\.[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]$'

SECONDS=0

echo "####################################################################"
echo "## Command (SSH) to K8sCluster (deploy-nginx-with-pvc-to-k8scluster)"
echo "####################################################################"

source ../init.sh

KEEP_PREV_KUBECONFIG=${OPTION02:-n}
K8SCLUSTERID_ADD=${OPTION03:-1}
LOCALIP=`hostname -I | cut -d' ' -f1`

KUBECTL=kubectl
if ! kubectl > /dev/null 2>&1; then
if ! ./kubectl > /dev/null 2>&1; then
# Download kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod u+x ./kubectl
fi
KUBECTL=./kubectl
fi

if [ "${INDEX}" == "0" ]; then
INDEXX=${NumCSP}
for ((cspi = 1; cspi <= INDEXX; cspi++)); do
INDEXY=${NumRegion[$cspi]}
CSP=${CSPType[$cspi]}
for ((cspj = 1; cspj <= INDEXY; cspj++)); do
REGION=$cspj

K8SCLUSTERID=${K8SCLUSTERID_PREFIX}${cspi}${cspj}${K8SCLUSTERID_ADD}

echo "[Get K8sClusterInfo for ${K8SCLUSTERID}]"
K8SCLUSTERINFO=$(curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/$NSID/k8scluster/${K8SCLUSTERID})

TMP_FILE_KUBECONFIG=$(mktemp ./${K8SCLUSTERID}-kubeconfig.XXXXXX || exit 1)
if [ "${KEEP_PREV_KUBECONFIG}" != "y" ]; then
echo "Delete Previous Kubeconfig Files"
rm -f "${K8SCLUSTERID}-kubeconfig."*
#trap 'echo "trapped"; rm -f -- "$TMP_FILE_KUBECONFIG"' EXIT
fi

ENDPOINT=$(jq -r '.AccessInfo.endpoint' <<<"$K8SCLUSTERINFO")
if [[ ! $ENDPOINT =~ $ENDPOINT_REGEX ]]; then
echo ".AccessInfo.endpoint ($ENDPOINT) is not valid"
echo "Try again after about 5 minutes"
continue
fi

echo "TMP_FILE_KUBECONFIG="$TMP_FILE_KUBECONFIG
jq -r '.AccessInfo.kubeconfig' <<<"$K8SCLUSTERINFO" > $TMP_FILE_KUBECONFIG
$KUBECTL --kubeconfig $TMP_FILE_KUBECONFIG apply -f ./nginx-with-pvc.yaml
dozing 1

# max(cspi)=17, max(cspj)=40
LOCALPORT=$((4000+$cspi*64+$cspj))
echo "LOCALPORT="$LOCALPORT
$KUBECTL --kubeconfig $TMP_FILE_KUBECONFIG port-forward --address=0.0.0.0 pod/nginx $LOCALPORT:80 &
dozing 1

echo "[K8sCluster Nginx for PV/PVC Test: complete to create a k8scluster in $CSP[$REGION]]"
echo "You can access to http://"$LOCALIP":"$LOCALPORT "until exiting by Ctrl+C"

$KUBECTL --kubeconfig $TMP_FILE_KUBECONFIG get pv,pvc &
done
done
wait

fi

echo "Done!"
duration=$SECONDS

printElapsed $@
echo ""

Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,28 @@ if [ "${INDEX}" == "0" ]; then
if [[ ! $ENDPOINT =~ $ENDPOINT_REGEX ]]; then
echo ".AccessInfo.endpoint ($ENDPOINT) is not valid"
echo "Try again after about 5 minutes"
break
continue
fi

echo "TMP_FILE_KUBECONFIG="$TMP_FILE_KUBECONFIG
jq -r '.AccessInfo.kubeconfig' <<<"$K8SCLUSTERINFO" > $TMP_FILE_KUBECONFIG
$KUBECTL --kubeconfig $TMP_FILE_KUBECONFIG apply -f https://github.com/weaveworks/scope/releases/download/v1.13.2/k8s-scope.yaml
dozing 10
dozing 1

# max(cspi)=17, max(cspj)=40
LOCALPORT=$((4000+$cspi*64+$cspj))
echo "LOCALPORT="$LOCALPORT
$KUBECTL --kubeconfig $TMP_FILE_KUBECONFIG port-forward --address=0.0.0.0 -n weave "$($KUBECTL --kubeconfig $TMP_FILE_KUBECONFIG get -n weave pod --selector=weave-scope-component=app -o jsonpath='{.items..metadata.name}')" $LOCALPORT:4040 &
dozing 1

echo "[K8sCluster Weavescope: complete to create a k8scluster in $CSP[$REGION]]"
echo "You can access to http://localhost:"$LOCALPORT "until exiting by Ctrl+C"

$KUBECTL --kubeconfig $TMP_FILE_KUBECONFIG patch svc -n weave weave-scope-app -p '{"spec": {"type": "LoadBalancer"}}' &
dozing 1

echo "You can access to EXTERNAL-IP(LoadBalancer)until exiting by Ctrl+C"
$KUBECTL --kubeconfig $TMP_FILE_KUBECONFIG get svc -n weave weave-scope-app &
done
done
wait
Expand Down
35 changes: 35 additions & 0 deletions src/testclient/scripts/sequentialFullTest/nginx-with-pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: html-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
initContainers:
- name: init-nginx
image: busybox
command: ['sh', '-c', 'echo "<html><body><h1>Welcome to Nginx for PV/PVC Test</h1></body></html>" > /usr/share/nginx/html/index.html']
volumeMounts:
- name: html-volume
mountPath: /usr/share/nginx/html
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
volumeMounts:
- name: html-volume
mountPath: /usr/share/nginx/html
volumes:
- name: html-volume
persistentVolumeClaim:
claimName: html-pvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash

# From https://aweirdimagination.net/2020/06/28/kill-child-jobs-on-script-exit/
cleanup() {
# kill all processes whose parent is this process
pkill -P $$
}

for sig in INT QUIT HUP TERM; do
trap "
cleanup
trap - $sig EXIT
kill -s $sig "'"$$"' "$sig"
done
trap cleanup EXIT

# From https://www.grepper.com/answers/215915/regex+for+url+in+bash
readonly ENDPOINT_REGEX='^[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]\.[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]$'

SECONDS=0

echo "####################################################################"
echo "## Command (SSH) to K8sCluster (undeploy-nginx-with-pvc-from-k8scluster)"
echo "####################################################################"

source ../init.sh

KEEP_PREV_KUBECONFIG=${OPTION02:-n}
K8SCLUSTERID_ADD=${OPTION03:-1}
LOCALIP=`hostname -I | cut -d' ' -f1`

KUBECTL=kubectl
if ! kubectl > /dev/null 2>&1; then
if ! ./kubectl > /dev/null 2>&1; then
# Download kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod u+x ./kubectl
fi
KUBECTL=./kubectl
fi

if [ "${INDEX}" == "0" ]; then
INDEXX=${NumCSP}
for ((cspi = 1; cspi <= INDEXX; cspi++)); do
INDEXY=${NumRegion[$cspi]}
CSP=${CSPType[$cspi]}
for ((cspj = 1; cspj <= INDEXY; cspj++)); do
REGION=$cspj

K8SCLUSTERID=${K8SCLUSTERID_PREFIX}${cspi}${cspj}${K8SCLUSTERID_ADD}

echo "[Get K8sClusterInfo for ${K8SCLUSTERID}]"
K8SCLUSTERINFO=$(curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/$NSID/k8scluster/${K8SCLUSTERID})

TMP_FILE_KUBECONFIG=$(mktemp ./${K8SCLUSTERID}-kubeconfig.XXXXXX || exit 1)
if [ "${KEEP_PREV_KUBECONFIG}" != "y" ]; then
echo "Delete Previous Kubeconfig Files"
rm -f "${K8SCLUSTERID}-kubeconfig."*
#trap 'echo "trapped"; rm -f -- "$TMP_FILE_KUBECONFIG"' EXIT
fi

ENDPOINT=$(jq -r '.AccessInfo.endpoint' <<<"$K8SCLUSTERINFO")
if [[ ! $ENDPOINT =~ $ENDPOINT_REGEX ]]; then
echo ".AccessInfo.endpoint ($ENDPOINT) is not valid"
echo "Try again after about 5 minutes"
continue
fi

echo "TMP_FILE_KUBECONFIG="$TMP_FILE_KUBECONFIG
jq -r '.AccessInfo.kubeconfig' <<<"$K8SCLUSTERINFO" > $TMP_FILE_KUBECONFIG
$KUBECTL --kubeconfig $TMP_FILE_KUBECONFIG delete -f ./nginx-with-pvc.yaml
dozing 10

$KUBECTL --kubeconfig $TMP_FILE_KUBECONFIG get pv,pvc &
done
done
wait

fi

echo "Done!"
duration=$SECONDS

printElapsed $@
echo ""

0 comments on commit 8a1618e

Please sign in to comment.