Skip to content

Conditional annotations inside list comprehensions - unclear if this is expected behavior #313

@Smana

Description

@Smana

When using conditional logic to add annotations inside KCL list comprehensions, the syntax if condition: annotation inside an annotations block doesn't work, but moving the
condition outside the annotations block does work. I'm not sure if this is the expected behavior.

Environment

  • Crossplane function-kcl version: v0.11.2
  • KCL version: v0.11.3
  • Crossplane version: v2.0

Current Behavior

This doesn't work - annotation is not added:

_items += [{
    metadata = {
        annotations = {
            if some_condition:
                "krm.kcl.dev/ready": "True"
        }
    }
} for item in items]

Working Alternative

This works - annotation is added:

  _items += [{
      metadata = {
          annotations = {
              "krm.kcl.dev/ready": "True"
          } if some_condition else {}
      }
  } for item in items]

Questions

  1. Is this the expected behavior for conditional expressions inside dictionary literals within list comprehensions?
  2. Should both syntaxes work the same way, or is the second approach the preferred/correct one?
  3. Is there documentation about the recommended syntax for conditional annotations?

Additional Notes

  • Static annotations work fine in list comprehensions
  • The conditional logic evaluates correctly - only the annotation assignment differs
  • This occurs specifically in list comprehensions; regular conditional blocks work as expected

Any clarification on the expected behavior would be helpful!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions