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

feat: Introduced storage/size based global, container, pod, and namespace-level policies #6

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,9 @@ jobs:

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

- name: Test Max Total Checkpoint Size
run: sudo -E bats -f "test_max_total_checkpoint_size" ./test/run_tests.bats

- name: Test Max Checkpoint Size
run: sudo -E bats -f "test_max_checkpoint_size" ./test/run_tests.bats
35 changes: 23 additions & 12 deletions api/v1/checkpointrestoreoperator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1

import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -34,27 +35,37 @@ type CheckpointRestoreOperatorSpec struct {
}

type GlobalPolicySpec struct {
MaxCheckpointsPerNamespaces *int `json:"maxCheckpointsPerNamespace,omitempty"`
MaxCheckpointsPerPod *int `json:"maxCheckpointsPerPod,omitempty"`
MaxCheckpointsPerContainer *int `json:"maxCheckpointsPerContainer,omitempty"`
MaxCheckpointsPerNamespaces *int `json:"maxCheckpointsPerNamespace,omitempty"`
MaxCheckpointsPerPod *int `json:"maxCheckpointsPerPod,omitempty"`
MaxCheckpointsPerContainer *int `json:"maxCheckpointsPerContainer,omitempty"`
MaxCheckpointSize *resource.Quantity `json:"maxCheckpointSize,omitempty"`
MaxTotalSizePerNamespace *resource.Quantity `json:"maxTotalSizePerNamespace,omitempty"`
MaxTotalSizePerPod *resource.Quantity `json:"maxTotalSizePerPod,omitempty"`
MaxTotalSizePerContainer *resource.Quantity `json:"maxTotalSizePerContainer,omitempty"`
}

type ContainerPolicySpec struct {
Namespace string `json:"namespace,omitempty"`
Pod string `json:"pod,omitempty"`
Container string `json:"container,omitempty"`
MaxCheckpoints *int64 `json:"maxCheckpoints,omitempty"`
Namespace string `json:"namespace,omitempty"`
Pod string `json:"pod,omitempty"`
Container string `json:"container,omitempty"`
MaxCheckpoints *int `json:"maxCheckpoints,omitempty"`
MaxCheckpointSize *resource.Quantity `json:"maxCheckpointSize,omitempty"`
MaxTotalSize *resource.Quantity `json:"maxTotalSize,omitempty"`
}

type PodPolicySpec struct {
Namespace string `json:"namespace,omitempty"`
Pod string `json:"pod,omitempty"`
MaxCheckpoints *int64 `json:"maxCheckpoints,omitempty"`
Namespace string `json:"namespace,omitempty"`
Pod string `json:"pod,omitempty"`
MaxCheckpoints *int `json:"maxCheckpoints,omitempty"`
MaxCheckpointSize *resource.Quantity `json:"maxCheckpointSize,omitempty"`
MaxTotalSize *resource.Quantity `json:"maxTotalSize,omitempty"`
}

type NamespacePolicySpec struct {
Namespace string `json:"namespace,omitempty"`
MaxCheckpoints *int64 `json:"maxCheckpoints,omitempty"`
Namespace string `json:"namespace,omitempty"`
MaxCheckpoints *int `json:"maxCheckpoints,omitempty"`
MaxCheckpointSize *resource.Quantity `json:"maxCheckpointSize,omitempty"`
MaxTotalSize *resource.Quantity `json:"maxTotalSize,omitempty"`
}

// CheckpointRestoreOperatorStatus defines the observed state of CheckpointRestoreOperator
Expand Down
56 changes: 53 additions & 3 deletions api/v1/zz_generated.deepcopy.go

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

