Skip to content

Controller selectors should be immutable after creation #50808

@crimsonfaith91

Description

@crimsonfaith91

Background
As part of the greater controller GA effort, we have removed defaulting spec.selector to spec.template.labels values in apps/v1beta2 as the defaulting operation is semantically broken. In this issue, we propose to make spec.selector immutable after API object creation.

Motivation

  1. Changing selectors leads to undefined behaviors - users are not expected to change the selectors
  2. Having selectors immutable ensures they always match created children, preventing events such as accidental bulk orphaning
  3. Having selectors mutable for GA is an immortal decision, which does not guarantee API backward compatibility

Immutability resolves some challenging issues that plague many teams for over a year e.g., #34292, and the current behavior for controllers with respect to selector mutations is undefined e.g., #26202.

In contrast, by making selectors immutable, validation ensures the selectors always match template labels of created children. This provides a risk-free, deterministic behavior to resolve the issue, and meet the general goal of declarative configuration.

We could lift the immutability in future after all controller types have well-defined behaviors (i.e., after GA). This provides ability to address new use cases while maintaining API backward compatibility. However, if we do not make selectors immutable prior to GA, we will have to live with mutable selectors for the lifetime of the v1 API and the controllers’ undefined behaviors until reasonable semantics are decided and implemented.

/kind bug
/sig apps
/sig api-machinery
@bgrant0607 @erictune @kow3ns @enisoc @janetkuo @foxish @liyinan926
@liggitt @smarterclayton @Kargakis @mikedanese

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.sig/api-machineryCategorizes an issue or PR as relevant to SIG API Machinery.sig/appsCategorizes an issue or PR as relevant to SIG Apps.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions