Skip to content

Commit

Permalink
Match all selector labels instead of only "name" (#103)
Browse files Browse the repository at this point in the history
Kubernetes pods can match a deployment by any label. The current code
assumes that there's only 1 label, and the label is always called
"name". That's not actually true, resulting in all (or no) pods being
listed when unfolding any deployment.

This commit applies all `matchLabels` in a deployment to all pods,
getting a more accurate list of which pods belong to which deployment.
  • Loading branch information
jypma authored and chrisbarrett committed Aug 13, 2019
1 parent 95d5c93 commit e0eff36
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions kubernetes-overview.el
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,16 @@
;; Pods

(defun kubernetes-overview--pods-for-deployment (state deployment)
(-let* (((&alist 'spec (&alist 'selector (&alist 'matchLabels (&alist 'name selector-name)))) deployment)
(-let* (((&alist 'spec (&alist 'selector (&alist 'matchLabels selectors))) deployment)
((&alist 'items pods) (kubernetes-state-pods state))
(pods (append pods nil)))
(nreverse (seq-reduce
(lambda (acc pod)
(if (equal selector-name (kubernetes-state-resource-label pod))
(cons pod acc)
acc))
(-let [(&alist 'metadata (&alist 'labels labels)) pod]
;; The labels present on the pod must contain all selector labels
(if (-all? (lambda (label) (-contains? labels label)) selectors)
(cons pod acc)
acc)))
pods
nil))))

Expand Down

0 comments on commit e0eff36

Please sign in to comment.