-
Notifications
You must be signed in to change notification settings - Fork 612
add groupByLabel function #165
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
Conversation
func groupByLabel(entries interface{}, label string) (map[string][]interface{}, error) { | ||
getLabel := func(v interface{}) (interface{}, error) { | ||
if container, ok := v.(RuntimeContainer); ok { | ||
if container.Labels[label] == "" { |
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 break if the label actually has a blank value. You may want to check the second return value from container.Labels[label]
to see if it is false
instead of checking for ""
. I did this in the whereLabel
function.
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.
Ah you are right, I misread groupBy
as excluding the container if the value is blank, so I went this route for consistency, but it only excludes if the value is nil. I'll change it.
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.
Done
I built something specific for grouping by the service name of the docker compose file: but this pull would make mine obsolete and make it more generic my vote for this one! ;) |
I tried to use groubByLabel like
but I always get
|
@tompson I've successfully used the new function with a binary built by running |
did exactly that, checked multiple times that I got the right binary do you have an example template file? |
You probably don't have this PR applied locally then. A simple example template would be:
|
wow, that was hard to track down, problem was that in
caused that make did not build |
Ah dang, that's a pain yeah. Glad you got it sorted out. |
@tompson When I work on this project I add an additional Git remote to my checkout of |
Thanks @codekitchen! |
This is convenient, but also necessary since the
$fieldPath
parameter togroupBy
can't contain dots in map key names, and labels are typically reverse-domain-name prefixed.