Archive pruner (#471)

All functions have a pkg reference. This can be a package with either source and a deploy archives, or, a deploy archive. Everytime a function is updated, a new package is created. With archive pruner, the archives that are pointed to by old pkg reference can be deleted from the storage.

* High level spec for package pruning.
* Skeleton for archive pruning
* Adding meat 1 to skeleton.
* Adding meat #2. Separated storage service into a httpHandler component and
Storage Layer component.
* Adding meat #3. getOrphanedArchives in pruner and getItems on
stowClient.
* Restructured archivePruner methods.
* Commiting the day's work. Ready for testing #1.
* Fixing compile errors.
* Test ready. added a few logs for debugging.
* Adding a filter for getItems in stowClient.
* After testing.
* Added a test for archivePruner.
* Adding helm value pruneInterval for testing.
* Modified test.
* Final test.
* Fixing interval from seconds to minutes.
* Small change.
* Changing debugs to info.
* Removing the WIP design
* Ran gofmt on all these files.
* Fixing prune_interval as string in ENV var.

* Addressing all comments, but one.

* changing getFile method in stowClient to stream it into a response.

* All comments incorporated.
* Introducing a new flag for running archivePruner.
1. This flag is disabled for archivePruner to run in unit test.
2. This flag is enabled for archivePruner to run in production.
3. Also disabling test_archive_pruner.sh in this PR. Follow up with
next PR to enable it.

* Addressing review comments.

* Changing the command to generate a file dynamically.

* Enabling arching_pruner_test

* giving execute permissions to test_archive_pruner.sh

* Making changes of positional parameters after recent commit.
Change test case permission and removing kubectlPortForward.

* Adding debug to see why test_utils.sh passed junk pruneInterval.

* shell needs special handling for positional parameters from 10.
This commit is contained in:
smruthi2187
2018-02-01 18:13:36 +08:00
committed by Ta-Ching Chen
parent 0c92f59c38
commit 31ba992726
14 changed files with 622 additions and 112 deletions
+2 -1
View File
@@ -16,6 +16,7 @@ FETCHER_IMAGE=$REPO/fetcher
FLUENTD_IMAGE=gcr.io/fission-ci/fluentd
BUILDER_IMAGE=$REPO/builder
TAG=test
PRUNE_INTERVAL=1 # this variable controls the interval to run archivePruner. The unit is in minutes.
dump_system_info
@@ -35,4 +36,4 @@ build_and_push_fluentd $FLUENTD_IMAGE:$TAG
build_fission_cli
install_and_test $IMAGE $TAG $FETCHER_IMAGE $TAG $FLUENTD_IMAGE $TAG
install_and_test $IMAGE $TAG $FETCHER_IMAGE $TAG $FLUENTD_IMAGE $TAG $PRUNE_INTERVAL
+4 -2
View File
@@ -162,11 +162,12 @@ helm_install_fission() {
routerNodeport=$7
fluentdImage=$8
fluentdImageTag=$9
pruneInterval="${10}"
ns=f-$id
fns=f-func-$id
helmVars=image=$image,imageTag=$imageTag,fetcherImage=$fetcherImage,fetcherImageTag=$fetcherImageTag,functionNamespace=$fns,controllerPort=$controllerNodeport,routerPort=$routerNodeport,pullPolicy=Always,analytics=false,logger.fluentdImage=$fluentdImage,logger.fluentdImageTag=$fluentdImageTag
helmVars=image=$image,imageTag=$imageTag,fetcherImage=$fetcherImage,fetcherImageTag=$fetcherImageTag,functionNamespace=$fns,controllerPort=$controllerNodeport,routerPort=$routerNodeport,pullPolicy=Always,analytics=false,logger.fluentdImage=$fluentdImage,logger.fluentdImageTag=$fluentdImageTag,pruneInterval=$pruneInterval
timeout 30 bash -c "helm_setup"
@@ -369,6 +370,7 @@ install_and_test() {
fetcherImageTag=$4
fluentdImage=$5
fluentdImageTag=$6
pruneInterval=$7
controllerPort=31234
routerPort=31235
@@ -377,7 +379,7 @@ install_and_test() {
id=$(generate_test_id)
trap "helm_uninstall_fission $id" EXIT
if ! helm_install_fission $id $image $imageTag $fetcherImage $fetcherImageTag $controllerPort $routerPort $fluentdImage $fluentdImageTag
if ! helm_install_fission $id $image $imageTag $fetcherImage $fetcherImageTag $controllerPort $routerPort $fluentdImage $fluentdImageTag $pruneInterval
then
dump_logs $id
exit 1
+117
View File
@@ -0,0 +1,117 @@
#!/bin/bash
set -euo pipefail
# global variables
pkg=""
http_status=""
url=""
cleanup() {
if [ -e "test-deploy-pkg.zip" ]; then
rm -rf test-deploy-pkg.zip test_dir
fi
if [ -e "/tmp/file" ]; then
rm -rf /tmp/file
fi
}
create_archive() {
echo "Creating an archive"
mkdir test_dir
dd if=/dev/urandom of=test_dir/dynamically_generated_file bs=256k count=1
printf 'def main():\n return "Hello, world!"' > test_dir/hello.py
zip -jr test-deploy-pkg.zip test_dir/
}
create_package() {
echo "Creating package"
pkg=$(fission package create --deploy "test-deploy-pkg.zip" --env python| cut -f2 -d' '| tr -d \')
}
delete_package() {
echo "Deleting package: $1"
fission package delete --name $1
}
get_archive_url_from_package() {
echo "Getting archive URL from package: $1"
url=`kubectl get package $1 -ojsonpath='{.spec.deployment.url}'`
}
get_archive_from_storage() {
http_status=`curl -sw "%{http_code}" $1 -o /tmp/file`
}
#1. declare trap to cleanup for all the required signals
#2. create an archives with large files such that total size of archive is > 256KB
#3. create 2 pkgs referencing those archives
#4. delete both the packages
#5. verify archives are not recycled . this handles the case where archives are just created but not referenced by pkgs yet.
#6. sleep for two minutes
#7. now verify that both get deleted.
main() {
# trap
trap cleanup EXIT
# create a huge archive
create_archive
echo "created archive test-deploy-pkg.zip"
# create packages with the huge archive
create_package
pkg_1=$pkg
get_archive_url_from_package $pkg_1
url_1=$url
echo "pkg: $pkg_1, archive_url : $url_1"
create_package
pkg_2=$pkg
get_archive_url_from_package $pkg_2
url_2=$url
echo "pkg: $pkg_2, archive_url : $url_2"
# delete packages
delete_package $pkg_1
delete_package $pkg_2
echo "deleted packages : $pkg_1 $pkg_2"
# curl on the archive url
get_archive_from_storage $url_1
echo "http_status for $url_1 : $http_status"
if [ "$http_status" -ne "200" ]; then
echo "Archive $url_1 absent on storage, while expected to be present"
exit 1
fi
# curl on the archive url
get_archive_from_storage $url_2
echo "http_status for $url_2 : $http_status"
if [ "$http_status" -ne "200" ]; then
echo "Archive $url_2 absent on storage, while expected to be present"
exit 1
fi
# archivePruner is set to run every minute for test. In production, its set to run every hour.
echo "waiting for packages to get recycled"
sleep 120
# curl on the archive url
get_archive_from_storage $url_1
echo "http_status for $url_1 : $http_status"
if [ "$http_status" -ne "404" ]; then
echo "Archive $url_1 should have been recycled, but curl returned $http_status, while expected status is 404."
exit 1
fi
# curl on the archive url
get_archive_from_storage $url_2
echo "http_status for $url_2 : $http_status"
if [ "$http_status" -ne "404" ]; then
echo "Archive $url_2 should have been recycled, but curl returned $http_status, while expected status is 404."
exit 1
fi
echo "Test archive pruner PASSED"
}
main