-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add k3s integration test #250
Draft
Mossaka
wants to merge
7
commits into
main
Choose a base branch
from
mossaka/k3s
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
df87d3c
tests/src/integration_test: Update port to be configurable through en…
Mossaka 2f84dcd
tests, Makefile, scripts: Added k3s tests and moved k3d to it's own t…
Mossaka cd4975e
tests, Makefile, scripts: Added k3s tests and moved k3d to it's own t…
Mossaka 7a9aba6
tests, Makefile, scripts: Added k3s tests and moved k3d to it's own t…
Mossaka ed79117
refactor(k3s): relocate and update k3s installation script
Mossaka 8b10035
refactor(images/spin): rename images/spin to images/spin-hello-world
Mossaka bc011ef
refactor(build-scripts): consolidate image build and push scripts
Mossaka 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,69 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
RUN_SPIN=false | ||
RUN_DOCKER=false | ||
|
||
cluster_name="test-cluster" | ||
OUT_DIRS=("test/out_spin" "test/out_spin_keyvalue" "test/out_spin_outbound_redis" "test/out_spin_multi_trigger_app" "test/out_spin_static_assets" "test/out_spin_mqtt_message_logger") | ||
IMAGES=("spin-hello-world" "spin-keyvalue" "spin-outbound-redis" "spin-multi-trigger-app" "spin-static-assets" "spin-mqtt-message-logger") | ||
|
||
|
||
spin_build_and_push() { | ||
local i=$1 | ||
spin build -f "./images/${IMAGES[$i]}/spin.toml" | ||
if [ "${IMAGES[$i]}" == "spin-static-assets" ]; then | ||
export SPIN_OCI_ARCHIVE_LAYERS=1 | ||
fi | ||
spin registry push "localhost:5000/spin-registry-push/${IMAGES[$i]}:latest" -f "./images/${IMAGES[$i]}/spin.toml" -k | ||
} | ||
|
||
docker_build_and_push() { | ||
local image="$1" | ||
local out_dir="$2" | ||
|
||
docker buildx build -t "${image}:latest" "./images/${image}" --load | ||
mkdir -p "${out_dir}" | ||
docker save -o "${out_dir}/img.tar" "${image}:latest" | ||
k3d image import "${out_dir}/img.tar" -c "$cluster_name" | ||
} | ||
|
||
while [[ "$#" -gt 0 ]]; do | ||
case "$1" in | ||
--spin) RUN_SPIN=true ;; | ||
--docker) RUN_DOCKER=true ;; | ||
--both) RUN_SPIN=true; RUN_DOCKER=true ;; | ||
*) echo "Unknown option: $1"; exit 1 ;; | ||
esac | ||
shift | ||
done | ||
|
||
if ! $RUN_SPIN && ! $RUN_DOCKER; then | ||
echo "Error: At least one of --spin, --docker, or --both must be specified." | ||
exit 1 | ||
fi | ||
|
||
|
||
if $RUN_SPIN; then | ||
echo "Running Spin builds and pushes..." | ||
if ! docker ps | grep -q test-registry; then | ||
docker run -d -p 5000:5000 --name test-registry registry:2 | ||
fi | ||
for i in "${!IMAGES[@]}"; do | ||
spin_build_and_push "$i" & | ||
done | ||
fi | ||
|
||
if $RUN_DOCKER; then | ||
echo "Running Docker builds and pushes..." | ||
for i in "${!IMAGES[@]}"; do | ||
docker_build_and_push "${IMAGES[$i]}" "${OUT_DIRS[$i]}" & | ||
done | ||
fi | ||
|
||
# Wait for all background jobs to finish | ||
wait | ||
|
||
sleep 5 | ||
echo "Images are ready" |
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,14 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
# Install k3s | ||
# Since the latest k3s already bakes in the Spin shim, we don't need to reconfigure it. | ||
# We will just need to make sure that containerd-shim-spin-v2 binary is in PATH | ||
# and that the k3s service is running. | ||
|
||
curl -sfL https://get.k3s.io | sh -s - server --write-kubeconfig-mode '0644' | ||
sudo systemctl start k3s | ||
|
||
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml | ||
kubectl get nodes |
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,21 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
cluster_name="test-cluster" | ||
dockerfile_path="deployments/k3d" | ||
|
||
docker build -t k3d-shim-test "$dockerfile_path" | ||
|
||
k3d cluster create "$cluster_name" \ | ||
--image k3d-shim-test --api-port 6551 -p '8082:80@loadbalancer' --agents 2 \ | ||
--registry-create test-registry:0.0.0.0:5000 \ | ||
--k3s-arg '--kubelet-arg=eviction-hard=imagefs.available<1%,nodefs.available<1%@agent:*' \ | ||
--k3s-arg '--kubelet-arg=eviction-minimum-reclaim=imagefs.available=1%,nodefs.available=1%@agent:*' | ||
|
||
kubectl wait --for=condition=ready node --all --timeout=120s | ||
|
||
echo "Running Spin and Docker builds and pushes..." | ||
./scripts/spin-build-and-push-images.sh --both | ||
|
||
echo ">>> Cluster setup and image builds/pushes complete!" |
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 | ||||
---|---|---|---|---|---|---|
|
@@ -2,7 +2,20 @@ | |||||
|
||||||
set -euo pipefail | ||||||
|
||||||
kubectl delete -f tests/workloads-common --wait --timeout 60s --ignore-not-found=true | ||||||
kubectl delete -f tests/workloads-pushed-using-docker-build-push --wait --timeout 60s --ignore-not-found=true | ||||||
kubectl delete -f tests/workloads-pushed-using-spin-registry-push --wait --timeout 60s --ignore-not-found=true | ||||||
case "$1" in | ||||||
k3d) | ||||||
TESTS_PATH="tests/k3d" | ||||||
;; | ||||||
k3s) | ||||||
TESTS_PATH="tests/k3s" | ||||||
;; | ||||||
*) | ||||||
echo "Invalid argument. Use 'k3d' or 'k3s'." | ||||||
exit 1 | ||||||
;; | ||||||
esac | ||||||
|
||||||
kubectl delete -f "tests/workloads-common" --wait --timeout 60s --ignore-not-found=true | ||||||
kubectl delete -f "tests/workloads-pushed-using-docker-build-push" --wait --timeout 60s --ignore-not-found=true | ||||||
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.
Suggested change
|
||||||
kubectl delete -f "$TESTS_PATH/workloads-pushed-using-spin-registry-push" --wait --timeout 60s --ignore-not-found=true | ||||||
kubectl wait pod --for=delete -l app=wasm-spin -l app=spin-keyvalue -l app=spin-outbound-redis -l app=spin-multi-trigger-app --timeout 60s |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 @@ | ||
This folder has yaml file to apply workloads which are built using `spin build` and pushed to a registry, managed with k3d in CI, using `spin registry push` command. |
Oops, something went wrong.
Oops, something went wrong.
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.
This highlights that it would be nice to have all the tests in one directory regardless of the K8s runtime rather than duplicating