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

Only check configs for unique names if they declare properties #585

Merged
Merged
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
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
Loading