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: Add support for defining resource limits in a component's properties #446

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions crates/wadm-types/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl From<ComponentProperties> for wadm::types::ComponentProperties {
wadm::types::ComponentProperties {
image: properties.image,
id: properties.id,
resources: properties.resources,
config: properties.config.into_iter().map(|c| c.into()).collect(),
secrets: properties.secrets.into_iter().map(|c| c.into()).collect(),
}
Expand Down Expand Up @@ -392,6 +393,7 @@ impl From<wadm::types::ComponentProperties> for ComponentProperties {
ComponentProperties {
image: properties.image,
id: properties.id,
resources: properties.resources,
config: properties.config.into_iter().map(|c| c.into()).collect(),
secrets: properties.secrets.into_iter().map(|c| c.into()).collect(),
}
Expand Down
11 changes: 11 additions & 0 deletions crates/wadm-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ pub struct ComponentProperties {
/// these values at runtime using `wasi:runtime/config.`
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub config: Vec<ConfigProperty>,
/// Configuration for setting the amount of resources available for the component
#[serde(skip_serializing_if = "Option::is_none")]
pub resources: Option<ResourceProperty>,
/// Named secret references to pass to the component. The component will be able to retrieve
/// these values at runtime using `wasmcloud:secrets/store`.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
Expand All @@ -238,6 +241,13 @@ pub struct ConfigDefinition {
pub secrets: Vec<SecretProperty>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash, JsonSchema)]
pub struct ResourceProperty {
/// The maximum amount of memory, in megabytes, that the component is allowed to consume.
#[validate(range(min = 1))]
pub memory: usize,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash, JsonSchema)]
pub struct SecretProperty {
/// The name of the secret. This is used by a reference by the component or capability to
Expand Down Expand Up @@ -759,6 +769,7 @@ mod test {
image: "wasmcloud.azurecr.io/fake:1".to_string(),
id: None,
config: vec![],
resources: None,
secrets: vec![],
},
},
Expand Down
25 changes: 25 additions & 0 deletions oam.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@
"description": "The image reference to use",
"type": "string"
},
"resources": {
"description": "Configuration for setting the amount of resources available for the component",
"anyOf": [
{
"$ref": "#/definitions/ResourceProperty"
},
{
"type": "null"
}
]
},
"secrets": {
"description": "Named secret references to pass to the component. The component will be able to retrieve these values at runtime using `wasmcloud:secrets/store`.",
"type": "array",
Expand Down Expand Up @@ -280,6 +291,20 @@
}
}
},
"ResourceProperty": {
"type": "object",
"required": [
"memory"
],
"properties": {
"memory": {
"description": "The maximum amount of memory, in megabytes, that the component is allowed to consume.",
"type": "integer",
"format": "uint",
"minimum": 1.0
}
}
},
"SecretProperty": {
"type": "object",
"required": ["name", "properties"],
Expand Down
6 changes: 6 additions & 0 deletions wit/wadm/types.wit
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ interface types {
record component-properties {
image: string,
id: option<string>,
resources: option<resource-property>
config: list<config-property>,
secrets: list<secret-property>,
}
Expand Down Expand Up @@ -173,6 +174,11 @@ interface types {
properties: option<list<tuple<string, string>>>,
}

// Resource properties
record resource-property {
memory: u32,
}

// Secret properties
record secret-property {
name: string,
Expand Down
Loading