Skip to main content

Module selector

Module selector 

Source
Expand description

Label-selector typed helpers.

K8s controllers match parents to children via label selectors:

  • EndpointsController: Service.spec.selector → matching Pods
  • ReplicaSetController: rs.spec.selector → matching Pods
  • Deployment: d.spec.selector → matching ReplicaSets
  • Job: job.spec.selector → matching Pods
  • NetworkPolicy: np.spec.podSelector → matching Pods

Six sites + counting — extract once, reuse forever.

Functions§

matches_labels
True iff every key/value in match_labels is present on resource.metadata.labels. Missing labels on the resource = no match. Empty selector = match nothing (K8s convention, not “match everything”; an empty selector at the API level is rejected before reaching controllers).
selector_match_labels
Extract spec.selector.matchLabels from a parent (Service / ReplicaSet / Deployment / etc.). Returns None if missing.
service_selector
Specialized helper for Service.spec.selector — at the K8s API level Service uses a flat map (no matchLabels wrapper). Falls back to the structured form for forward-compat with other kinds that may pass through here.