-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
129 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env bash | ||
function pull_chart_from_release() { | ||
local msg="usage: helm release pull <RELEASE NAME>" | ||
if [[ $# < 1 ]]; then exit_with_help "$msg"; fi | ||
|
||
RELEASE=$1 | ||
NAMESPACE=$HELM_NAMESPACE | ||
|
||
RELEASE_STATUS=$(helm -n $NAMESPACE status $RELEASE -o json) | ||
if [ $? -eq 0 ]; then | ||
echo $RELEASE_STATUS | jq > $(dirname -- "$0")/data/release-$RELEASE-status.json; | ||
VERSION=$(cat $(dirname -- "$0")/data/release-$RELEASE-status.json | jq -r .version) | ||
|
||
RELEASE_CONTENT=$(kubectl \ | ||
get secrets sh.helm.release.v1.$RELEASE.v$VERSION \ | ||
-n $NAMESPACE \ | ||
-o jsonpath='{.data.release}' \ | ||
| base64 -d | base64 -d | gzip -d | jq | tee $(dirname -- "$0")/data/release-$RELEASE-content.json) | ||
|
||
CHART_NAME=$(cat $(dirname -- "$0")/data/release-$RELEASE-content.json | jq -r .chart.metadata.name) | ||
CHART_VERSION=$(cat $(dirname -- "$0")/data/release-$RELEASE-content.json | jq -r .chart.metadata.version) | ||
CHART_DIR=$CHART_NAME-$CHART_VERSION | ||
|
||
mkdir -p $CHART_DIR | ||
|
||
# sudo wget https://github.com/mikefarah/yq/releases/download/v4.25.3/yq_linux_amd64 -O /usr/bin/yq | ||
echo $RELEASE_CONTENT | jq -r '.chart.metadata' | yq e -P - > $CHART_DIR/Chart.yaml | ||
echo $RELEASE_CONTENT | jq -r '.chart.values' | yq e -P - > $CHART_DIR/values.yaml | ||
|
||
# Create Chart Templates | ||
for row in $(echo $RELEASE_CONTENT | jq -r '.chart.templates[] | @base64'); do | ||
#echo $row | ||
_jq() { | ||
echo ${row} | base64 --decode | jq -r ${1} | ||
} | ||
filename=$(echo $(_jq '.name')) | ||
data=$(echo $(_jq '.data') ) | ||
mkdir -p $(dirname $CHART_DIR/$filename) | ||
echo $data | base64 -d > $CHART_DIR/$filename | ||
done | ||
# Create Chart files | ||
for row in $(echo $RELEASE_CONTENT | jq -r '.chart.files[] | @base64'); do | ||
#echo $row | ||
_jq() { | ||
echo ${row} | base64 --decode | jq -r ${1} | ||
} | ||
filename=$(echo $(_jq '.name')) | ||
data=$(echo $(_jq '.data') ) | ||
mkdir -p $(dirname $CHART_DIR/$filename) | ||
echo $data | base64 -d > $CHART_DIR/$filename | ||
done | ||
fi | ||
rm_dir './data' | ||
return 0; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Error Handling | ||
function on_error() { echo "error: [ ${BASH_SOURCE[1]} at line ${BASH_LINENO[0]} ]"; } | ||
set -o errtrace | ||
trap on_error ERR | ||
|
||
# Alias Expansion | ||
shopt -s expand_aliases | ||
alias kwargs='(( $# )) && local' | ||
|
||
# Kill Script Function | ||
trap exit TERM | ||
alias exit_script='kill -s TERM $$' | ||
|
||
# Set Script Globals | ||
_ROOT="$( cd "$(dirname "$0")" ; pwd -P )" |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env bash | ||
source $(dirname -- "$0")/lib/config.sh | ||
source $(dirname -- "$0")/lib/utility.sh | ||
source $(dirname -- "$0")/lib/api/helm-ops.sh | ||
|
||
|
||
function main() { | ||
|
||
init_dir './data' | ||
|
||
declare -A -x command_table=( | ||
['pull']="pull_chart_from_release" | ||
) | ||
|
||
local commands="${!command_table[@]}" | ||
local msg="usage: ./release.sh [ $commands ]" | ||
if [[ $# < 1 ]]; then exit_with_help "$msg"; fi | ||
|
||
local command=${1}; shift | ||
local fn_name=${command_table[$command]} | ||
|
||
if [[ $fn_name == '' ]]; then exit_with_help "$msg"; fi | ||
if $fn_name $@; then | ||
rm -Rf $(dirname -- "$0")/data; | ||
return 0; | ||
else | ||
return 1; | ||
fi | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
|
||
function exit_with_help() { echo $1 && exit_script; } | ||
|
||
function get_timestamp() { printf $(date '+%Y-%m-%d_%H%M%S'); } | ||
|
||
function init_dir() { [[ -d $_ROOT'/'$1 ]] || mkdir $_ROOT'/'$1; } | ||
|
||
function rm_dir() { [[ -d $_ROOT'/'$1 ]] || rm -rf $_ROOT'/'$1; } | ||
|
||
function str_split() { | ||
|
||
declare -a -x -g str_split_result=() | ||
IFS="$2"; read -ra str_split_result <<< $1; IFS=' ' | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Name: "release" | ||
version: "0.1.0" | ||
usage: "pull or update Helm Releases" | ||
description: |- | ||
Update values of a releases, pull charts from releases | ||
command: "$HELM_PLUGIN_DIR/release.sh" |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
# import library code | ||
source $(dirname -- "$0")/lib/main.sh | ||
|
||
# pass args to main() | ||
main $@ |