-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: do profile-based yaml generation
The purpose of profiles is to provide reasonable defaults for yaml templates for each of the major use cases: * develop: used by developers to run mayastor * release: used for stable releases of mayastor * test: used by mayastor e2e tests In addition to that I have: * increased debug level of moac when running in develop env * fixed wrong usage of -l parameter (indexing starts at 0) * introduced rule of thumb for cpu count and hugepage mem (1:1) Resolves: CAS-699
- Loading branch information
Jan Kryl
committed
Feb 22, 2021
1 parent
043b39d
commit 386e39a
Showing
8 changed files
with
162 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
mayastorImagesTag: develop | ||
mayastorImagesTag: latest | ||
mayastorImagePullPolicy: Always | ||
mayastorCpuCount: "2" | ||
mayastorCpuCount: "1" | ||
mayastorHugePagesGiB: "1" | ||
mayastorImagesRepo: "" | ||
mayastorImagesRegistry: "" | ||
mayastorPools: | ||
- node: "NODE_NAME" | ||
device: "DEVICE" | ||
device: "DEVICE" | ||
# This option is intended for development yamls and motivated by the problem of | ||
# moac that does not update status of msp resource in some cases. Feel free to | ||
# remove when no longer needed. | ||
moacDebug: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,158 @@ | ||
#! /bin/sh | ||
#!/bin/sh | ||
|
||
# This is a wrapper script for helm to generate yaml files for deploying | ||
# mayastor. It provides reasonable defaults for helm values based on | ||
# selected profile. Easy to use and minimizing risk of error. | ||
# Keep the script as simple as possible - ad-hoc use cases can be addressed | ||
# by running helm directly. | ||
|
||
set -e | ||
|
||
if [ "x$1" = x ]; then | ||
cat <<EOF | ||
USAGE: $0 [-t <target_dir>] <mayastor_docker_images_tag> [<mayastor_images_repo>] | ||
SCRIPTDIR="$(realpath "$(dirname "$0")")" | ||
|
||
# Internal variables tunable by options | ||
cores= | ||
moac_debug=false | ||
output_dir="$SCRIPTDIR/../deploy" | ||
pools= | ||
profile= | ||
pull_policy= | ||
registry= | ||
tag= | ||
|
||
help() { | ||
cat <<EOF | ||
Generate (some) deployment YAMLs from the helm chart and store them to deploy/ | ||
in the repo. If -t is specified do not put them to deploy/ but rather to the | ||
directory given. | ||
Usage: $0 [OPTIONS] <PROFILE> | ||
Common options: | ||
-c <cores> # of cpu cores for mayastor overriding the profile's default. | ||
-h/--help Display help message and exit. | ||
-o <output_dir> Directory to store the generated yaml files (default $output_dir) | ||
-p <node,device> Node name and associated pool device (the option may repeat). | ||
-r <registry> Docker image registry of mayastor images (default none). | ||
-t <tag> Tag of mayastor images overriding the profile's default. | ||
Profiles: | ||
develop: Used by developers of mayastor. | ||
release: Recommended for stable releases deployed by users. | ||
test: Used by mayastor e2e tests. | ||
EOF | ||
exit 1 | ||
fi | ||
} | ||
|
||
SCRIPTDIR="$(realpath "$(dirname "$0")")" | ||
# Parse common options | ||
while [ "$#" -gt 0 ]; do | ||
case "$1" in | ||
-c) | ||
shift | ||
cores=$1 | ||
;; | ||
-h|--help) | ||
help | ||
exit 0 | ||
;; | ||
-o) | ||
shift | ||
output_dir=$1 | ||
;; | ||
-p) | ||
shift | ||
pools="$pools $1" | ||
;; | ||
-r) | ||
shift | ||
registry=$1 | ||
;; | ||
-t) | ||
shift | ||
tag=$1 | ||
;; | ||
-*) | ||
echo "Unknown option: $1" | ||
help | ||
exit 1 | ||
;; | ||
*) | ||
profile=$1 | ||
shift | ||
break | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
if [ "$1" = "-t" ]; then | ||
TARGET_DIR="$2" | ||
shift 2 | ||
else | ||
TARGET_DIR="$SCRIPTDIR/../deploy" | ||
fi | ||
if [ ! -d "$TARGET_DIR" ]; then | ||
mkdir -p "$TARGET_DIR" | ||
# The space after profile name is reserved for profile specific options which | ||
# we don't have yet. | ||
if [ "$#" -gt 0 ]; then | ||
help | ||
exit 1 | ||
fi | ||
|
||
if [ "x$2" = x ]; then | ||
mayastor_images_repo="NONE" | ||
# In most of the cases the tag will be a specific version that does not change | ||
# so save dockerhub bandwidth and don't always pull the image. | ||
if [ -n "$tag" ]; then | ||
pull_policy=IfNotPresent | ||
else | ||
mayastor_images_repo="$2" | ||
pull_policy=Always | ||
fi | ||
|
||
# Set profile defaults | ||
case "$profile" in | ||
"develop") | ||
[ -z "$cores" ] && cores=1 | ||
[ -z "$tag" ] && tag=develop | ||
moac_debug=true | ||
;; | ||
"release") | ||
[ -z "$cores" ] && cores=1 | ||
[ -z "$tag" ] && tag=latest | ||
;; | ||
"test") | ||
[ -z "$cores" ] && cores=2 | ||
[ -z "$tag" ] && tag=ci | ||
moac_debug=true | ||
;; | ||
*) | ||
echo "Missing or invalid profile name. Type \"$0 --help\"" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
set -u | ||
|
||
if ! which helm > /dev/null 2>&1; then | ||
echo "Install helm to path >v3.4.1" | ||
echo "https://github.com/helm/helm/releases/tag/v3.4.1" | ||
exit 1 | ||
if ! which helm >/dev/null 2>&1; then | ||
echo "Install helm (>v3.4.1) to PATH" | ||
exit 1 | ||
fi | ||
|
||
tmpd=$(mktemp -d /tmp/generate-deploy.sh.XXXXXXXX) | ||
if [ ! -d "$output_dir" ]; then | ||
mkdir -p "$output_dir" | ||
fi | ||
|
||
tmpd=$(mktemp -d /tmp/generate-deploy-yamls.sh.XXXXXXXX) | ||
# shellcheck disable=SC2064 | ||
trap "rm -fr '$tmpd'" HUP QUIT EXIT TERM INT | ||
|
||
template_params="mayastorImagesTag=$1" | ||
if [ "$mayastor_images_repo" != "NONE" ]; then | ||
template_params="$template_params,mayastorImagesRepo=$mayastor_images_repo" | ||
# A rule of thumb: # of cpu cores equals to Gigs of hugepage memory | ||
template_params="mayastorImagesTag=$tag" | ||
template_params="$template_params,mayastorImagePullPolicy=$pull_policy" | ||
template_params="$template_params,mayastorCpuCount=$cores" | ||
template_params="$template_params,mayastorHugePagesGiB=$cores" | ||
template_params="$template_params,moacDebug=$moac_debug" | ||
if [ -n "$registry" ]; then | ||
template_params="$template_params,mayastorImagesRegistry=$registry" | ||
fi | ||
if [ -n "$pools" ]; then | ||
i=0 | ||
for pool in $pools; do | ||
node=$(echo "$pool" | sed 's/,.*//') | ||
device=$(echo "$pool" | sed 's/.*,//') | ||
template_params="$template_params,mayastorPools[$i].node=$node" | ||
template_params="$template_params,mayastorPools[$i].device=$device" | ||
i=$((i + 1)) | ||
done | ||
fi | ||
|
||
helm template --set "$template_params" mayastor "$SCRIPTDIR/../chart" --output-dir="$tmpd" --namespace mayastor | ||
|
||
mv "$tmpd"/mayastor/templates/*.yaml "$TARGET_DIR" | ||
mv "$tmpd"/mayastor/templates/*.yaml "$output_dir/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters