Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration tests to gh actions kind infra #381

Merged
merged 1 commit into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions scripts/install-cert-manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,37 @@

set -Eo pipefail

SCRIPTS_DIR=$(cd "$(dirname "$0")" || exit 1; pwd)
DEFAULT_CERT_MANAGER_VERSION="v0.14.3"

source "$SCRIPTS_DIR/lib/k8s.sh"
source "$SCRIPTS_DIR/lib/common.sh"

check_is_installed kubectl "You can install kubectl with the helper scripts/install-kubectl.sh"

__cert_manager_version="$1"
if [ "z$__cert_manager_version" == "z" ]; then
__cert_manager_version=${CERT_MANAGER_VERSION:-$DEFAULT_CERT_MANAGER_VERSION}
fi

echo -n "installing cert-manager ... "
__cert_manager_url="https://github.com/jetstack/cert-manager/releases/download/${__cert_manager_version}/cert-manager.yaml"
echo -n "installing cert-manager from $__cert_manager_url ... "
kubectl apply --validate=false -f $__cert_manager_url
echo "ok."
install() {
echo -n "installing cert-manager ... "
__cert_manager_url="https://github.com/jetstack/cert-manager/releases/download/${__cert_manager_version}/cert-manager.yaml"
echo -n "installing cert-manager from $__cert_manager_url ... "
kubectl apply --validate=false -f $__cert_manager_url
echo "ok."
}

check() {
echo -n "checking cert-manager deployments have rolled out ... "
local __ns="cert-manager"
local __timeout="4m"
check_deployment_rollout cert-manager-webhook $__ns $__timeout
check_deployment_rollout cert-manager $__ns
check_deployment_rollout cert-manager-cainjector $__ns
echo "ok."
}


install
check
6 changes: 3 additions & 3 deletions scripts/lib/aws.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ ecr_login() {
local __err_msg="Failed ECR login. Please make sure you have IAM permissions to access ECR."
if [ $AWS_CLI_VERSION -gt 1 ]; then
( aws ecr get-login-password --region $__aws_region | \
docker login --username AWS --password-stdin $__ecr_url ) ||
( echo "\n$__err_msg" && exit 1 )
docker login --username AWS --password-stdin $__ecr_url ) ||
( echo "\n$__err_msg" && exit 1 )
else
$( aws ecr get-login --no-include-email ) || ( echo "\n$__err_msg" && exit 1 )
$( aws ecr get-login --no-include-email ) || ( echo "\n$__err_msg" && exit 1 )
fi
echo "ok."
}
4 changes: 2 additions & 2 deletions scripts/lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ is_installed() {
# vpc id is needed for setting up AWS CloudMap namespaces
vpc_id() {
local __md_url="http://169.254.169.254/latest/meta-data/network/interfaces"
local __macid=$( curl $__md_url/macs/ || exit 1 )
local __vpcid=$( curl $__md_url/macs/${macid}/vpc-id || exit 1 )
local __macid=$( curl ${__md_url}/macs/ || exit 1 )
local __vpcid=$( curl ${__md_url}/macs/${__macid}vpc-id || exit 1 )
echo "$__vpcid"

}
Expand Down
33 changes: 33 additions & 0 deletions scripts/lib/k8s.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
ROOT_DIR="$THIS_DIR/../.."
SCRIPTS_DIR="$ROOT_DIR/scripts"

# resource_exists returns 0 when the supplied resource can be found, 1
# otherwise. An optional second parameter overrides the Kubernetes namespace
# argument
k8s_resource_exists() {
local __res_name=${1:-}
local __namespace=${2:-}
local __args=""
if [ -n "$__namespace" ]; then
__args="$__args-n $__namespace"
fi
kubectl get $__args "$__res_name" >/dev/null 2>&1
}


# check_deployment_rollout watches the status of the latest rollout
# until it's done or until the timeout. Namespace and timeout are optional
# parameters
check_deployment_rollout() {
local __dep_name=${1:-}
local __namespace=${2:-}
local __timeout=${3:-"2m"}
local __args=""
if [ -n "$__namespace" ]; then
__args="$__args-n $__namespace"
fi
kubectl rollout status deployment/"$__dep_name" $__args --timeout=$__timeout
}
38 changes: 36 additions & 2 deletions scripts/test-with-kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ IMAGE=${ECR_URL}/${IMAGE_NAME}


CLUSTER_NAME_BASE="test"
CLUSTER_NAME=""
K8S_VERSION="1.17"
TMP_DIR=""

source "$SCRIPTS_DIR/lib/aws.sh"
source "$SCRIPTS_DIR/lib/common.sh"
source "$SCRIPTS_DIR/lib/k8s.sh"

check_is_installed curl
check_is_installed docker
Expand Down Expand Up @@ -56,8 +58,26 @@ function build_and_publish_controller {
echo "ok."
}

function run_integration_tests {
echo "Not implemented"
function install_controller {
echo -n "installing appmesh controller ... "
local __controller_name="appmesh-controller"
local __ns="appmesh-system"
AWS_ACCOUNT=$AWS_ACCOUNT_ID AWS_REGION=$AWS_REGION make deploy
check_deployment_rollout $__controller_name $__ns
echo -n "check the pods in appmesh-system namespace ... "
kubectl get pod -n $__ns
echo "ok."

}

function run_integration_test {
local __type=$1
local __vpc_id=$( vpc_id )
echo -n "running integration test type $__type ... "
ginkgo -v -r test/integration/$__type -- --cluster-kubeconfig=${KUBECONFIG} \
--cluster-name=${CLUSTER_NAME} --aws-region=${AWS_REGION} \
--aws-vpc-id=$__vpc_id
echo "ok."
}

function clean_up {
Expand Down Expand Up @@ -89,5 +109,19 @@ install_crds
# Install cert-manager
$SCRIPTS_DIR/install-cert-manager.sh

# Install the controller
install_controller

# Show the installed CRDs
kubectl get crds

#FIXME sometimes the test controller "deployment" is ready but internally process is not ready
# leading to tests failing. Added this hack to workaround. Will be replaced with a better
# check later
sleep 15

# Run integration tests
run_integration_test mesh
run_integration_test virtualservice
run_integration_test virtualrouter
run_integration_test gatewayroute
10 changes: 5 additions & 5 deletions test/framework/utils/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package utils
import "time"

const (
PollIntervalShort = 2 * time.Second
PollIntervalMedium = 10 * time.Second
PollRetries = 5
PollIntervalShort = 5 * time.Second
PollIntervalMedium = 15 * time.Second
PollRetries = 10

AWSPollIntervalShort = 1 * time.Second
AWSPollIntervalMedium = 5 * time.Second
AWSPollIntervalShort = 5 * time.Second
AWSPollIntervalMedium = 15 * time.Second
)