|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +### Globals |
| 4 | +## CLOPS infos |
| 5 | +CLOPS_NAME="clops-helm" |
| 6 | +CLOPS_REPO="https://chartmuseum.cloudical.net/clops" |
| 7 | +VERSION_FILE="/tmp/versions" |
| 8 | +CLOPS_FILE="/tmp/clops_chart" |
| 9 | +CLOPS_TMP_FILE="/tmp/clops_chart_tmp" |
| 10 | +CLOPS_VALUES_FILE="/tmp/clops_values" |
| 11 | +SELECTED_NEW_VALUES="/tmp/GEN_CHART" |
| 12 | +SELECTED_OLD_VALUES="/tmp/GEN_CHART_OLD" |
| 13 | + |
| 14 | +### function definitions |
| 15 | +## add chart function |
| 16 | +function helm_repo_add () { |
| 17 | + helm repo add $1 $2 2>&1 > /dev/null |
| 18 | + helm repo update 2>&1 > /dev/null |
| 19 | +} |
| 20 | + |
| 21 | +## Add CLOPS Helm repository |
| 22 | +helm_repo_add "$CLOPS_NAME" "$CLOPS_REPO" |
| 23 | + |
| 24 | +read_input() { |
| 25 | + read RESULT |
| 26 | + printf "$RESULT" |
| 27 | +} |
| 28 | + |
| 29 | +print_divider () { |
| 30 | + printf "%-*s\n" "60" "" | tr ' ' '-' |
| 31 | +} |
| 32 | + |
| 33 | +get_chart_in_version() { |
| 34 | + print_divider |
| 35 | + printf "\tEnter the %s version you want \n\tin Format 'X.Y.Z', 'X.Y.*' or 'X.Y'\n\tChoice > " "$1" |
| 36 | + V=`read_input` |
| 37 | + printf "\n\tRequesting Chart %s in Version %s\n" "$1" "$V" |
| 38 | + FETCH_V=`helm show chart "$1/$1" --version "$V" 2>/dev/null | yq '.version'` |
| 39 | + helm show values "$1/$1" --version "$V" > "$SELECTED_NEW_VALUES" \ |
| 40 | + && printf "\tFound Version %s\n" "$FETCH_V" \ |
| 41 | + || get_chart_in_version $1 |
| 42 | +} |
| 43 | + |
| 44 | +print_dependencies() { |
| 45 | + LIST_LENGTH=`cat "$CLOPS_FILE" | yq '. | length'` |
| 46 | + print_divider |
| 47 | + printf "\tSelect the chart you want to compare\n" |
| 48 | + print_divider |
| 49 | + for i in $(seq 0 `echo $(($LIST_LENGTH - 1))`) |
| 50 | + do |
| 51 | + printf "\t%s. Chart: %s \n" "$i" `cat "$CLOPS_FILE" | yq e ".[$i].name"` |
| 52 | + done |
| 53 | + print_divider |
| 54 | +} |
| 55 | + |
| 56 | +## Print clops infos to files |
| 57 | +helm show chart "$CLOPS_NAME/$CLOPS_NAME" | yq '.dependencies' > "$CLOPS_FILE" |
| 58 | +helm show values "$CLOPS_NAME/$CLOPS_NAME" > "$CLOPS_VALUES_FILE" |
| 59 | + |
| 60 | +print_dependencies |
| 61 | + |
| 62 | +printf "\tChoice > " |
| 63 | +C=`read_input` |
| 64 | +while [[ $C -gt $LIST_LENGTH || $C -lt 0 ]]; do |
| 65 | + printf "\tSelection must be between 0 and %d \n" "$C" |
| 66 | + printf "\tChoice > " |
| 67 | + C=`read_input` |
| 68 | +done |
| 69 | + |
| 70 | +SELECTION_NAME=`cat "$CLOPS_FILE" | yq e ".[$C].name"` |
| 71 | +SELECTION_REPO=`cat "$CLOPS_FILE" | yq e ".[$C].repository"` |
| 72 | +SELECTION_VERS=`cat "$CLOPS_FILE" | yq e ".[$C].version"` |
| 73 | + |
| 74 | +helm_repo_add $SELECTION_NAME $SELECTION_REPO |
| 75 | + |
| 76 | +SELECTION_UPDA=`helm show chart "$SELECTION_NAME/$SELECTION_NAME" | yq '.version'` |
| 77 | + |
| 78 | +printf "\n\t%s current version is %s \n\tNewest available is %s\n" "$SELECTION_NAME" "$SELECTION_VERS" "$SELECTION_UPDA" |
| 79 | +print_divider |
| 80 | + |
| 81 | +get_chart_in_version $SELECTION_NAME |
| 82 | + |
| 83 | +print_divider |
| 84 | +print_divider |
| 85 | + |
| 86 | +### |
| 87 | +### Diff Selected Versions to current chart |
| 88 | +### |
| 89 | +helm show values "$SELECTION_NAME/$SELECTION_NAME" --version "$SELECTION_VERS" > "$SELECTED_OLD_VALUES" |
| 90 | + |
| 91 | +cat "$CLOPS_VALUES_FILE" | yq e ".$SELECTION_NAME" > "$CLOPS_TMP_FILE" |
| 92 | + |
| 93 | +## VARS |
| 94 | +VALUES_TMP="/tmp/diff" |
| 95 | +VALUES_TMP_NEW="/tmp/diff_new" |
| 96 | + |
| 97 | +python3 get_yaml_diff.py "$SELECTED_OLD_VALUES" "$SELECTED_NEW_VALUES" > "$VALUES_TMP" |
| 98 | +python3 get_yaml_diff.py "$CLOPS_TMP_FILE" "$VALUES_TMP" > "$VALUES_TMP_NEW" |
| 99 | +yq 'del(.enabled)' "$VALUES_TMP_NEW" |
| 100 | + |
| 101 | +print_divider |
| 102 | + |
0 commit comments