Skip to content

[Rule] Detect duplicate label keys #313

@mschoettle

Description

@mschoettle

Rule Description

  • Category: best-practice?
  • Severity: error
  • Fixable: no

Problematic Code Example

Provide an example of code that would trigger this rule.

services:
  app:
    [...]
    labels:
      - "service.foo=bar"
      - "service.foo=baz"

Correct Code Example

Provide an example of the code that would pass the rule.

services:
  app:
    [...]
    labels:
      - "service.foo=bar"
      - "service.bar=baz"

Rule Details

Explain the rule in detail and why it should be added:

It can happen that one accidentally creates a label where the key of the label already exists. What seems to happen when this is run that the last label value wins. It is often hard to detect manually and requires troubleshooting.

An example where this just happened to us is using Ofelia to define jobs. It also has happened to me with traefik labels before.

Where it might not be appropriate: It might be possible that someone wants to deliberately overwrite a label to use a different value (e.g., when using multiple compose files that get merged).

Supported Options

n/a

References

n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions