Skip to content

Commit

Permalink
Merge pull request #5 from DelusionalOptimist/mvp
Browse files Browse the repository at this point in the history
initial meshery-smp-action
  • Loading branch information
leecalcote authored Jul 31, 2021
2 parents 033e2dc + 36efacc commit 57ba78c
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 0 deletions.
21 changes: 21 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "Service Mesh Performance Testing with Meshery"
description: "Validate SMP specification using Meshery"
author: "Layer5"

inputs:
provider_token:
description: "Provider token to use. NOTE: value of the 'token' key in auth.json"
platform:
description: "Platform to deploy meshery on. Possible values: docker, kubernetes"
default: docker
profile_filename:
description: "Name of the file containing SMP profile"
required: true

runs:
using: "node12"
main: "main.js"

branding:
icon: 'check-circle'
color: 'green'
5 changes: 5 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const spawnSync = require('child_process').spawnSync;
const path = require("path");

const proc = spawnSync('bash', [path.join(__dirname, 'main.sh')], {stdio: 'inherit'});
process.exit(proc.status)
44 changes: 44 additions & 0 deletions main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

SCRIPT_DIR=$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}" || realpath "${BASH_SOURCE[0]}")")

main() {
get_dependencies

setupArgs=()
if [[ -n "${INPUT_PROVIDER_TOKEN:-}" ]]; then
setupArgs+=(--provider-token ${INPUT_PROVIDER_TOKEN})
fi

if [[ -n "${INPUT_PLATFORM:-}" ]]; then
setupArgs+=(--platform ${INPUT_PLATFORM})
fi

#if [[ -n "${INPUT_SERVICE_MESH:-}" ]]; then
# setupArgs+=(--service-mesh ${INPUT_SERVICE_MESH})
#fi

"$SCRIPT_DIR/meshery.sh" "${setupArgs[@]}"

commandArgs=()
#if [[ -n "${INPUT_SERVICE_MESH:-}" ]]; then
# commandArgs+=(--service-mesh ${INPUT_SERVICE_MESH})
#fi

if [[ -n "${INPUT_PROFILE_FILENAME:-}" ]]; then
commandArgs+=(--profile-name ${INPUT_PROFILE_FILENAME})
fi

"$SCRIPT_DIR/mesheryctl.sh" "${commandArgs[@]}"
}

get_dependencies() {
sudo wget https://github.com/mikefarah/yq/releases/download/v4.10.0/yq_linux_amd64 -O /usr/bin/yq --quiet
sudo chmod +x /usr/bin/yq
}

main
98 changes: 98 additions & 0 deletions meshery.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env bash

SCRIPT_DIR=$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}" || realpath "${BASH_SOURCE[0]}")")

main() {

local provider_token=
local PLATFORM=docker

parse_command_line "$@"

echo "Checking if a k8s cluster exits..."
kubectl config current-context
if [[ $? -eq 0 ]]
then
echo "Cluster found"
else
printf "Cluster not found. \nCreating one...\n"
create_k8s_cluster
echo "Cluster created successfully!"
fi

if [[ -z $provider_token ]]
then
printf "Token not provided.\nUsing local provider...\n"
echo '{ "meshery-provider": "None", "token": null }' | jq -c '.token = ""'> ~/auth.json
else
echo '{ "meshery-provider": "Meshery", "token": null }' | jq -c '.token = "'$provider_token'"' > ~/auth.json
fi
cat ~/auth.json

kubectl config view --minify --flatten > ~/minified_config
mv ~/minified_config ~/.kube/config

curl -L https://git.io/meshery | PLATFORM=$PLATFORM bash -

sleep 60
}

create_k8s_cluster() {
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
sudo apt update -y
sudo apt install conntrack
minikube version
minikube start --driver=none --kubernetes-version=v1.20.7
sleep 40
}

meshery_config() {
mkdir ~/.meshery
config='{"contexts":{"local":{"endpoint":"http://localhost:9081","token":"Default","platform":"docker","adapters":[],"channel":"stable","version":"latest"}},"current-context":"local","tokens":[{"location":"auth.json","name":"Default"}]}'

echo $config | yq e '."contexts"."local"."adapters"[0]="'$1'"' -P - > ~/.meshery/config.yaml

cat ~/.meshery/config.yaml
}

parse_command_line() {
while :
do
case "${1:-}" in
-t|--provider-token)
if [[ -n "${2:-}" ]]; then
provider_token=$2
shift
else
echo "ERROR: '-t|--provider_token' cannot be empty." >&2
exit 1
fi
;;
-p|--platform)
if [[ -n "${2:-}" ]]; then
PLATFORM=$2
shift
else
echo "ERROR: '-p|--platform' cannot be empty." >&2
exit 1
fi
;;
#--service-mesh)
# if [[ -n "${2:-}" ]]; then
# meshery_config "meshery-$2"
# shift
# else
# echo "ERROR: '--service-mesh' cannot be empty." >&2
# exit 1
# fi
# ;;
*)
break
;;
esac
shift
done
}

main "$@"
65 changes: 65 additions & 0 deletions mesheryctl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

SCRIPT_DIR=$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}" || realpath "${BASH_SOURCE[0]}")")

declare -A adapters
adapters["istio"]=meshery-istio:10000
adapters["linkerd"]=meshery-linkerd:10001
adapters["consul"]=meshery-consul:10002
adapters["octarine"]=meshery-octarine:10003
adapters["nsm"]=meshery-nsm:10004
adapters["kuma"]=meshery-kuma:10007
adapters["cpx"]=meshery-cpx:10008
adapters["osm"]=meshery-osm:10009
adapters["traefik-mesh"]=meshery-traefik-mesh:10006

main() {
#local service_mesh_adapter=
#local service_mesh=
local perf_profile_name=

parse_command_line "$@"
#docker network connect bridge meshery_meshery_1
#docker network connect minikube meshery_meshery_1
#docker network connect minikube meshery_meshery-"$service_mesh"_1
#docker network connect bridge meshery_meshery-"$service_mesh"_1

mesheryctl system config minikube -t ~/auth.json
#echo $spec $service_mesh_adapter

mesheryctl perf apply --file $GITHUB_WORKSPACE/.github/$perf_profile_name -t ~/auth.json
}

parse_command_line() {
while :
do
case "${1:-}" in
#--service-mesh)
# if [[ -n "${2:-}" ]]; then
# # figure out assigning port numbers and adapter names
# service_mesh=$2
# service_mesh_adapter=${adapters["$2"]}
# shift
# else
# echo "ERROR: '--service-mesh' cannot be empty." >&2
# exit 1
# fi
# ;;
--profile-name)
if [[ -n "${2:-}" ]]; then
perf_profile_name=$2
shift
else
echo "ERROR: '--profile-name' cannot be empty." >&2
exit 1
fi
;;
*)
break
;;
esac
shift
done
}

main "$@"

0 comments on commit 57ba78c

Please sign in to comment.