Expand description
Label-selector typed helpers.
K8s controllers match parents to children via label selectors:
EndpointsController: Service.spec.selector → matching PodsReplicaSetController: 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_labelsis present onresource.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.matchLabelsfrom a parent (Service /ReplicaSet/ Deployment / etc.). ReturnsNoneif 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.