-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #265 from stefanprodan/resource-requirements-schema
Add resource requirements to Timoni's CUE schemas
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
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,40 @@ | ||
// Copyright 2023 Stefan Prodan | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
// CPUQuantity is a string that is validated as a quantity of CPU, such as 100m or 2000m. | ||
#CPUQuantity: string & =~"^[1-9]\\d*m$" | ||
|
||
// MemoryQuantity is a string that is validated as a quantity of memory, such as 128Mi or 2Gi. | ||
#MemoryQuantity: string & =~"^[1-9]\\d*(Mi|Gi)$" | ||
|
||
// ResourceRequirement defines the schema for the CPU and Memory resource requirements. | ||
#ResourceRequirement: { | ||
cpu?: #CPUQuantity | ||
memory?: #MemoryQuantity | ||
} | ||
|
||
// ResourceRequirements defines the schema for the compute resource requirements of a container. | ||
// More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/. | ||
#ResourceRequirements: { | ||
// Limits describes the maximum amount of compute resources allowed. | ||
limits?: #ResourceRequirement | ||
|
||
// Requests describes the minimum amount of compute resources required. | ||
// Requests cannot exceed Limits. | ||
requests?: #ResourceRequirement & { | ||
if limits != _|_ { | ||
if limits.cpu != _|_ { | ||
_lc: strconv.Atoi(strings.Split(limits.cpu, "m")[0]) | ||
_rc: strconv.Atoi(strings.Split(requests.cpu, "m")[0]) | ||
#cpu: int & >=_rc & _lc | ||
} | ||
} | ||
} | ||
} |