diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 924957c4..2ee8c38d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -35,3 +35,16 @@ $ADMIRAL_HOME/install/scripts/cluster-secret.sh ${KUBECFG_FILE} diff --git a/install/scripts/install_admiral.sh b/install/scripts/install_admiral.sh new file mode 100755 index 00000000..6be08e26 --- /dev/null +++ b/install/scripts/install_admiral.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +[ $# -eq 0 ] && { echo "Usage: $0 " ; exit 1; } + +install_dir=$1 + +#verify KUBECONFIG is set +if [ -z "$KUBECONFIG" ] +then + echo "\$KUBECONFIG is not set" + exit 1; +fi + +#Install admiral + +kubectl apply -f $install_dir/yaml/remotecluster.yaml +kubectl apply -f $install_dir/yaml/demosinglecluster.yaml + +#Verify admiral is running +kubectl rollout status deployment admiral -n admiral \ No newline at end of file diff --git a/install/scripts/install_sample_services.sh b/install/scripts/install_sample_services.sh new file mode 100755 index 00000000..eb5c7227 --- /dev/null +++ b/install/scripts/install_sample_services.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +[ $# -eq 0 ] && { echo "Usage: $0 " ; exit 1; } + +install_dir=$1 + +#verify KUBECONFIG is set +if [ -z "$KUBECONFIG" ] +then + echo "\$KUBECONFIG is not set" + exit 1; +fi + +#Install test services + +kubectl apply -f $install_dir/yaml/sample.yaml + +#Install the dependency CR + +kubectl apply -f $install_dir/yaml/sample_dep.yaml + +#wait for the deployments to come up +kubectl rollout status deployment greeting -n sample +kubectl rollout status deployment webapp -n sample + +#Wait for admiral's magic +sleep 5 + +#Verify that admiral created service names for 'greeting' service +num_ses=$(kubectl get serviceentry -n admiral-sync | grep "global-se" -c) + +if [ -z "$num_ses" ] || [ $num_ses -lt 1 ] +then + echo "No service entries created" + exit 1; +else + echo "Admiral did it's magic!" + exit 0 +fi \ No newline at end of file diff --git a/install/scripts/redirect-dns.sh b/install/scripts/redirect-dns.sh index 4a3c9f19..36f6ad38 100755 --- a/install/scripts/redirect-dns.sh +++ b/install/scripts/redirect-dns.sh @@ -1,27 +1,51 @@ #!/usr/bin/env bash +function ver { printf "%03d%03d%03d%03d" $(echo "$1" | tr '.' ' '); } +target_coredns_version=1.6.7 +target_coredns_image="docker.io/coredns/coredns:$target_coredns_version" +coredns_upgrade_skip_msg="Skipping coredns upgrade and redirection for admiral as this needs coredns version > 1.5.0" CORE_DNS_IP=$(kubectl get svc istiocoredns -n istio-system -o jsonpath='{.spec.clusterIP}') +coredns_image=$(kubectl get deployment coredns -n kube-system -o=jsonpath='{$.spec.template.spec.containers[:1].image}') +coredns_ver=$(echo $coredns_image | awk -F: '{print $2}') +#if coredns version < 1.5.0, then upgrade to 1.6.7 +if [ $(ver $coredns_ver) -lt $(ver 1.5.0) ] +then + printf "Current codedns version: %s\n" "$coredns_ver" + printf "Coredns will be upgraded to $target_coredns_image.\nDo you wish to proceed?\n" + options="Please enter yes/Y/y or no/N/n" + echo $options + read -p "" yn + case $yn in + [Yy]* ) kubectl set image deployment/coredns -n kube-system coredns=$target_coredns_image; kubectl rollout status deployment/coredns -n kube-system;; + * ) echo $coredns_upgrade_skip_msg; exit ;; + esac +else + echo "Running compatible coredns version: $coredns_ver" +fi + echo "Istio coredns is hosted at: $CORE_DNS_IP" export WORK_DIR=$(pwd) export CORE_DNS_CM=/tmp/coredns-cm.yaml cat < ${CORE_DNS_CM} -apiVersion: v1 data: Corefile: | .:53 { errors - health + health { + lameduck 5s + } + ready kubernetes cluster.local in-addr.arpa ip6.arpa { pods insecure - upstream fallthrough in-addr.arpa ip6.arpa + ttl 30 } prometheus :9153 - proxy . /etc/resolv.conf + forward . /etc/resolv.conf cache 30 loop reload @@ -32,13 +56,9 @@ data: cache 30 forward . ${CORE_DNS_IP} } -kind: ConfigMap -metadata: - name: coredns - namespace: kube-system EOF -kubectl apply -f $CORE_DNS_CM +kubectl patch configmap/coredns -n kube-system --patch "$(cat $CORE_DNS_CM)" rm -rf $CORE_DNS_CM diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 00000000..36275ed3 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,9 @@ +# Integration tests + +Note that these scripts do not including the kubectl version compatibility with k8s server version. +You have to install the appropriate kubectl version before running these tests. + +## Run +```bash +./run.sh "1.14.2" "1.4.3" "../out" +``` \ No newline at end of file diff --git a/tests/cleanup.sh b/tests/cleanup.sh new file mode 100755 index 00000000..4313acf0 --- /dev/null +++ b/tests/cleanup.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +[ $# -lt 1 ] && { echo "Usage: $0 " ; exit 1; } + +rm -rf "istio-$istio_version"* +minikube delete \ No newline at end of file diff --git a/tests/create_cluster.sh b/tests/create_cluster.sh new file mode 100755 index 00000000..f35c3330 --- /dev/null +++ b/tests/create_cluster.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +[ $# -lt 2 ] && { echo "Usage: $0 " ; exit 1; } + +k8s_version=$1 +vm_driver=$2 + +minikube start --memory=8192 --cpus=4 --kubernetes-version=$k8s_version --vm-driver $vm_driver \ No newline at end of file diff --git a/tests/dns_setup.sh b/tests/dns_setup.sh new file mode 100755 index 00000000..2019f6dc --- /dev/null +++ b/tests/dns_setup.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +[ $# -lt 1 ] && { echo "Usage: $0 " ; exit 1; } + +install_dir=$1 + +#verify KUBECONFIG is set +if [ -z "$KUBECONFIG" ] +then + echo "\$KUBECONFIG is not set" + exit 1; +fi + +#Point hosts ending in global to be resolved by istio coredns +$install_dir/scripts/redirect-dns.sh \ No newline at end of file diff --git a/tests/install_istio.sh b/tests/install_istio.sh new file mode 100755 index 00000000..b8e97f6d --- /dev/null +++ b/tests/install_istio.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +function ver { printf "%03d%03d%03d%03d" $(echo "$1" | tr '.' ' '); } + +[ $# -lt 2 ] && { echo "Usage: $0 [osx|linux]" ; exit 1; } + +istio_version=$1 +os=$2 + +#Download & extract Istio + +#Downloading istiofunction ver { printf "%03d%03d%03d%03d" $(echo "$1" | tr '.' ' '); } + +wget "https://github.com/istio/istio/releases/download/$istio_version/istio-$istio_version-$os.tar.gz" + +#Extracting istio +tar -xf "istio-$istio_version-$os.tar.gz" + +#Create istio-system namespace + +kubectl create ns istio-system + +#Create k8s secret to be used by Citadel for mTLS cert generation +kubectl create secret generic cacerts -n istio-system --from-file="istio-$istio_version/samples/certs/ca-cert.pem" --from-file="istio-$istio_version/samples/certs/ca-key.pem" --from-file="istio-$istio_version/samples/certs/root-cert.pem" --from-file="istio-$istio_version/samples/certs/cert-chain.pem" + +#Generate, install and verify Istio CRDs + +if [ $(ver $istio_version) -lt $(ver 1.5.0) ] +then + helm template "istio-$istio_version/install/kubernetes/helm/istio-init" --name istio-init --namespace istio-system | kubectl apply -f - + #Make sure Istio crds are installed + crds_count=0 + while [ $crds_count -lt 1 ] + do + crds_count=$(kubectl get crds | grep 'istio.io' | wc -l) + done + + helm template "istio-$istio_version/install/kubernetes/helm/istio" --name istio --namespace istio-system -f "istio-$istio_version/install/kubernetes/helm/istio/example-values/values-istio-multicluster-gateways.yaml" | kubectl apply -f - + + #Verify that pilot is up and running + kubectl rollout status deployment istio-pilot -n istio-system + + #Verify that sidecar injector is running + kubectl rollout status deployment istio-sidecar-injector -n istio-system + +else + "./istio-$istio_version/bin/istioctl" manifest apply -f "istio-$istio_version/install/kubernetes/operator/examples/multicluster/values-istio-multicluster-gateways.yaml" + #Verify that istiod is up and running + kubectl rollout status deployment istiod -n istio-system +fi + +# Delete envoy filter for translating `global` to `svc.cluster.local` +kubectl delete envoyfilter istio-multicluster-ingressgateway -n istio-system + diff --git a/tests/master_run.sh b/tests/master_run.sh new file mode 100755 index 00000000..1b413ce6 --- /dev/null +++ b/tests/master_run.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +(cd ../; make gen-yaml) + +k8s_versions=( +# "1.18.0" + "1.16.8" +# "1.14.2" +) +istio_versions=( +# "1.4.6" + "1.5.1" +) + + +for k8s_version in "${k8s_versions[@]}" +do + for istio_version in "${istio_versions[@]}" + do + echo "Testing with k8s verision: $k8s_version and istio version: $istio_version" + ./run.sh $k8s_version $istio_version "../out" +# pass=$(./run.sh $k8s_version $istio_version "../out" | grep -c "PASS") +# if [ $pass -lt 1 ] +# then +# echo "FAIL: k8s verision: $k8s_version and istio version: $istio_version" +# else +# echo "PASS: k8s verision: $k8s_version and istio version: $istio_version" +# fi + done +done diff --git a/tests/run.sh b/tests/run.sh new file mode 100755 index 00000000..1debbcdb --- /dev/null +++ b/tests/run.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +[ $# -lt 3 ] && { echo "Usage: $0 " ; exit 1; } + +k8s_version=$1 +istio_version=$2 +install_dir=$3 + +source ./create_cluster.sh $k8s_version "virtualbox" +./install_istio.sh $istio_version "osx" +./dns_setup.sh $install_dir +$install_dir/scripts/install_admiral.sh $install_dir +$install_dir/scripts/cluster-secret.sh $KUBECONFIG $KUBECONFIG admiral +$install_dir/scripts/install_sample_services.sh $install_dir + +#allow for stabilization of DNS and Istio SEs before running tests +sleep 10 +./test1.sh "webapp" "sample" "greeting" + +./cleanup.sh $istio_version diff --git a/tests/test1.sh b/tests/test1.sh new file mode 100755 index 00000000..10a38c67 --- /dev/null +++ b/tests/test1.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +[ $# -lt 3 ] && { echo "Usage: $0 " ; exit 1; } + +source=$1 +source_ns=$2 +dest=$3 + +#Test +output=$(kubectl exec --namespace=sample -it $(kubectl get pod -l "app=$source" --namespace=$source_ns -o jsonpath='{.items[0].metadata.name}') -c $source -- curl -v "http://default.$dest.global" && echo "") + +if [[ "$output" == *"Admiral"* ]]; then + echo "PASS" + exit 0 +else + echo "FAIL" . $output + exit 1 +fi