-
Notifications
You must be signed in to change notification settings - Fork 137
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
Expose custom funcs to template #638
Conversation
f8f1f8d
to
779bda5
Compare
Codecov Report
@@ Coverage Diff @@
## main #638 +/- ##
==========================================
+ Coverage 44.95% 45.07% +0.12%
==========================================
Files 61 62 +1
Lines 3546 3554 +8
==========================================
+ Hits 1594 1602 +8
Misses 1870 1870
Partials 82 82
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Additional helper functions have proven useful to consumers when rendering templates with hardware data. The concrete use-case is formatting of partitions where nvme uses a different format to the historical block device. Signed-off-by: Chris Doherty <[email protected]>
779bda5
to
d889e78
Compare
In this PR and in added documentation, specifying that the device partition format is the Linux kernel format may avoid some confusion. |
@displague Good call out. Are you thinking in the function comment (and the docs site when it goes up)? If there's somewhere else in this repository we need it could you fire me a link, thanks. |
// Examples | ||
// formatPartition("/dev/nvme0n1", 0) -> /dev/nvme0n1p1 | ||
// formatPartition("/dev/sda", 1) -> /dev/sda1 | ||
func formatPartition(dev string, partition int) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we OK with this name? I originally had formatDevicePartition
, and @displague called out the formatting produced is specific to Linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be very helpful in future workflows - no doubt we will want to build on this with other internal helper functions (for other string comparisons or modifications) and also for metadata mining.
I could see use in having a helper that chooses the most appropriate disk based on some heuristics, or one that returns the appropriate NIC or bonding device names.
I found the existing template operators helpful when reviewing this https://pkg.go.dev/text/template#pkg-overview (I wanted to make sure we weren't duplicating functionality with the string comparators).
I'm a maintainer of several other services often related to the Kuberenetes back-end/Kubernetes controllers and I'm taking ownership for a lot of release synchronization making it both appropriate and necessary for me to maintain aspects of the Tink repository. Requirements: - I have reviewed the [community membership guidelines](https://github.com/tinkerbell/proposals/blob/main/proposals/0024/GOVERNANCE.md) - I have [enabled 2FA on my GitHub account](https://github.com/settings/security) - I have subscribed to the [tinkerbell-contributors e-mail list](https://groups.google.com/g/tinkerbell-contributors) - I am actively contributing to 1 or more Tinkerbell subprojects Here is a list of non-trival PRs I have been the primary reviewer on: #596 #628 #614 I have also made a number of code contributions to this repository, here are a few of them: #638 #631 #626 #622 #612 I have also raised various issues and am driving the releasing across Tinkerbell including in this repository. Requesting consideration of expedited responsibilities: yes Sponsors: - @mmlb (Maintainer) - @micahhausler (Maintainer) - @jacobweinstock (Core contributor in other Tinkerbell repositories)
Having exposed a subset of hardware data to templates there's a need to provide some helper functions for manipulating the data. The concrete use case is formatting of disk partitions.
This PR introduces
formatPartition
to templates accepting the device path. The function currently supports historic block devices (/dev/sd<char>
) and NVMe drives. Additionally it addsstrings.Contains
,strings.HasPrefix
andstrings.HasSuffix
which have proven useful.Example template snippet
Documentation will need adding to the docs website in the on-going documentation effort.