23 changes: 20 additions & 3 deletions config/crd/bases/criu.org_checkpointrestoreoperators.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ spec:
properties:
container:
type: string
maxCheckpointSize:
type: integer
maxCheckpoints:
format: int64
type: integer
maxTotalSize:
type: integer
namespace:
type: string
Expand All @@ -63,18 +66,29 @@ spec:
type: array
globalPolicy:
properties:
maxCheckpointSize:
type: integer
maxCheckpointsPerContainer:
type: integer
maxCheckpointsPerNamespace:
type: integer
maxCheckpointsPerPod:
type: integer
maxTotalSizePerContainer:
type: integer
maxTotalSizePerNamespace:
type: integer
maxTotalSizePerPod:
type: integer
type: object
namespacePolicies:
items:
properties:
maxCheckpointSize:
type: integer
maxCheckpoints:
format: int64
type: integer
maxTotalSize:
type: integer
namespace:
type: string
Expand All @@ -83,8 +97,11 @@ spec:
podPolicies:
items:
properties:
maxCheckpointSize:
type: integer
maxCheckpoints:
format: int64
type: integer
maxTotalSize:
type: integer
namespace:
type: string
Expand Down
10 changes: 10 additions & 0 deletions config/samples/_v1_checkpointrestoreoperator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,25 @@ spec:
maxCheckpointsPerNamespace: 50
maxCheckpointsPerPod: 30
maxCheckpointsPerContainer: 10
maxCheckpointSize: 10
maxTotalSizePerNamespace: 1000
maxTotalSizePerPod: 500
maxTotalSizePerContainer: 100
# containerPolicies:
# - namespace: <namespace>
# pod: <pod_name>
# container: <container_name>
# maxCheckpoints: 5
# maxCheckpointSize: 10
# maxTotalSize: 100
Copy link
Member

Choose a reason for hiding this comment

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

It might be better to use format similar to other resource limits in Kubernetes:

https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#meaning-of-memory

Limits and requests for memory are measured in bytes. You can express memory as a plain integer or as a fixed-point number using one of these quantity suffixes: E, P, T, G, M, k. You can also use the power-of-two equivalents: Ei, Pi, Ti, Gi, Mi, Ki.

# podPolicies:
# - namespace: <namespace>
# pod: <pod_name>
# maxCheckpoints: 10
# maxCheckpointSize: 10
# maxTotalSize: 500
# namespacePolicies:
# - namespace: <namespace>
# maxCheckpoints: 15
# maxCheckpointSize: 10
# maxTotalSize: 1000
14 changes: 14 additions & 0 deletions docs/retention_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ spec:
# pod: <pod_name>
# container: <container_name>
# maxCheckpoints: 5
# maxCheckpointSize: 6 # Maximum size of a single checkpoint in MB
# maxTotalSize: 20 # Maximum total size of checkpoints for the container in MB
# podPolicies:
# - namespace: <namespace>
# pod: <pod_name>
# maxCheckpoints: 10
# maxCheckpointSize: 8 # Maximum size of a single checkpoint in MB
# maxTotalSize: 50 # Maximum total size of checkpoints for the pod in MB
# namespacePolicies:
# - namespace: <namespace>
# maxCheckpoints: 15`
Expand All @@ -54,18 +58,28 @@ A sample configuration file is available [here](/config/samples/_v1_checkpointre
- `maxCheckpointsPerNamespace`: Maximum number of checkpoints per namespace.
- `maxCheckpointsPerPod`: Maximum number of checkpoints per pod.
- `maxCheckpointsPerContainer`: Maximum number of checkpoints per container.
- `maxCheckpointSize`: Maximum size of a single checkpoint in MB.
- `maxTotalSizePerNamespace`: Maximum total size of checkpoints per namespace in MB.
- `maxTotalSizePerPod`: Maximum total size of checkpoints per pod in MB.
- `maxTotalSizePerContainer`: Maximum total size of checkpoints per container in MB.
- `containerPolicies` (optional): Specific retention policies for containers.
- `namespace`: Namespace of the container.
- `pod`: Pod name of the container.
- `container`: Container name.
- `maxCheckpoints`: Maximum number of checkpoints for the container.
- `maxCheckpointSize`: Maximum size of a single checkpoint in MB.
- `maxTotalSize`: Maximum total size of checkpoints for the container in MB.
- `podPolicies` (optional): Specific retention policies for pods.
- `namespace`: Namespace of the pod.
- `pod`: Pod name.
- `maxCheckpoints`: Maximum number of checkpoints for the pod.
- `maxCheckpointSize`: Maximum size of a single checkpoint in MB.
- `maxTotalSize`: Maximum total size of checkpoints for the pod in MB.
- `namespacePolicies` (optional): Specific retention policies for namespaces.
- `namespace`: Namespace name.
- `maxCheckpoints`: Maximum number of checkpoints for the namespace.
- `maxCheckpointSize`: Maximum size of a single checkpoint in MB.
- `maxTotalSize`: Maximum total size of checkpoints for the namespace in MB.

## Policy Hierarchy and Application

Expand Down
Loading
Loading