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

Small fixes due to 0.17 to 1.0 upgrade testing #592

Merged
merged 1 commit into from
Apr 28, 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
24 changes: 12 additions & 12 deletions deploy/helm/sumologic/upgrade-1.0.0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This script will automatically take the configurations of your existing values.y
and return one that is compatible with v1.0.0.

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

Usage:
Expand Down Expand Up @@ -172,11 +172,11 @@ done
yq w -i new.yaml falco.enabled false

# Preserve the functionality of addStream=false or addTime=false
if [ $(yq r $OLD_VALUES_YAML sumologic.addStream) != "true" ] && [ $(yq r $OLD_VALUES_YAML sumologic.addTime) != "true" ]; then
if [ "$(yq r $OLD_VALUES_YAML sumologic.addStream)" != "true" ] && [ "$(yq r $OLD_VALUES_YAML sumologic.addTime)" != "true" ]; then
REMOVE="stream,time"
elif [ $(yq r $OLD_VALUES_YAML sumologic.addStream) != "true" ]; then
elif [ "$(yq r $OLD_VALUES_YAML sumologic.addStream)" != "true" ]; then
REMOVE="stream"
elif [ $(yq r $OLD_VALUES_YAML sumologic.addTime) != "true" ]; then
elif [ "$(yq r $OLD_VALUES_YAML sumologic.addTime)" != "true" ]; then
REMOVE="time"
fi

Expand All @@ -185,7 +185,7 @@ FILTER="<filter containers.**>
remove_keys $REMOVE
</filter>"

if [ $(yq r $OLD_VALUES_YAML sumologic.addStream) != "true" ] || [ $(yq r $OLD_VALUES_YAML sumologic.addTime) != "true" ]; then
if [ "$(yq r $OLD_VALUES_YAML sumologic.addStream)" != "true" ] || [ "$(yq r $OLD_VALUES_YAML sumologic.addTime)" != "true" ]; then
yq w -i new.yaml fluentd.logs.containers.extraFilterPluginConf "$FILTER"
fi

Expand Down Expand Up @@ -240,21 +240,21 @@ function get_release_regex() {
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/"$//'
}

metrics_length=$(yq r -l "${OLD_VALUES_YAML}" 'prometheus-operator.prometheus.prometheusSpec.remoteWrite')
metrics_length=$(( ${metrics_length} - 1))
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_regex_length=$(yq r -l "${OLD_VALUES_YAML}" "prometheus-operator.prometheus.prometheusSpec.remoteWrite[${i}].writeRelabelConfigs")
metric_regex_length=$(( ${metric_regex_length} - 1))
metric_name="$(yq r "${OLD_VALUES_YAML}" "prometheus-operator.prometheus.prometheusSpec.remoteWrite[${i}].url" | grep -oP '/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))"

for j in $(seq 0 ${metric_regex_length}); do
metric_regex_action=$(yq r "${OLD_VALUES_YAML}" "prometheus-operator.prometheus.prometheusSpec.remoteWrite[${i}].writeRelabelConfigs[${j}].action")
if [[ "${metric_regex_action}" = "keep" ]]; then
break
fi
done
regexes_len=$(echo -e ${expected_metrics} | grep -A 2 "${metric_name}$" | grep regex | wc -l)
regexes_len="$(echo -e ${expected_metrics} | grep -A 2 "${metric_name}$" | grep regex | wc -l)"
if [[ "${regexes_len}" -eq "2" ]]; then

regex_1_0="$(get_release_regex "${metric_name}" '^\s+-' 'head')"
Expand All @@ -264,7 +264,7 @@ for i in $(seq 0 ${metrics_length}); do
yq w -i new.yaml "prometheus-operator.prometheus.prometheusSpec.remoteWrite[${i}].writeRelabelConfigs[${j}].regex" "${regex_1_0}"
else
echo "Changes of regex for 'prometheus-operator.prometheus.prometheusSpec.remoteWrite[${i}].writeRelabelConfigs[${j}]' (${metric_name}) detected, please migrate it manually"
git --no-pager diff $(echo "${regex_0_17}" | git hash-object -w --stdin) $(echo "${regex}" | git hash-object -w --stdin) --word-diff-regex='[^\|]'
git --no-pager diff --no-index $(echo "${regex_0_17}" | git hash-object -w --stdin) $(echo "${regex}" | git hash-object -w --stdin) --word-diff-regex='[^\|]'
fi
fi

Expand Down