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

attempt to convert to ephemoral container #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
29 changes: 18 additions & 11 deletions aggregator-backup/download-aggregator.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env bash
#
# This script will use kubectl to copy the aggregator data files to a temporary
# location, then tar the contents and remove the temp directory
# This script will use kubectl to copy the aggregator data files using an ephemeral container

set -eo pipefail

Expand Down Expand Up @@ -35,18 +34,26 @@ if [ "$r" == "${r#[y]}" ]; then
fi

# Grab the Pod Name of the aggregator pod
# If you use zsh and this line isn't working, it is likely due to your partial line response
# and zsh adds a % delimeter to the end. Add the following line to your ~/.zshrc file:
# PROMPT_EOL_MARK=''
podName="$(kubectl get pods -n "$namespace" -l app=aggregator -o jsonpath='{.items[0].metadata.name}')"

# find read db file
readDbFile="$(kubectl exec -c aggregator "$podName" -n "$namespace" -- find /var/configs/waterfowl -type f -name '*.read')"
echo "Found read db file: $readDbFile"
# Use ephemeral container to access and copy the read DB file
echo "Accessing aggregator filesystem using ephemeral container..."
kubectl debug -n "$namespace" "$podName" -it --image=busybox --target=aggregator --share-processes -- /bin/sh -c "
cd /proc/1/root${aggDir}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we know for sure this is always under /proc/1/root ?

@jessegoodier @cliffcolvin

readDbFile=\$(find . -type f -name '*.read')
if [ -z \"\$readDbFile\" ]; then
echo 'Read DB file not found'
exit 1
fi
echo \"Found read db file: \$readDbFile\"
mkdir -p /tmp/$tmpDir
cp \"\$readDbFile\" /tmp/$tmpDir/
echo 'File copied to ephemeral container'
" || { echo "Failed to access or copy file from ephemeral container"; exit 1; }

# Download file from container and store it in the same filename in current directory
echo "Copying aggregator Files from $namespace/$podName:$aggDir to $tmpDir..."
kubectl cp -c aggregator "$namespace"/"$podName":"$readDbFile" ./$tmpDir/"$podName".read
# Copy file from ephemeral container to local machine
echo "Copying file from ephemeral container to local machine..."
kubectl cp -n "$namespace" "$podName":/tmp/$tmpDir ./$tmpDir

# Archive the directory
tar cfz kubecost-aggregator.tar.gz $tmpDir && \
Expand Down