Skip to content

Commit

Permalink
only check configs that declare properties for unique names. Signed-o…
Browse files Browse the repository at this point in the history
…ff-by: Author Name <[email protected]>
  • Loading branch information
StuartHarris committed Feb 7, 2025
1 parent ffc655e commit 6aa6c7c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
19 changes: 14 additions & 5 deletions crates/wadm-types/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,16 +697,21 @@ pub fn validate_component_properties(application: &Manifest) -> Vec<ValidationFa
/// Validates link configs in a WADM application manifest.
///
/// At present this can check for:
/// - all config names are unique
/// - all configs that declare `properties` have unique names
/// (configs without properties refer to existing configs)
///
pub fn validate_link_configs(manifest: &Manifest) -> Vec<ValidationFailure> {
let mut failures = Vec::new();
let mut link_config_names = HashSet::new();
for link_trait in manifest.links() {
if let TraitProperty::Link(LinkProperty { target, source, .. }) = &link_trait.properties {
for config in target.config.iter() {
for config in &target.config {
// we only need to check for uniqueness of configs with properties
if config.properties.is_none() {
continue;
}
// Check if config name is unique
if !link_config_names.insert((config.name.clone(),)) {
if !link_config_names.insert(config.name.clone()) {
failures.push(ValidationFailure::new(
ValidationFailureLevel::Error,
format!("Duplicate link config name found: '{}'", config.name),
Expand All @@ -715,9 +720,13 @@ pub fn validate_link_configs(manifest: &Manifest) -> Vec<ValidationFailure> {
}

if let Some(source) = source {
for config in source.config.iter() {
for config in &source.config {
// we only need to check for uniqueness of configs with properties
if config.properties.is_none() {
continue;
}
// Check if config name is unique
if !link_config_names.insert((config.name.clone(),)) {
if !link_config_names.insert(config.name.clone()) {
failures.push(ValidationFailure::new(
ValidationFailureLevel::Error,
format!("Duplicate link config name found: '{}'", config.name),
Expand Down
18 changes: 18 additions & 0 deletions tests/fixtures/manifests/duplicate_link_config_names.wadm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ spec:
name: kvredis
config:
- name: redis-url
properties:
url: "redis://127.0.0.1:6379"
# this config name is duplicated, but has no properties,
# so it references an existing config
- name: my_example_app-shared_redis

- name: userinfo2
type: component
Expand All @@ -35,6 +40,11 @@ spec:
name: kvredis
config:
- name: redis-url
properties:
url: "redis://127.0.0.1:6379"
# this config name is duplicated, but has no properties,
# so it references an existing config
- name: my_example_app-shared_redis

- name: webcap1
type: capability
Expand All @@ -52,8 +62,14 @@ spec:
source:
config:
- name: default-port
properties:
port: 0.0.0.0:8080
- name: alternate-port
properties:
address: 0.0.0.0:8081
- name: alternate-port
properties:
address: 0.0.0.0:8081

- name: webcap2
type: capability
Expand All @@ -71,6 +87,8 @@ spec:
source:
config:
- name: default-port
properties:
address: 0.0.0.0:8080

- name: kvredis
type: capability
Expand Down

0 comments on commit 6aa6c7c

Please sign in to comment.