Skip to content

[BUG] mismatching-selector registers ReplicationController but appears to skip it #1188

Description

@GeneCodeSavvy

System info:

  • OS: macOS

Describe the bug

The mismatching-selector check appears to advertise ReplicationController support through its DeploymentLike scope, but ReplicationController objects are skipped during selector extraction.

DeploymentLike includes ReplicationController, but mismatching-selector calls extract.Selector(object.K8sObject). For ReplicationController, spec.selector is a plain map[string]string, while extract.Selector only handles special-cased DeploymentConfig / CronJob selectors or reflected Spec.Selector fields typed as *metav1.LabelSelector.

As a result, a ReplicationController with mismatched spec.selector and pod template labels is not reported.

To Reproduce

Steps to reproduce the behavior:

  1. Save the sample YAML below as rc-mismatching-selector.yaml.
  2. Run:
    kube-linter lint --include mismatching-selector --do-not-auto-add-defaults rc-mismatching-selector.yaml
  3. Observe that no mismatching-selector finding is reported for the ReplicationController.

Sample YAML input

apiVersion: v1
kind: ReplicationController
metadata:
  name: rc-selector-mismatch
spec:
  selector:
    app: api
    tier: backend
  template:
    metadata:
      labels:
        app: api
        tier: frontend
    spec:
      containers:
      - name: app
        image: nginx

Expected behavior

The mismatching-selector check should report that the ReplicationController selector does not match the pod template labels.

Either ReplicationController should be removed from the effective DeploymentLike scope for this check, or extract.Selector should convert ReplicationController.spec.selector into a metav1.LabelSelector{MatchLabels: ...} similar to how DeploymentConfig is handled.

Screenshots

Not applicable.

Additional context

The check is registered with scope.objectKinds: DeploymentLike, and DeploymentLike includes ReplicationController.

The issue seems to come from selector extraction rather than object-kind matching: extract.Selector does not currently handle selector maps from ReplicationController.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    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