-
Notifications
You must be signed in to change notification settings - Fork 21
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
feat: add checkpoint uds-core slim package #818
Open
Racer159
wants to merge
39
commits into
main
Choose a base branch
from
gotta-go-fast
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.
Open
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
80a9892
feat: add frozen uds-core slim package
Racer159 59d8999
lint
Racer159 2b74bd5
tune this for speed
Racer159 895d53a
swap to checkpoint
Racer159 68a03ae
add release workflow
Racer159 7a09a33
Merge branch 'main' into gotta-go-fast
Racer159 7d86107
add testing
Racer159 a853265
add id token write back
Racer159 6af295e
install uds wo brew
Racer159 c1e3e54
install uds wo brew
Racer159 c1a457e
fix oci
Racer159 88e0aa6
fixup version var
Racer159 6e24a4a
fix version
Racer159 db1aeef
slim istio validate
Racer159 7cff415
add npm ci
Racer159 9296753
make a slim dev test
Racer159 98bd274
fix save logs
Racer159 964786b
lint
Racer159 4788325
swap back checkpoint workflow
Racer159 a05b23c
Merge branch 'main' into gotta-go-fast
Racer159 34235c9
Merge branch 'main' into gotta-go-fast
Racer159 d8a12b2
Merge branch 'main' into gotta-go-fast
Racer159 e34b0de
initial feedback
Racer159 ca35214
Merge branch 'main' into gotta-go-fast
Racer159 2211d71
add docs
Racer159 b3cb482
refine README
Racer159 d1abeee
fix lil string
Racer159 d84c408
fix last bits
Racer159 4046f6f
revert checkpoint workflow
Racer159 cb9db50
Update packages/checkpoint-dev/zarf.yaml
Racer159 3adc01d
produce a downloadable artifact
Racer159 2b0c083
fix permissions
Racer159 43a4ec2
fix docker load
Racer159 830b978
Merge branch 'main' into gotta-go-fast
Racer159 e72901a
Merge branch 'main' into gotta-go-fast
Racer159 401d88c
Update packages/checkpoint-dev/zarf.yaml
Racer159 aaea091
Merge branch 'main' into gotta-go-fast
Racer159 5cb166b
Merge branch 'main' into gotta-go-fast
Racer159 2336dc7
Merge branch 'main' into gotta-go-fast
Racer159 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,65 @@ | ||
name: Checkpoint UDS Core | ||
|
||
on: | ||
pull_request: # TODO: TEMP @WSTARR | ||
# milestoned is added here as a workaround for release-please not triggering PR workflows (PRs should be added to a milestone to trigger the workflow). | ||
types: [milestoned, opened, reopened, synchronize] | ||
# triggered by tag-and-release.yaml | ||
workflow_call: | ||
|
||
jobs: | ||
publish-uds-core: | ||
strategy: | ||
matrix: | ||
architecture: [amd64, arm64] | ||
runs-on: ${{ matrix.architecture == 'arm64' && 'uds-ubuntu-arm64-4-core' || 'uds-ubuntu-big-boy-4-core' }} | ||
name: Publish checkpoint | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
id-token: write # This is needed for OIDC federation. | ||
|
||
steps: | ||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
|
||
- name: Environment setup | ||
uses: ./.github/actions/setup | ||
with: | ||
registry1Username: ${{ secrets.IRON_BANK_ROBOT_USERNAME }} | ||
registry1Password: ${{ secrets.IRON_BANK_ROBOT_PASSWORD }} | ||
ghToken: ${{ secrets.GITHUB_TOKEN }} | ||
chainguardIdentity: ${{ secrets.CHAINGUARD_IDENTITY }} | ||
|
||
- name: Deploy K3d + UDS Core Slim Bundle | ||
run: | | ||
uds run -f tasks/deploy.yaml latest-slim-bundle-release --no-progress | ||
|
||
- name: Create Checkpoint Package | ||
run: | | ||
uds run -f tasks/create.yaml checkpoint-dev-package --no-progress | ||
|
||
- name: Test Checkpoint Package | ||
run: | | ||
uds run -f tasks/deploy.yaml checkpoint-package --no-progress | ||
npm ci | ||
uds run test:slim-dev --no-progress | ||
|
||
- name: Debug Output | ||
if: always() | ||
uses: ./.github/actions/debug-output | ||
|
||
# - name: Publish Checkpoint Package | ||
# run: uds run -f tasks/publish.yaml checkpoint-package --no-progress | ||
|
||
- name: Save logs | ||
if: always() | ||
uses: ./.github/actions/save-logs | ||
with: | ||
suffix: -${{ matrix.architecture }} | ||
|
||
- uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 | ||
with: | ||
name: checkpoint-pkg-${{ matrix.architecture }} | ||
path: | | ||
build/zarf-package-k3d-core-slim-dev-${{ matrix.architecture }}-0.28.0.tar.zst |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# K3d + UDS Core Slim Dev Checkpoint | ||
|
||
This is a special Zarf package that takes a running K3d cluster (named `uds`) and wraps its committed container and volumes into a zarf package. | ||
|
||
## Creating this package | ||
|
||
In order to create this package you must follow the following: | ||
|
||
1. Setup a K3d cluster (named `uds`) containing the contents you'd like to checkpoint | ||
|
||
> [!NOTE] | ||
> The intent for this package is that those contents are the `uds dev stack`, `zarf init` and `uds core slim` | ||
|
||
2. Run `uds zarf package create <path-to-zarf-yaml> --confirm` on the Zarf Package in this directory | ||
|
||
> [!IMPORTANT] | ||
> This package requires `sudo` to create and deploy currently - if you see a prompt and it seems stalled it is waiting for password input (hidden by the spinner) | ||
|
||
## Deploying this package | ||
|
||
Once you have a package with the contents you want created you can deploy it with: | ||
|
||
``` | ||
uds zarf package deploy <path-to-zarf-tarball> --confirm | ||
``` | ||
|
||
> [!IMPORTANT] | ||
> This package requires `sudo` to deploy and create currently - if you see a prompt and it seems stalled it is waiting for password input (hidden by the spinner) | ||
|
||
> [!NOTE] | ||
> The pre-reqs for this package are the same as `uds-k3d` and you do not need to have a cluster running prior to deploying it. |
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,74 @@ | ||
#!/bin/bash | ||
|
||
# Name of the running k3d container | ||
K3S_CONTAINER="k3d-uds-server-0" | ||
|
||
if [ -z "$TMPDIR" ]; then | ||
# macOS sets TMPDIR to a user temp directory - this also provides more options to linux | ||
TMPDIR="/tmp" | ||
fi | ||
DATA_DIR="${TMPDIR}/uds-checkpoint-data" | ||
|
||
# Step 0: Ensure we can get sudo | ||
echo "This package requires elevated permissions to create - requesting sudo (if paused enter password)" | ||
sudo echo "got sudo! success!" | ||
|
||
# Step 1: Get the container ID of the running k3d container | ||
CONTAINER_ID=$(docker ps -qf "name=$K3S_CONTAINER") | ||
|
||
if [ -z "$CONTAINER_ID" ]; then | ||
echo "No running container found for $K3S_CONTAINER" | ||
exit 1 | ||
fi | ||
|
||
# Step 2: Get the mounted volumes of the running container | ||
echo "Inspecting container volumes for $CONTAINER_ID..." | ||
VOLUMES=$(docker inspect -f '{{ json .Mounts }}' "$CONTAINER_ID" | jq) | ||
|
||
# Step 3: Prepare directories to save the volume data | ||
sudo rm -rf "$DATA_DIR" | ||
mkdir -p "${DATA_DIR}/kubelet_data" "${DATA_DIR}/k3s_data" | ||
|
||
# Step 4: Loop through volumes and copy data to corresponding directories | ||
echo "Copying volumes to local directories..." | ||
|
||
for row in $(echo "$VOLUMES" | jq -r '.[] | @base64'); do | ||
_jq() { | ||
echo "${row}" | base64 --decode | jq -r "${1}" | ||
} | ||
|
||
SOURCE=$(_jq '.Source') | ||
DESTINATION=$(_jq '.Destination') | ||
|
||
case "$DESTINATION" in | ||
"/var/lib/kubelet") | ||
echo "Copying $SOURCE to ${DATA_DIR}/kubelet_data/" | ||
sudo cp -a "$SOURCE"/. "${DATA_DIR}/kubelet_data/" | ||
;; | ||
"/var/lib/rancher/k3s") | ||
echo "Copying $SOURCE to ${DATA_DIR}/k3s_data/" | ||
sudo cp -a "$SOURCE"/. "${DATA_DIR}/k3s_data/" | ||
;; | ||
*) | ||
echo "$DESTINATION is not needed. Skipping..." | ||
;; | ||
esac | ||
done | ||
|
||
# Step 5: Commit and save the current container as a new image | ||
IMAGE_NAME="ghcr.io/defenseunicorns/uds-core/checkpoint:latest" | ||
echo "Committing container $CONTAINER_ID to image $IMAGE_NAME:latest..." | ||
docker commit -p "$CONTAINER_ID" "$IMAGE_NAME" | ||
|
||
echo "Saving image to ${DATA_DIR}/uds-k3d-checkpoint-latest.tar..." | ||
sudo docker save -o "${DATA_DIR}/uds-k3d-checkpoint-latest.tar" "$IMAGE_NAME" | ||
|
||
echo "Container image saved to ${DATA_DIR}/uds-k3d-checkpoint-latest.tar" | ||
|
||
# Step 6: Create a tarball from the data contents | ||
echo "Creating a final tarball to include in the package" | ||
sudo tar --blocking-factor=64 -cpf uds-checkpoint.tar -C "$DATA_DIR" . | ||
|
||
echo "Successfully checkpointed the cluster!" | ||
|
||
exit 0 |
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,96 @@ | ||
# yaml-language-server: $schema=https://raw.githubusercontent.com/defenseunicorns/zarf/main/zarf.schema.json | ||
|
||
kind: ZarfPackageConfig | ||
metadata: | ||
name: k3d-core-slim-dev | ||
description: "Rehydratable UDS K3d + UDS Core Slim (Istio, UDS Operator and Keycloak) Checkpoint" | ||
authors: "Defense Unicorns - Product" | ||
# x-release-please-start-version | ||
version: "0.28.0" | ||
# x-release-please-end | ||
|
||
variables: | ||
- name: CLUSTER_NAME | ||
description: "Name of the cluster" | ||
default: "uds" | ||
|
||
- name: K3D_EXTRA_ARGS | ||
description: "Optionally pass k3d arguments to the default" | ||
default: "" | ||
|
||
- name: NGINX_EXTRA_PORTS | ||
description: "Optionally allow more ports through Nginx (combine with K3D_EXTRA_ARGS '-p <port>:<port>@server:*')" | ||
default: "[]" | ||
|
||
components: | ||
- name: destroy-cluster | ||
required: true | ||
description: "Optionally destroy the cluster before creating it" | ||
actions: | ||
onDeploy: | ||
before: | ||
- cmd: | | ||
echo "This package requires elevated permissions to deploy - requesting sudo (if paused enter password)" | ||
sudo echo "got sudo! success!" | ||
- cmd: k3d cluster delete ${ZARF_VAR_CLUSTER_NAME} | ||
description: "Destroy the cluster" | ||
- cmd: | | ||
sudo rm -rf data | ||
Racer159 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- name: create-cluster | ||
required: true | ||
description: "Create the K3d cluster w/UDS Core pre-installed" | ||
files: | ||
- source: uds-checkpoint.tar | ||
target: uds-checkpoint.tar | ||
actions: | ||
onCreate: | ||
before: | ||
- cmd: ./checkpoint.sh | ||
onSuccess: | ||
- cmd: | | ||
if [ -z "$TMPDIR" ]; then | ||
# macOS sets TMPDIR to a user temp directory - this also provides more options to linux | ||
TMPDIR="/tmp" | ||
fi | ||
DATA_DIR="${TMPDIR}/uds-checkpoint-data" | ||
sudo rm -rf "$DATA_DIR" uds-checkpoint.tar | ||
onDeploy: | ||
after: | ||
- cmd: | | ||
if [ -z "$TMPDIR" ]; then | ||
# macOS sets TMPDIR to a user temp directory - this also provides more options to linux | ||
TMPDIR="/tmp" | ||
fi | ||
DATA_DIR="${TMPDIR}/uds-checkpoint-data" | ||
mkdir -p "$DATA_DIR" | ||
|
||
sudo tar --blocking-factor=64 -xpf uds-checkpoint.tar -C "$DATA_DIR" | ||
K8S_TOKEN="$(sudo cat ${DATA_DIR}/k3s_data/server/token)" | ||
echo $K8S_TOKEN | ||
sudo docker load -i "${DATA_DIR}/uds-k3d-checkpoint-latest.tar" | ||
|
||
k3d cluster create \ | ||
-p "80:80@server:*" \ | ||
-p "443:443@server:*" \ | ||
--api-port 6550 \ | ||
--k3s-arg "--disable=traefik@server:*" \ | ||
--k3s-arg "--disable=metrics-server@server:*" \ | ||
--k3s-arg "--disable=servicelb@server:*" \ | ||
--k3s-arg "--disable=local-storage@server:*" \ | ||
--k3s-arg "--token=${K8S_TOKEN}@server:*" \ | ||
-v "${DATA_DIR}/kubelet_data:/var/lib/kubelet@server:*" \ | ||
-v "${DATA_DIR}/k3s_data:/var/lib/rancher/k3s@server:*" \ | ||
--image ghcr.io/defenseunicorns/uds-core/checkpoint:latest ${ZARF_VAR_K3D_EXTRA_ARGS} \ | ||
${ZARF_VAR_CLUSTER_NAME} | ||
description: "Create the cluster" | ||
# This action waits on Keycloak since it is the slowest pod to start after cluster creation. By waiting on it, we guarantee the cluster is healthy and usable after deployment. | ||
- description: Keycloak to be Healthy | ||
wait: | ||
cluster: | ||
kind: Pod | ||
name: app.kubernetes.io/name=keycloak | ||
namespace: keycloak | ||
condition: Ready | ||
Racer159 marked this conversation as resolved.
Show resolved
Hide resolved
Racer159 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
onSuccess: | ||
- cmd: rm -f uds-checkpoint.tar |
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
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
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
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.
During creation I see these errors (which cause the deploy to fail later):
I think pretty much universally on macOS docker is run inside of a VM, in my case the VM can be accessed with
colima ssh
but docker desktop, rancher desktop, etc would likely have similar issues and ways to access the VM.I was able to rewrite a portion of this script to use
docker cp
instead and got closer (at least didn't get errors with the volumes). I think this is probably a better, more agnostic option here and simplifies a lot of this logic (no looping through volumes, just copy the two paths we need explicitly). I was hoping it might also remove the need forsudo
but in my case one of the paths gave some permission errors still until I added sudo. I'm sure there's some efficiency loss here, but since it's create time I think it's worth it to make this work across distros? In my run locally it took less than a minute still to run which still seems decently performant (granted I couldn't get it to run successfully previously so unsure of the real comparison).Would be curious your thoughts on this - I dropped the script changes into a gist since there were a handful of changes across the entirety of the file: https://gist.github.com/mjnagel/6d681678df83067169c4e652466f704f
I also had to add
--no-xattrs
to the final tar command, I got warnings/errors without this (suspect that's some macOS <> Linux stuff). This got me much closer but I hit some issues with the token:I tried to tweak the commands around startup (using the k3d
--token
option rather than k3s arg) and validated the token exists after extraction but couldn't figure this one out. Would be curious if you hit the same issue with my modified script and can figure out what's wrong?