Skip to content

Commit

Permalink
refactor: abstract component_to_scalers fn
Browse files Browse the repository at this point in the history
Signed-off-by: Brooks Townsend <[email protected]>
  • Loading branch information
brooksmtownsend committed Sep 12, 2024
1 parent c156dc0 commit b64dca9
Show file tree
Hide file tree
Showing 5 changed files with 380 additions and 343 deletions.
26 changes: 13 additions & 13 deletions crates/wadm-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub const VERSION_ANNOTATION_KEY: &str = "version";
/// The description key, as predefined by the [OAM
/// spec](https://github.com/oam-dev/spec/blob/master/metadata.md#annotations-format)
pub const DESCRIPTION_ANNOTATION_KEY: &str = "description";
/// The annotation key for shared manifests
/// The annotation key for shared applications
pub const SHARED_ANNOTATION_KEY: &str = "wasmcloud.dev/shared";
/// The identifier for the builtin spreadscaler trait type
pub const SPREADSCALER_TRAIT: &str = "spreadscaler";
Expand Down Expand Up @@ -225,11 +225,11 @@ pub enum Properties {
#[serde(deny_unknown_fields)]
pub struct ComponentProperties {
/// The image reference to use. Required unless the component is a shared component
/// that is defined in another shared manifest.
/// that is defined in another shared application.
pub image: Option<String>,
/// Information to locate a component within a shared manifest. Cannot be specified
/// Information to locate a component within a shared application. Cannot be specified
/// if the image is specified.
pub manifest: Option<SharedManifestComponentProperties>,
pub application: Option<SharedApplicationComponentProperties>,
/// The component ID to use for this component. If not supplied, it will be generated
/// as a combination of the [Metadata::name] and the image reference.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -281,11 +281,11 @@ pub struct SecretSourceProperty {
#[serde(deny_unknown_fields)]
pub struct CapabilityProperties {
/// The image reference to use. Required unless the component is a shared component
/// that is defined in another shared manifest.
/// that is defined in another shared application.
pub image: Option<String>,
/// Information to locate a component within a shared manifest. Cannot be specified
/// Information to locate a component within a shared application. Cannot be specified
/// if the image is specified.
pub manifest: Option<SharedManifestComponentProperties>,
pub application: Option<SharedApplicationComponentProperties>,
/// The component ID to use for this provider. If not supplied, it will be generated
/// as a combination of the [Metadata::name] and the image reference.
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -301,10 +301,10 @@ pub struct CapabilityProperties {
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)]
pub struct SharedManifestComponentProperties {
/// The name of the shared manifest
pub struct SharedApplicationComponentProperties {
/// The name of the shared application
pub name: String,
/// The name of the component in the shared manifest
/// The name of the component in the shared application
pub component: String,
}

Expand Down Expand Up @@ -783,7 +783,7 @@ mod test {
properties: Properties::Component {
properties: ComponentProperties {
image: Some("wasmcloud.azurecr.io/fake:1".to_string()),
manifest: None,
application: None,
id: None,
config: vec![],
secrets: vec![],
Expand All @@ -797,7 +797,7 @@ mod test {
properties: Properties::Capability {
properties: CapabilityProperties {
image: Some("wasmcloud.azurecr.io/httpserver:0.13.1".to_string()),
manifest: None,
application: None,
id: None,
config: vec![],
secrets: vec![],
Expand Down Expand Up @@ -826,7 +826,7 @@ mod test {
properties: Properties::Capability {
properties: CapabilityProperties {
image: Some("wasmcloud.azurecr.io/ledblinky:0.0.1".to_string()),
manifest: None,
application: None,
id: None,
config: vec![],
secrets: vec![],
Expand Down
16 changes: 8 additions & 8 deletions crates/wadm-types/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,15 +595,15 @@ fn validate_policies(manifest: &Manifest) -> Vec<ValidationFailure> {
/// Ensure that all components in a manifest either specify an image reference or a shared
/// component in a different manifest. Note that this does not validate that the image reference
/// is valid or that the shared component is valid, only that one of the two properties is set.
pub fn validate_component_properties(manifest: &Manifest) -> Vec<ValidationFailure> {
pub fn validate_component_properties(application: &Manifest) -> Vec<ValidationFailure> {
let mut failures = Vec::new();
for component in manifest.spec.components.iter() {
for component in application.spec.components.iter() {
match &component.properties {
Properties::Component {
properties:
ComponentProperties {
image,
manifest,
application,
config,
..
},
Expand All @@ -612,24 +612,24 @@ pub fn validate_component_properties(manifest: &Manifest) -> Vec<ValidationFailu
properties:
CapabilityProperties {
image,
manifest,
application,
config,
..
},
} => match (image, manifest) {
} => match (image, application) {
(Some(_), Some(_)) => {
failures.push(ValidationFailure::new(
ValidationFailureLevel::Error,
"Component cannot have both 'image' and 'manifest' properties".into(),
"Component cannot have both 'image' and 'application' properties".into(),
));
}
(None, None) => {
failures.push(ValidationFailure::new(
ValidationFailureLevel::Error,
"Component must have either 'image' or 'manifest' property".into(),
"Component must have either 'image' or 'application' property".into(),
));
}
// NOTE: This is a problem because of our left-folding config implementation. A shared manifest
// NOTE: This is a problem because of our left-folding config implementation. A shared application
// could specify additional config and actually overwrite the original manifest's config.
(None, Some(shared_properties)) if !config.is_empty() => {
failures.push(ValidationFailure::new(
Expand Down
Loading

0 comments on commit b64dca9

Please sign in to comment.