Skip to content

Configurable metadata: requiredLabels, requiredAnnotations, extraLabels and extraAnnotations #215

Closed

Description

@ephico2real2

The owner's decision (2026-11-14)

"in the payload we need fields to be required for metadata for labels and annotations ... configure this compulsory but parameterizable ... requiredAnnotations (stanza) and requiredLabels (stanza as well) - we want to be able to configure the required keys so that the requester needs to set them - and also have flexibility to configure extraAnnotations and extraLabels - so that they can set additional labels or annotations if they want."

The owner's sample of a company's namespace today (company.net stands for any company's domain):

kind: Namespace
apiVersion: v1
metadata:
  name: abc-rnd                     # every namespace starts with the team's mnemonic
  labels:
    name: abc-rnd                       # required: a copy of the namespace name
    company.net/app-environment: rnd    # required
    company.net/mnemonic: abc           # required
    company.net/lob: amgsst             # required: line of business
    company.net/cl: '1'                 # required: critical level
    company.net/provisioner: cluster-configs   # written by the old way of provisioning; useful for adoption
    company.net/mnemonic-group-contact: ''     # optional
    company.net/mnemonic-confluence: ''        # optional
  annotations:
    company.net/app-environment: rnd    # required

Today

metadata-keys.yaml (deploy/helm/cmapi/config/, examples/cluster-configs/policies/) has governed keys (each with kind, required, pattern or format), team keys (free extra keys with allowed prefixes and limits), system keys that cmapi writes, reservedPrefixes, sensitiveKeys and emailDomains. It cannot say: a value that cmapi derives (the namespace name, the environment), a list of allowed values, a key that must match the namespace name's prefix, or a key recognised only at adoption.

What to build

  1. Four stanzas in the configuration (per instance, in the Helm values and metadata-keys.yaml), replacing governed and team with no change of behaviour for the keys that exist:
    requiredLabels:
      name:                        { value: { from: namespace } }      # cmapi sets it; the requester does not
      company.net/app-environment: { value: { from: environment } }
      company.net/mnemonic:        { pattern: "^[a-z]{3}$", namespacePrefix: true }   # abc-rnd must start with "abc-"
      company.net/lob:             { enum: [amgsst] }                  # or a pattern
      company.net/cl:              { enum: ["0", "1", "2", "3"] }
    requiredAnnotations:
      company.net/app-environment: { value: { from: environment } }
    extraLabels:
      keys:
        company.net/mnemonic-group-contact: { format: email-in-domains }
        company.net/mnemonic-confluence:    { format: url }
      allowOther: { prefixes: ["", "*.company.net/"], max: 50 }       # any other key, within the limits
    extraAnnotations:
      keys: {}
      allowOther: { prefixes: ["", "*.company.net/"], max: 50, maxValueBytes: 4096, maxBytesTotal: 65536 }
    adoptionLabels:
      company.net/provisioner: { recognise: [cluster-configs] }       # read when an old namespace is adopted
    Each key takes one of: value.from (derived by cmapi: namespace, environment, cluster, team, ...), pattern, enum, format (email-in-domains, url, ...), and optional namespacePrefix, description and example (for the API document and the portal form).
  2. The request. A derived key is never sent by the requester (sending it is refused, or ignored with a warning: decide and record). A required key that the requester must give and that is missing, empty or invalid refuses the plan with one problem that lists each key and its rule. Extra keys are accepted within the configured keys and limits. The plan and the dry run show the final labels and annotations.
  3. One source for every check: the same stanzas feed cmapi's plan-time validation, the Kyverno policies of Kyverno policies generated from cmapi's configuration, with approved per-namespace overrides #212 (and their messages, filled from the same values), the OpenAPI description and examples of labels and annotations, and the portal's New namespace form (required fields first, extra fields after).
  4. Changing a required key is a reviewed configuration change. Existing namespaces that miss a new required key show as non-compliant (a finding on the namespace and on the Policies tab); the fix is an update request, not an automatic change.
  5. Adoption: adoptionLabels lets cmapi recognise namespaces that the old way provisioned, for the adoption work of story [Draft] OBI-39: Adoption, policy visibility and recoverable operations #26.
  6. Keep system, reservedPrefixes, sensitiveKeys and emailDomains as they are; a required or extra key must not use a reserved or system key, and the loader refuses a configuration that does.

Proof

Tests that fail before and pass after: each rule (missing required key, bad enum, pattern, namespace prefix, derived key sent by the requester, an extra key outside the allowed prefixes or over the limit); the owner's sample namespace renders exactly; the loader refuses a bad configuration; the portal form shows the configured keys. docs/02 (live and export), docs/04 regenerated, the contract gate, the service suite and GitHub's checks green on the exact head.

Activity

  1. added
    feature
    status:open
    Backlog
    on Nov 14, 2026
  2. ephico2real2 commented on Nov 14, 2026

    @ephico2real2
    OwnerAuthor

    Owner decisions, 2026-11-14:

    1. Keep both keys; they are different things. cmapi.net/env is cmapi's own system key: the environment of the namespace's cluster, which matches the instance that manages it; approval rules, Kyverno and the instance boundary (422 environment-not-served) use it. company.net/app-environment is the company's label, filled as in the owner's sample. Do not merge them and do not make cmapi read the company key. In this issue, company.net/app-environment stays derived from the cluster's environment (value.from: environment), so a requester cannot set a value that disagrees, unless the owner says requesters type it.

    2. Two instances, not three. The owner: "nonprod (dev, rnd, uat and qa) and another instance (prod) will be deployed to manage prod (production clusters)". The design and examples today have three: nonprod (rnd, dev), staging (qa, uat), prod (prod) (examples/instances/, docs/01, docs/02, and the OpenAPI description "The nonprod instance serves [dev, rnd]"). Change the example instance files, the docs (live and export) and every place that names the instances to the owner's two; it is configuration, so no code change is expected, but check the code and tests for any assumption of a staging instance.

  3. ephico2real2 commented on Nov 14, 2026

    @ephico2real2
    OwnerAuthor

    Correction by the owner, 2026-11-14 (replaces item 2 of my previous comment): keep the three cmapi deployments (instances) of the design: nonprod (rnd, dev), staging (qa, uat), prod (prod). The owner: "I like the fact that we have 3 cmapi deployments". Do not change the instance files, docs or OpenAPI description to two. Item 1 (keep both cmapi.net/env and company.net/app-environment) stands. #222 (email links hard-code #nonprod) still applies, since the staging and prod instances send emails too.

  4. added 2 commits that reference this issue on Nov 14, 2026
  5. ephico2real2 commented on Nov 14, 2026

    @ephico2real2
    OwnerAuthor

    Owner decision, 2026-11-14 (after Fable's review of PR #234): company.net/mnemonic-group-contact and company.net/mnemonic-confluence move to annotations: optional keys of extraAnnotations, with format: email-in-domains and format: url. A label value cannot hold @, :// or / (at most 63 characters of letters, digits, dot, dash and underscore), so they cannot be labels with those formats. Existing namespaces that carry them as labels keep those labels at adoption (raw as-is), each reported as a finding (#26).

  6. added 4 commits that reference this issue on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Backlogfeaturestatus:open

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions