-
Notifications
You must be signed in to change notification settings - Fork 325
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
hack/bin/integration-cleanup.sh: Use jq magic instead of bash #1432
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
051ee98
hack/bin/integration-cleanup.sh: Use jq magic instead of bash
akshaymankar 665885d
Hi CI
akshaymankar 3e08975
hack/bin/integration-cleanup.sh: echo deletion of release
akshaymankar b169cba
handle the no-releases-to-cleanup case; drive-by shellcheck/formattin…
jschaul c225f41
Fix typo
akshaymankar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,9 @@ | ||
.[] | ||
| .parsedUpdatedTime = ( .updated | ||
| sub("(?<time>.*)\\.[\\d]+(?<tz>.*)"; "\(.time)\(.tz)") | ||
| strptime("%Y-%m-%d %H:%M:%S %z %Z") | ||
| mktime | ||
) | ||
| select ( .parsedTime < (now - 3 * 60 * 60)) | ||
| [.name, .namespace] | ||
| @tsv | ||
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 |
---|---|---|
|
@@ -4,31 +4,15 @@ | |
# | ||
# Motivation: cleanup of old test clusters that were not deleted (e.g. by the CI system, because it broke) | ||
|
||
date_seconds() { | ||
d=$1 | ||
if [[ $OSTYPE =~ darwin* ]]; then | ||
date -j -f "%b %d %H:%M:%S %Y" "$date_str" +"%s" | ||
else | ||
date -d "$d" +"%s" | ||
fi | ||
} | ||
set -euo pipefail | ||
|
||
date_now=$(date +"%s") | ||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
TOP_LEVEL="$DIR/../.." | ||
|
||
# Since helm only shows information as hard-to-parse text pending https://github.com/kubernetes/helm/pull/2950 | ||
# we are stuck with brittle grep/awk magic. | ||
|
||
IFS=$'\n' | ||
for release in $(helm list -A | grep test-); do | ||
name=$(echo "$release" | awk '{print $1}') | ||
namespace=$(echo "$release" | awk '{print $2}') | ||
date_str=$(echo "$release" | awk '{print $4" "$5" "$6}') | ||
date_s=$(date_seconds "$date_str") | ||
diff=$(( $date_now - $date_s )) | ||
if [ $diff -ge 7200 ]; then | ||
echo "test release '$name' older than 2 hours; deleting..." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wanna keep that echo statement in some modified form? |
||
releases=$(helm list -A -f 'test-' -o json \ | ||
| jq -r -f "$DIR/filter-old-releases.jq") | ||
while read line; do | ||
name=$(awk '{print $1}' <<<"$line") | ||
namespace=$(awk '{print $2}' <<<"$line") | ||
helm delete -n "$namespace" "$name" | ||
fi | ||
|
||
done | ||
unset IFS | ||
done <<<"$releases" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: why tabs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think jq can either output a json array, a csv or a tsv. Out of these I thought tsv was the most compatible with bash as I can
awk '{print $1}'
. Do you have a better idea?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just stumbled upon it and was curious, as
FS
usually defaults to space.