Resourcequota
This example shows a sample usage of the base-env
Resource Type. It is one of the implicit
Resource Types
that always gets provisioned for a Deployment.
The Resource Definition base-env-resourcequota.yaml
uses it the provision a Kubernetes manifest describing a
ResourceQuota
in the target namespace.
The base-env
Resource Definition reads the configuration values from another Resource of type config
using a
Resource Reference
. The reference specifies a class (config#quota
) so that the proper config
Resource Definition will be matched based on its matching criteria.
Two config
Resource Definitions are provided:
config-quota.yaml
will be matched for all references ofres_id: quota
config-quota-override.yaml
will additionally be matched for a particularapp_id: my-app
only, effectively providing an override for the configuration values for this particular Application id
The Resource Graphs for two Applications, one of which matches the “override” criteria, will look like this:
flowchart LR
subgraph app2[Resource Graph "my-app"]
direction LR
workload2[Workload] --> baseEnv2(type: base-env\nid: base-env) --> config2("type: config\nid:quota")
end
subgraph app1[Resource Graph "some-app"]
direction LR
workload1[Workload] --> baseEnv1(type: base-env\nid: base-env) --> config1("type: config\nid: quota")
end
resDefBaseEnv[base-env\nResource Definition]
resDefBaseEnv -.-> baseEnv1
resDefBaseEnv -.-> baseEnv2
resDefQuotaConfig[config-quota\nResource Definition] -.->|criteria:\n- res_id: quota| config1
resDefQuotaConfigOverride[config-quota-override\nResource Definition] -.->|criteria:\n- res_id: quota\n app_id: my-app| config2
Resource Definitions
base-env-resourcequota.yaml
(
view on GitHub
)
:
# This Resource Definition uses the base-env Resource type to create
# a ResourceQuota manifest in the target namespace.
# The actual values are read from a referenced config resource.
apiVersion: entity.humanitec.io/v1b1
kind: Definition
metadata:
id: base-env
entity:
name: base-env
type: base-env
driver_type: humanitec/template
driver_inputs:
values:
templates:
manifests: |-
quota.yaml:
location: namespace
data:
apiVersion: v1
kind: ResourceQuota
metadata:
name: compute-resources
spec:
hard:
limits.cpu: ${resources['config#quota'].outputs.limits-cpu}
limits.memory: ${resources['config#quota'].outputs.limits-memory}
criteria:
- {}
config-quota-override.yaml
(
view on GitHub
)
:
# This Resource Definition uses the Echo Driver to provide configuration values
apiVersion: entity.humanitec.io/v1b1
kind: Definition
metadata:
id: quota-config-override
entity:
name: quota-config-override
type: config
driver_type: humanitec/echo
driver_inputs:
# Any Driver inputs will be returned as outputs by the Echo Driver
values:
limits-cpu: "750m"
limits-memory: "750Mi"
# The matching criteria make this Resource Definition match for a particular app_id only
criteria:
- res_id: quota
app_id: my-app
config-quota.yaml
(
view on GitHub
)
:
# This Resource Definition uses the Echo Driver to provide configuration values
apiVersion: entity.humanitec.io/v1b1
kind: Definition
metadata:
id: quota-config
entity:
name: quota-config
type: config
driver_type: humanitec/echo
driver_inputs:
# Any Driver inputs will be returned as outputs by the Echo Driver
values:
limits-cpu: "500m"
limits-memory: "500Mi"
criteria:
- res_id: quota
base-env-resourcequota.tf
(
view on GitHub
)
:
resource "humanitec_resource_definition" "base-env" {
driver_type = "humanitec/template"
id = "base-env"
name = "base-env"
type = "base-env"
driver_inputs = {
values_string = jsonencode({
"templates" = {
"manifests" = "quota.yaml:\n location: namespace\n data:\n apiVersion: v1\n kind: ResourceQuota\n metadata:\n name: compute-resources\n spec:\n hard:\n limits.cpu: $${resources['config#quota'].outputs.limits-cpu}\n limits.memory: $${resources['config#quota'].outputs.limits-memory}"
}
})
}
}
resource "humanitec_resource_definition_criteria" "base-env_criteria_0" {
resource_definition_id = resource.humanitec_resource_definition.base-env.id
}
config-quota-override.tf
(
view on GitHub
)
:
resource "humanitec_resource_definition" "quota-config-override" {
driver_type = "humanitec/echo"
id = "quota-config-override"
name = "quota-config-override"
type = "config"
driver_inputs = {
values_string = jsonencode({
"limits-cpu" = "750m"
"limits-memory" = "750Mi"
})
}
}
resource "humanitec_resource_definition_criteria" "quota-config-override_criteria_0" {
resource_definition_id = resource.humanitec_resource_definition.quota-config-override.id
res_id = "quota"
app_id = "my-app"
}
config-quota.tf
(
view on GitHub
)
:
resource "humanitec_resource_definition" "quota-config" {
driver_type = "humanitec/echo"
id = "quota-config"
name = "quota-config"
type = "config"
driver_inputs = {
values_string = jsonencode({
"limits-cpu" = "500m"
"limits-memory" = "500Mi"
})
}
}
resource "humanitec_resource_definition_criteria" "quota-config_criteria_0" {
resource_definition_id = resource.humanitec_resource_definition.quota-config.id
res_id = "quota"
}