Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade script fixes #613

Merged
merged 4 commits into from
May 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions deploy/helm/sumologic/upgrade-1.0.0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and return one that is compatible with v1.0.0.

Requirements:
yq (3.2.1) https://github.com/mikefarah/yq/releases/tag/3.2.1
curl
grep
sed
git diff in case of changes to Prometheus remote write regexes

Usage:
Expand All @@ -23,16 +26,27 @@ Returns:
For more details, please refer to Migration steps and Changelog here: [link]
"

if [ "$1" = "" ]; then

if [[ "$1" = "" ]] || [[ "$1" = "--help" ]]; then
echo "$MAN"
exit 1
fi

function check_required_command() {
local command_to_check="$1"
command -v ${command_to_check} >/dev/null 2>&1 || { echo >&2 "Required command is missing: ${command_to_check}"; echo >&2 "Please consult --help and install missing commands before continue. Aborting."; exit 1; }
}

check_required_command yq
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: yq should be in exactly 3.2.1 version

check_required_command grep
check_required_command sed
check_required_command curl

readonly OLD_VALUES_YAML="$1"
readonly HELM_RELEASE_NAME="${2:-collection}"
readonly NAMESPACE="${3:-sumologic}"

URL=https://raw.githubusercontent.com/SumoLogic/sumologic-kubernetes-collection/v1.0.0/deploy/helm/sumologic/values.yaml
URL=https://raw.githubusercontent.com/SumoLogic/sumologic-kubernetes-collection/release-v1.0/deploy/helm/sumologic/values.yaml
curl -s $URL > new.yaml

OLD_CONFIGS="sumologic.eventCollectionEnabled
Expand Down Expand Up @@ -227,8 +241,8 @@ fi
# Prometheus changes
# Diff of prometheus regexes:
# git diff v1.0.0 v0.17.1 deploy/helm/sumologic/values.yaml | \
# grep -P '(regex|url)\:' | \
# grep -P "^(\-|\+)\s+ (regex|url)\:" | \
# grep -E '(regex|url)\:' | \
# grep -E "^(\-|\+)\s+ (regex|url)\:" | \
# sed 's|- url: http://$(CHART).$(NAMESPACE).svc.cluster.local:9888||' | \
# sed 's/$/\\n/'
#
Expand Down Expand Up @@ -272,14 +286,14 @@ function get_release_regex() {
local str_grep="${2}"
local filter="${3}"

echo -e ${expected_metrics} | grep -A 3 "${metric_name}$" | "${filter}" -n 3 | grep -P "${str_grep}" | grep -oP ': .*' | sed 's/: //' | sed -e "s/^'//" -e 's/^"//' -e "s/'$//" -e 's/"$//'
echo -e ${expected_metrics} | grep -A 3 "${metric_name}$" | "${filter}" -n 3 | grep -E "${str_grep}" | grep -oE ': .*' | sed 's/: //' | sed -e "s/^'//" -e 's/^"//' -e "s/'$//" -e 's/"$//'
}

metrics_length="$(yq r -l "${OLD_VALUES_YAML}" 'prometheus-operator.prometheus.prometheusSpec.remoteWrite')"
metrics_length="$(( ${metrics_length} - 1))"

for i in $(seq 0 ${metrics_length}); do
metric_name="$(yq r "${OLD_VALUES_YAML}" "prometheus-operator.prometheus.prometheusSpec.remoteWrite[${i}].url" | grep -oP '/prometheus\.metrics.*')"
metric_name="$(yq r "${OLD_VALUES_YAML}" "prometheus-operator.prometheus.prometheusSpec.remoteWrite[${i}].url" | grep -oE '/prometheus\.metrics.*')"
metric_regex_length="$(yq r -l "${OLD_VALUES_YAML}" "prometheus-operator.prometheus.prometheusSpec.remoteWrite[${i}].writeRelabelConfigs")"
metric_regex_length="$(( ${metric_regex_length} - 1))"

Expand Down