Skip to content

Conversation

@Supratim69
Copy link
Contributor

#461

PR enhances the auto-discovery features for Docker, Docker Swarm, and Kubernetes by allowing external hostnames to be specified using newline delimiters and by trimming whitespace around comma delimiters.

  • Adds a utility function to robustly parse host lists from labels/annotations
  • Updates Docker, Swarm, and Kubernetes watchers to use the new parser
  • Expands test coverage for all supported formats
  • Updates documentation with new examples and usage notes
  • Fully backward compatible with previous comma-separated formats

@Supratim69
Copy link
Contributor Author

@itzg please have a look

@itzg
Copy link
Owner

itzg commented Oct 23, 2025

@itzg please have a look

I already get emails for all PRs for all my repos. No need to at-mention me especially since it induces a notification.

@itzg itzg linked an issue Oct 23, 2025 that may be closed by this pull request
Copy link
Owner

@itzg itzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing this! Just a few things to tweak.

Comment on lines 65 to 69
wg, ctx := errgroup.WithContext(ctx)
wg.Go(func() error {
s.Run()
return nil
})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is unrelated. Please remove it.

library.go Outdated
Comment on lines 2 to 31

import (
"strings"
)

// SplitExternalHosts splits a string containing external hostnames by comma and/or newline delimiters.
// It trims whitespace around each hostname and filters out empty strings.
// Examples:
// - "host1.com,host2.com" -> ["host1.com", "host2.com"]
// - "host1.com, host2.com" -> ["host1.com", "host2.com"]
// - "host1.com\nhost2.com" -> ["host1.com", "host2.com"]
// - "host1.com,\nhost2.com" -> ["host1.com", "host2.com"]
func SplitExternalHosts(s string) []string {
// First, replace newlines with commas to normalize the delimiter
normalized := strings.ReplaceAll(s, "\n", ",")

// Split by comma
parts := strings.Split(normalized, ",")

// Trim whitespace and filter out empty strings
result := make([]string, 0, len(parts))
for _, part := range parts {
trimmed := strings.TrimSpace(part)
if trimmed != "" {
result = append(result, trimmed)
}
}

return result
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this into the server package. I really should have included a comment in this file to say its only a placeholder to ensure the repo can be used as a library.

library.go Outdated
Comment on lines 15 to 19
// First, replace newlines with commas to normalize the delimiter
normalized := strings.ReplaceAll(s, "\n", ",")

// Split by comma
parts := strings.Split(normalized, ",")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use https://pkg.go.dev/regexp@go1.25.3#Regexp.Split where the regex can then be ",|\n"

go.mod Outdated
Comment on lines 3 to 5
go 1.24.0

toolchain go1.24.9
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this

@Supratim69
Copy link
Contributor Author

made the requested changes. moved the SplitExternalHosts to utils file in server. Can you please merge with the hacktober tags. Thanks

Copy link
Owner

@itzg itzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super close now. Thanks.

server/utils.go Outdated
// - "host1.com,\nhost2.com" -> ["host1.com", "host2.com"]
func SplitExternalHosts(s string) []string {
// Use regexp to split on either comma or newline
re := regexp.MustCompile(",|\n")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MustCompile made me realize this would be best declared as a const. Then it can be slightly optimized.

@Supratim69
Copy link
Contributor Author

is this fine?

Copy link
Owner

@itzg itzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look great. Now I noticed the extra whitespace changes in README.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh...GitHub was keeping this file collapsed due to the large diffs. Please revert all of the whitespace changes and leave just the lines that need modifying. You might need to temporarily disable code formatting in your editor.

@Supratim69
Copy link
Contributor Author

Should be done now. Let me know if there are any other issues I can pickup and get done

Copy link
Owner

@itzg itzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing this and review fixes.

@itzg itzg merged commit 22ec39b into itzg:main Oct 24, 2025
2 checks passed
@itzg
Copy link
Owner

itzg commented Oct 24, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow newline and comma-whitespace external host lists

2 participants