Skip to content

Commit

Permalink
Implement function to get the ports from a service
Browse files Browse the repository at this point in the history
Contributes to #240.
  • Loading branch information
jinnovation committed Sep 22, 2024
1 parent e9d5e8f commit c54ef1e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions kele.el
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,26 @@ PORTS is used according to `completion-extra-properties'."
'face 'completions-annotations))))
ports))

(cl-defun kele--service-ports (obj &key (protocol nil))
"Get the exposed ports for service OBJ.
If PROTOCOL is provided, filter for only ports of that protocol.
OBJ is assumed to be a `kele--resource-container'."
(let-alist (oref obj resource)
(let ((ports .spec.ports))
(if protocol
(-filter (lambda (port-spec)
(equal
(alist-get 'protocol port-spec)
protocol))
ports)
ports))))

(kele--service-ports
(kele--get-resource (kele--gvk-create :version "v1" :kind "services")
"job-online-photo-score-rest"))

(defun kele--port-forwards-active-p ()
"Return non-nil if there are any port-forwards active."
(< 0 (length (mapcar 'car kele--active-port-forwards))))
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test-kele.el
Original file line number Diff line number Diff line change
Expand Up @@ -720,4 +720,15 @@ metadata:
(kele-list-kill)
(expect 'vtable-revert-command :to-have-been-called))))

(describe "`kele--service-ports'"
(it "retrieves the port specs"
(expect
(kele--service-ports
(kele--resource-container-create
:resource '((spec . ((ports . [((name . "foo")
(protocol . "TCP")
(port . 8081))]))))))
:to-equal
[((name . "foo") (protocol . "TCP") (port . 8081))])))

;;; test-kele.el ends here

0 comments on commit c54ef1e

Please sign in to comment.