Skip to content

Commit 16a556e

Browse files
committed
test suite + action
1 parent 49258b0 commit 16a556e

11 files changed

+79
-21
lines changed

.github/workflows/tests.yaml

+31-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
## Copyright © 2022-2023, Oracle and/or its affiliates.
2+
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
3+
14
name: tests
25
on:
6+
# workflow_dispatch
37
schedule:
4-
- cron: '0 7 * * 1' # Mondays at 7AM
8+
- cron: '0 15 * * 7' # Sundays at 8AM PST
59
jobs:
610
tests:
711
runs-on: ubuntu-latest
@@ -14,23 +18,43 @@ jobs:
1418
COMPARTMENT_OCID: ${{ secrets.COMPARTMENT_OCID }}
1519
steps:
1620
- uses: actions/checkout@v3
17-
- name: Run tests
21+
- name: Install OCI CLI
1822
run: |
19-
# Install OCI CLI
2023
wget https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh
2124
chmod +x ./install.sh
22-
bash -c "./install.sh --accept-all-defaults"
25+
./install.sh --accept-all-defaults
2326
mkdir -p ~/.oci
2427
echo "$OCI_KEY" > ~/.oci/oci_ci_user.pem
2528
echo "$OCI_CONFIG" > ~/.oci/config
26-
# install terraform and kubectl
29+
echo "~/bin" >> $GITHUB_PATH
30+
export PATH=$PATH:/home/runner/bin
31+
oci setup repair-file-permissions --file /home/runner/.oci/config
32+
oci setup repair-file-permissions --file /home/runner/.oci/oci_ci_user.pem
33+
- name: Check Deps
34+
run: |
35+
# sudo apt list -a kubectl
2736
# curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
2837
# sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
29-
sudo apt-get update
30-
sudo apt-get install -y terraform=1.2.9 kubectl=1.24.12
3138
# sudo apt-get update && sudo apt-get install -y gnupg software-properties-common
3239
# wget -O- https://apt.releases.hashicorp.com/gpg | \
3340
# gpg --dearmor | \
3441
# sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
42+
# sudo apt-get install -y terraform=1.2.9 kubectl=1.24.12
3543
44+
# install terraform and kubectl
45+
# sudo apt-get update
46+
kubectl version --client=true
47+
terraform version
48+
49+
- name: Run tests
50+
run: |
51+
pwd
52+
export PATH=$PATH:/home/runner/bin
3653
./tests/tests.sh
54+
- name: Cleanup
55+
if: always()
56+
run: |
57+
rm -rf ~/.oci
58+
rm -f test.tfvars
59+
rm -rf ./.terraform
60+
rm -f terraform.tfstate*

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
![tests](https://github.com/oracle-quickstart/oke-flink/actions/workflows/tests.yaml/badge.svg)
2+
13
# oke-flink
24

35
Deploy a Kubernetes cluster on Oracle Cloud Infrastructure with multiple node pools and add-ons like Apache Flink.

tests/A1_full_1np.tfvars

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## Copyright © 2022-2023, Oracle and/or its affiliates.
2+
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
3+
14
region = "us-sanjose-1"
25
tenancy_ocid = "ocid1.tenancy.oc1.."
36

tests/A2_full_3np.tfvars

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## Copyright © 2022-2023, Oracle and/or its affiliates.
2+
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
3+
14
region = "us-sanjose-1"
25
tenancy_ocid = "ocid1.tenancy.oc1.."
36

tests/manifests/autoscaling.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## Copyright © 2022-2023, Oracle and/or its affiliates.
2+
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
3+
14
apiVersion: apps/v1
25
kind: Deployment
36
metadata:

tests/manifests/autoscaling_np2.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## Copyright © 2022-2023, Oracle and/or its affiliates.
2+
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
3+
14
apiVersion: apps/v1
25
kind: Deployment
36
metadata:

tests/test_autoscaler.sh

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## Copyright © 2022-2023, Oracle and/or its affiliates.
2+
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
3+
14
#!/bin/bash
25
set -e
36

@@ -50,21 +53,21 @@ log INFO "cluster-autoscaler leader is pod ${AUTOSCALER_LEADER}. Tailing the log
5053
# Tail the log until we find the scaling down mention (tail in subshell so the command exits when grep finds the line)
5154
log INFO "Waiting for the nodepool to scale down..."
5255
set +e
53-
(kubectl logs --since=5s ${AUTOSCALER_LEADER} -n kube-system &) | grep -p "Scale-down: removing empty node"
56+
(kubectl logs --since=5s ${AUTOSCALER_LEADER} -n kube-system &) | grep "Scale-down: removing empty node"
5457

5558
log INFO "Node is being removed..."
56-
(kubectl logs --since=5s ${AUTOSCALER_LEADER} -n kube-system &) | grep -p "Successfully added ignore-taint.cluster-autoscaler.kubernetes.io/oke-impending-node-termination"
59+
(kubectl logs --since=5s ${AUTOSCALER_LEADER} -n kube-system &) | grep "Successfully added ignore-taint.cluster-autoscaler.kubernetes.io/oke-impending-node-termination"
5760

58-
(kubectl logs --since=5s ${AUTOSCALER_LEADER} -n kube-system &) | grep -p "1 unregistered nodes present"
61+
(kubectl logs --since=5s ${AUTOSCALER_LEADER} -n kube-system &) | grep "1 unregistered nodes present"
5962
log INFO "Waiting for the node to be removed..."
6063
set -e
6164

6265
COUNTER=12
63-
NB_NODES=$(kubectl get nodes --no-headers | grep -p " Ready " | wc -l | tr -d " ")
66+
NB_NODES=$(kubectl get nodes --no-headers | grep " Ready " | wc -l | tr -d " ")
6467
while [[ $NB_NODES -gt $CURRENT_NB_NODES && $COUNTER -gt 0 ]]; do
6568
log INFO "Number of nodes is $NB_NODES, expecting $CURRENT_NB_NODES"
6669
sleep 20
67-
NB_NODES=$(kubectl get nodes --no-headers | grep -p " Ready " | wc -l | tr -d " ")
70+
NB_NODES=$(kubectl get nodes --no-headers | grep " Ready " | wc -l | tr -d " ")
6871
COUNTER=$(( $COUNTER - 1 ))
6972
done
7073

tests/test_flink.sh

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## Copyright © 2022-2023, Oracle and/or its affiliates.
2+
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
3+
14
#!/bin/bash
25
set -e
36
clean_up () {

tests/test_terraform_utils.sh

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1+
## Copyright © 2022-2023, Oracle and/or its affiliates.
2+
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
3+
14
#!/bin/bash
25

6+
DIRNAME=$(pwd)
7+
38
function render_tfvars {
4-
K8S_VERSION=${K8S_VERSION:-\"\"}
5-
cp $1 test.tfvars
6-
sed -i "" "s|ocid1\.tenancy\.oc1\.\.|${TENANCY_OCID}|g" test.tfvars
7-
sed -i "" "s|ocid1\.compartment\.oc1\.\.|${COMPARTMENT_OCID}|g" test.tfvars
8-
sed -i "" "s|kubernetes_version=null|kubernetes_version=\"${K8S_VERSION}\"|g" test.tfvars
9+
cp $1 ${DIRNAME}/test.tfvars
10+
sed "s|ocid1\.tenancy\.oc1\.\.|${TENANCY_OCID}|g" ${DIRNAME}/test.tfvars > ${DIRNAME}/test.tfvars.tmp && mv ${DIRNAME}/test.tfvars.tmp ${DIRNAME}/test.tfvars
11+
sed "s|ocid1\.compartment\.oc1\.\.|${COMPARTMENT_OCID}|g" ${DIRNAME}/test.tfvars > ${DIRNAME}/test.tfvars.tmp && mv ${DIRNAME}/test.tfvars.tmp ${DIRNAME}/test.tfvars
12+
sed "s|kubernetes_version=null|kubernetes_version=\"${K8S_VERSION}\"|g" ${DIRNAME}/test.tfvars > ${DIRNAME}/test.tfvars.tmp && mv ${DIRNAME}/test.tfvars.tmp ${DIRNAME}/test.tfvars
13+
cat ${DIRNAME}/test.tfvars
914
}
1015

1116
function deploy_stack {
1217
log INFO "Deploying stack..."
1318
terraform apply -var-file="test.tfvars" -auto-approve
1419
}
1520

21+
function init_stack {
22+
log INFO "Initializing Terraform..."
23+
terraform init
24+
}
25+
1626
function destroy_stack {
1727
log INFO "Destroying stack..."
18-
terraform destroy -auto-approve -refresh=false
28+
terraform destroy -auto-approve -refresh=false -var-file="test.tfvars"
1929
}
2030

2131
function get_cluster_access {

tests/test_utils.sh

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## Copyright © 2022-2023, Oracle and/or its affiliates.
2+
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
3+
14
#!/bin/bash
25

36
RED='\033[0;31m'

tests/tests.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## Copyright © 2022-2023, Oracle and/or its affiliates.
2+
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
3+
14
#!/bin/bash
25

36
set -e
@@ -17,8 +20,8 @@ source ./${BASE_DIR}/test_terraform_utils.sh
1720

1821
render_tfvars "${BASE_DIR}/A1_full_1np.tfvars"
1922

23+
init_stack || exit 1
2024
deploy_stack || exit 1
21-
2225
get_cluster_access || exit 1
2326

2427
# test autoscaler on first node pool (10 1GB mem pods)
@@ -29,12 +32,10 @@ set +e
2932
set -e
3033

3134
render_tfvars "${BASE_DIR}/A2_full_3np.tfvars"
32-
3335
deploy_stack || exit 1
3436

3537
# test autoscaler on second node pool (large 12G mem pod) to scale from 0 nodes to 1
3638
set +e
3739
( ./$BASE_DIR/test_autoscaler.sh "./${BASE_DIR}/manifests/autoscaling_np2.yaml" 1 ) || exit 1
3840
set -e
39-
4041
exit 0

0 commit comments

Comments
 (0)