Skip to content

Commit

Permalink
Merge pull request #265 from stefanprodan/resource-requirements-schema
Browse files Browse the repository at this point in the history
Add resource requirements to Timoni's CUE schemas
  • Loading branch information
stefanprodan authored Dec 3, 2023
2 parents 71fe137 + 84b0c6e commit b5541f1
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions schemas/timoni.sh/core/v1alpha1/requirements.cue
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
}
}
}
}

0 comments on commit b5541f1

Please sign in to comment.