Skip to content

Commit

Permalink
test suite + action
Browse files Browse the repository at this point in the history
  • Loading branch information
streamnsight committed Apr 1, 2023
1 parent 49258b0 commit 16a556e
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 21 deletions.
38 changes: 31 additions & 7 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## Copyright © 2022-2023, Oracle and/or its affiliates.
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl

name: tests
on:
# workflow_dispatch
schedule:
- cron: '0 7 * * 1' # Mondays at 7AM
- cron: '0 15 * * 7' # Sundays at 8AM PST
jobs:
tests:
runs-on: ubuntu-latest
Expand All @@ -14,23 +18,43 @@ jobs:
COMPARTMENT_OCID: ${{ secrets.COMPARTMENT_OCID }}
steps:
- uses: actions/checkout@v3
- name: Run tests
- name: Install OCI CLI
run: |
# Install OCI CLI
wget https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh
chmod +x ./install.sh
bash -c "./install.sh --accept-all-defaults"
./install.sh --accept-all-defaults
mkdir -p ~/.oci
echo "$OCI_KEY" > ~/.oci/oci_ci_user.pem
echo "$OCI_CONFIG" > ~/.oci/config
# install terraform and kubectl
echo "~/bin" >> $GITHUB_PATH
export PATH=$PATH:/home/runner/bin
oci setup repair-file-permissions --file /home/runner/.oci/config
oci setup repair-file-permissions --file /home/runner/.oci/oci_ci_user.pem
- name: Check Deps
run: |
# sudo apt list -a kubectl
# curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
# sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update
sudo apt-get install -y terraform=1.2.9 kubectl=1.24.12
# sudo apt-get update && sudo apt-get install -y gnupg software-properties-common
# wget -O- https://apt.releases.hashicorp.com/gpg | \
# gpg --dearmor | \
# sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
# sudo apt-get install -y terraform=1.2.9 kubectl=1.24.12
# install terraform and kubectl
# sudo apt-get update
kubectl version --client=true
terraform version
- name: Run tests
run: |
pwd
export PATH=$PATH:/home/runner/bin
./tests/tests.sh
- name: Cleanup
if: always()
run: |
rm -rf ~/.oci
rm -f test.tfvars
rm -rf ./.terraform
rm -f terraform.tfstate*
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![tests](https://github.com/oracle-quickstart/oke-flink/actions/workflows/tests.yaml/badge.svg)

# oke-flink

Deploy a Kubernetes cluster on Oracle Cloud Infrastructure with multiple node pools and add-ons like Apache Flink.
Expand Down
3 changes: 3 additions & 0 deletions tests/A1_full_1np.tfvars
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Copyright © 2022-2023, Oracle and/or its affiliates.
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl

region = "us-sanjose-1"
tenancy_ocid = "ocid1.tenancy.oc1.."

Expand Down
3 changes: 3 additions & 0 deletions tests/A2_full_3np.tfvars
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Copyright © 2022-2023, Oracle and/or its affiliates.
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl

region = "us-sanjose-1"
tenancy_ocid = "ocid1.tenancy.oc1.."

Expand Down
3 changes: 3 additions & 0 deletions tests/manifests/autoscaling.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Copyright © 2022-2023, Oracle and/or its affiliates.
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl

apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down
3 changes: 3 additions & 0 deletions tests/manifests/autoscaling_np2.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Copyright © 2022-2023, Oracle and/or its affiliates.
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl

apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down
13 changes: 8 additions & 5 deletions tests/test_autoscaler.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Copyright © 2022-2023, Oracle and/or its affiliates.
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl

#!/bin/bash
set -e

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

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

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

COUNTER=12
NB_NODES=$(kubectl get nodes --no-headers | grep -p " Ready " | wc -l | tr -d " ")
NB_NODES=$(kubectl get nodes --no-headers | grep " Ready " | wc -l | tr -d " ")
while [[ $NB_NODES -gt $CURRENT_NB_NODES && $COUNTER -gt 0 ]]; do
log INFO "Number of nodes is $NB_NODES, expecting $CURRENT_NB_NODES"
sleep 20
NB_NODES=$(kubectl get nodes --no-headers | grep -p " Ready " | wc -l | tr -d " ")
NB_NODES=$(kubectl get nodes --no-headers | grep " Ready " | wc -l | tr -d " ")
COUNTER=$(( $COUNTER - 1 ))
done

Expand Down
3 changes: 3 additions & 0 deletions tests/test_flink.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Copyright © 2022-2023, Oracle and/or its affiliates.
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl

#!/bin/bash
set -e
clean_up () {
Expand Down
22 changes: 16 additions & 6 deletions tests/test_terraform_utils.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
## Copyright © 2022-2023, Oracle and/or its affiliates.
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl

#!/bin/bash

DIRNAME=$(pwd)

function render_tfvars {
K8S_VERSION=${K8S_VERSION:-\"\"}
cp $1 test.tfvars
sed -i "" "s|ocid1\.tenancy\.oc1\.\.|${TENANCY_OCID}|g" test.tfvars
sed -i "" "s|ocid1\.compartment\.oc1\.\.|${COMPARTMENT_OCID}|g" test.tfvars
sed -i "" "s|kubernetes_version=null|kubernetes_version=\"${K8S_VERSION}\"|g" test.tfvars
cp $1 ${DIRNAME}/test.tfvars
sed "s|ocid1\.tenancy\.oc1\.\.|${TENANCY_OCID}|g" ${DIRNAME}/test.tfvars > ${DIRNAME}/test.tfvars.tmp && mv ${DIRNAME}/test.tfvars.tmp ${DIRNAME}/test.tfvars
sed "s|ocid1\.compartment\.oc1\.\.|${COMPARTMENT_OCID}|g" ${DIRNAME}/test.tfvars > ${DIRNAME}/test.tfvars.tmp && mv ${DIRNAME}/test.tfvars.tmp ${DIRNAME}/test.tfvars
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
cat ${DIRNAME}/test.tfvars
}

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

function init_stack {
log INFO "Initializing Terraform..."
terraform init
}

function destroy_stack {
log INFO "Destroying stack..."
terraform destroy -auto-approve -refresh=false
terraform destroy -auto-approve -refresh=false -var-file="test.tfvars"
}

function get_cluster_access {
Expand Down
3 changes: 3 additions & 0 deletions tests/test_utils.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Copyright © 2022-2023, Oracle and/or its affiliates.
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl

#!/bin/bash

RED='\033[0;31m'
Expand Down
7 changes: 4 additions & 3 deletions tests/tests.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Copyright © 2022-2023, Oracle and/or its affiliates.
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl

#!/bin/bash

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

render_tfvars "${BASE_DIR}/A1_full_1np.tfvars"

init_stack || exit 1
deploy_stack || exit 1

get_cluster_access || exit 1

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

render_tfvars "${BASE_DIR}/A2_full_3np.tfvars"

deploy_stack || exit 1

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

exit 0

0 comments on commit 16a556e

Please sign in to comment.