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

Add count-based checkpoint retention policies #5

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
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
59 changes: 54 additions & 5 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ on: [push, pull_request]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
env:
CHECKPOINT_DIR: /var/lib/kubelet/checkpoints
REGISTRY_PORT: 5000
Parthiba-Hazra marked this conversation as resolved.
Show resolved Hide resolved
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -14,8 +22,20 @@ jobs:
with:
go-version-file: 'go.mod'

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: network=host

- name: Install dependencies
run: |
# Install bats
sudo apt-get update
sudo apt-get install -y bats

# Install kind
curl -sLo kind "$(curl -sL https://api.github.com/repos/kubernetes-sigs/kind/releases/latest | jq -r '[.assets[] | select(.name == "kind-linux-amd64")] | first | .browser_download_url')"
chmod +x kind
Expand All @@ -26,23 +46,52 @@ jobs:
chmod +x kubectl
sudo mv kubectl /bin/

- name: Prepare Checkpoints Directory in Host
run: |
sudo mkdir -p ${{ env.CHECKPOINT_DIR }}
sudo chmod 700 ${{ env.CHECKPOINT_DIR }}

- name: Generate Checkpoint Tar Files
run: ./test/generate_checkpoint_tar.sh

- name: Create Kubernetes cluster
run: |
kind create cluster
kind create cluster --config=./test/kind-config.yaml
kind export kubeconfig

- name: Load Docker image into kind cluster
- name: Connect the registry to the Kind network
id: connect-registry
run: |
make docker-build IMG=checkpoint-restore-operator:ci
kind load docker-image checkpoint-restore-operator:ci
REGISTRY_ID=$(docker ps -qf "ancestor=registry:2")
REGISTRY_NAME=$(docker inspect -f '{{.Name}}' $REGISTRY_ID | sed 's/\///')
echo "REGISTRY_NAME=$REGISTRY_NAME" >> $GITHUB_ENV
./test/configure_local_registry.sh
env:
REGISTRY_PORT: ${{ env.REGISTRY_PORT }}
REGISTRY_NAME: ${{ env.REGISTRY_NAME }}

- name: Build and push to local registry
uses: docker/build-push-action@v6
with:
push: true
tags: localhost:5000/checkpoint-restore-operator:ci

- name: Deploy to Kubernetes
run: |
make install
make deploy IMG=checkpoint-restore-operator:ci
make deploy IMG=localhost:5000/checkpoint-restore-operator:ci

- name: Wait for deployments to be ready
run: ./test/wait_for_deployment.sh checkpoint-restore-operator-controller-manager

- name: Check resources
run: kubectl get all -n checkpoint-restore-operator-system

- name: Test Garbage Collection
run: sudo -E bats -f "test_garbage_collection" ./test/run_tests.bats

- name: Test Max Checkpoints Set to 0
run: sudo -E bats -f "test_max_checkpoints_set_to_0" ./test/run_tests.bats

- name: Test Max Checkpoints Set to 1
run: sudo -E bats -f "test_max_checkpoints_set_to_1" ./test/run_tests.bats
32 changes: 30 additions & 2 deletions api/v1/checkpointrestoreoperator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,36 @@ import (
// CheckpointRestoreOperatorSpec defines the desired state of CheckpointRestoreOperator
type CheckpointRestoreOperatorSpec struct {
// Important: Run "make" to regenerate code after modifying this file
CheckpointDirectory string `json:"checkpointDirectory,omitempty"`
MaxCheckpointsPerContainer *int `json:"maxCheckpointsPerContainer,omitempty"`
CheckpointDirectory string `json:"checkpointDirectory,omitempty"`
ApplyPoliciesImmediately bool `json:"applyPoliciesImmediately,omitempty"`
GlobalPolicies GlobalPolicySpec `json:"globalPolicy,omitempty"`
ContainerPolicies []ContainerPolicySpec `json:"containerPolicies,omitempty"`
PodPolicies []PodPolicySpec `json:"podPolicies,omitempty"`
NamespacePolicies []NamespacePolicySpec `json:"namespacePolicies,omitempty"`
}

type GlobalPolicySpec struct {
MaxCheckpointsPerNamespaces *int `json:"maxCheckpointsPerNamespace,omitempty"`
MaxCheckpointsPerPod *int `json:"maxCheckpointsPerPod,omitempty"`
MaxCheckpointsPerContainer *int `json:"maxCheckpointsPerContainer,omitempty"`
}

type ContainerPolicySpec struct {
Namespace string `json:"namespace,omitempty"`
Pod string `json:"pod,omitempty"`
Container string `json:"container,omitempty"`
MaxCheckpoints *int64 `json:"maxCheckpoints,omitempty"`
}

type PodPolicySpec struct {
Namespace string `json:"namespace,omitempty"`
Pod string `json:"pod,omitempty"`
MaxCheckpoints *int64 `json:"maxCheckpoints,omitempty"`
}

type NamespacePolicySpec struct {
Namespace string `json:"namespace,omitempty"`
MaxCheckpoints *int64 `json:"maxCheckpoints,omitempty"`
}

// CheckpointRestoreOperatorStatus defines the observed state of CheckpointRestoreOperator
Expand Down
115 changes: 111 additions & 4 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 47 additions & 2 deletions config/crd/bases/criu.org_checkpointrestoreoperators.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,57 @@ spec:
description: CheckpointRestoreOperatorSpec defines the desired state of
CheckpointRestoreOperator
properties:
applyPoliciesImmediately:
type: boolean
checkpointDirectory:
description: 'Important: Run "make" to regenerate code after modifying
this file'
type: string
maxCheckpointsPerContainer:
type: integer
containerPolicies:
items:
properties:
container:
type: string
maxCheckpoints:
format: int64
type: integer
namespace:
type: string
pod:
type: string
type: object
type: array
globalPolicy:
properties:
maxCheckpointsPerContainer:
type: integer
maxCheckpointsPerNamespace:
type: integer
maxCheckpointsPerPod:
type: integer
type: object
namespacePolicies:
items:
properties:
maxCheckpoints:
format: int64
type: integer
namespace:
type: string
type: object
type: array
podPolicies:
items:
properties:
maxCheckpoints:
format: int64
type: integer
namespace:
type: string
pod:
type: string
type: object
type: array
type: object
status:
description: CheckpointRestoreOperatorStatus defines the observed state
Expand Down
18 changes: 17 additions & 1 deletion config/samples/_v1_checkpointrestoreoperator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,21 @@ metadata:
app.kubernetes.io/created-by: checkpoint-restore-operator
name: checkpointrestoreoperator-sample
spec:
maxCheckpointsPerContainer: 5
checkpointDirectory: /var/lib/kubelet/checkpoints
applyPoliciesImmediately: false
globalPolicy:
maxCheckpointsPerNamespace: 50
maxCheckpointsPerPod: 30
maxCheckpointsPerContainer: 10
# containerPolicies:
# - namespace: <namespace>
# pod: <pod_name>
# container: <container_name>
# maxCheckpoints: 5
# podPolicies:
# - namespace: <namespace>
# pod: <pod_name>
# maxCheckpoints: 10
# namespacePolicies:
# - namespace: <namespace>
# maxCheckpoints: 15
Loading
Loading