Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kele-list: show owner references in column #211

Merged
merged 8 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified docs/how-tos/img/kele-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/kele-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ with Kele.

![](./img/demo.gif)
![](./img/menu-bar.png)
![](./img/kele-list.png)
![](./img/doom-modeline.png)

!!! tip
Expand Down
1 change: 1 addition & 0 deletions docs/references/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ versioning][semver].
- Added variable for selecting which YAML major mode function to use for YAML
highlighting in resource buffers
- Added output to `kele-list` buffers indicating the context
- Added additional columns to `kele-list` output, e.g. owner references
- Added binding `g` for refreshing a `kele-list` buffer

### Fixed
Expand Down
51 changes: 31 additions & 20 deletions kele.el
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,13 @@ show the requested Kubernetes object manifest.
"Concatenate GROUP and VERSION into single group-version string."
(if group (concat group "/" version) version))

(defun kele--gvk-string (group version kind)
"Construct GVK string from GROUP, VERSION, and KIND."
(let ((vk (format "%s.%s" version kind)))
(if group
(concat group "/" vk)
vk)))

(defun kele--groupversion-split (group-version)
"Split a single GROUP-VERSION string.

Expand Down Expand Up @@ -1597,6 +1604,12 @@ prompting and the function simply returns the single option."
gvs)))))

(defun kele--make-list-vtable (group-version kind context namespace)
"Construct an interactive vtable listing resources of KIND.

GROUP-VERSION, CONTEXT, and NAMESPACE are according to Kubernetes
conventions and serve to further specify the resources to list.

KIND is expectod to be the plural form."
(-let (((group version) (kele--groupversion-split group-version)))
(make-vtable
:insert nil
Expand All @@ -1610,37 +1623,35 @@ prompting and the function simply returns the single option."
(alist-get 'items resource-list)))
:columns '((:name "Name" :width 30 :align left :primary ascend)
(:name "Namespace" :width 20 :align left)
(:name "Group" :width 10 :align left)
(:name "Version" :width 10 :align left)
(:name "Kind" :width 10 :align left)
(:name "GVK" :width 10 :align left)
(:name "Owner(s)" :width 20 :align left)
(:name "Created" :width 30 :align left))
;; FIXME: Bind `g' to refresh the table **anywhere** the cursor is on the
;; buffer, not just when hovering over the table itself
:actions
`("RET" (lambda (object)
(-let* (((&alist 'metadata (&alist 'name name)) object))
(kele-get ,context ,namespace ,group-version ,kind name)))
(let-alist object
(kele-get ,context ,namespace ,group-version ,kind .metadata.name)))
"k" (lambda (object)
(-let* (((&alist 'metadata (&alist 'name name)) object))
(kele-delete ,context ,namespace ,group-version ,kind name)
(let-alist object
(kele-delete ,context ,namespace ,group-version ,kind .metadata.name)
(vtable-revert-command))))
:getter (lambda (object column vtable)
(-let* (((&alist 'metadata
(&alist
'name name
'namespace namespace
'creationTimestamp created-time))
object))
(let-alist object
(pcase (vtable-column vtable column)
("Name" name)
("Name" .metadata.name)
("Namespace"
(or namespace
(or .metadata.namespace
(propertize "N/A" 'face 'kele-disabled-face)))
("Group"
(or group (propertize "N/A" 'face 'kele-disabled-face)))
("Version" version)
("Kind" kind)
("Created" created-time)))))))
("GVK" (kele--gvk-string group version kind))
("Owner(s)"
(if (not .metadata.ownerReferences)
(propertize "N/A" 'face 'kele-disabled-face)
(if (> (length .metadata.ownerReferences) 1)
"Multiple"
(let-alist (elt .metadata.ownerReferences 0)
(format "%s/%s" .kind .name)))))
("Created" .metadata.creationTimestamp)))))))

(defvar kele-list-mode-map
(let ((map (make-sparse-keymap)))
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test-kele.el
Original file line number Diff line number Diff line change
Expand Up @@ -668,4 +668,10 @@ metadata:
(kele--get-groupversion-arg)
(expect 'completing-read :to-have-been-called))))

(describe "kele--gvk-string"
(it "formats w/o group"
(expect (kele--gvk-string nil "v1" "Pod") :to-equal "v1.Pod"))
(it "formats w/ group"
(expect (kele--gvk-string "group" "v1" "Pod") :to-equal "group/v1.Pod")))

;;; test-kele.el ends here
Loading