Skip to content

Commit

Permalink
endpoints: check for path prefix with strings.HasPrefix (#182)
Browse files Browse the repository at this point in the history
Previously, path[0] was used which caused a panic for empty labels
This will _allow_ the use of an empty label value, which will be translated to "/"
  • Loading branch information
roobre committed May 28, 2021
1 parent 3a8cceb commit 1130a92
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions internal/pkg/endpoints/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,20 +286,20 @@ func getPortList(e *apiv1.Endpoints, s *apiv1.Service) []string {

func getPath(o metav1.Object) string {
var path string
var ok bool

// Annotations take precedence over labels.
if _, ok = o.GetAnnotations()[defaultScrapePathLabel]; ok {
path, _ = o.GetAnnotations()[defaultScrapePathLabel]
} else if path, ok = o.GetLabels()[defaultScrapePathLabel]; ok {
path, _ = o.GetLabels()[defaultScrapePathLabel]
if annotation, ok := o.GetAnnotations()[defaultScrapePathLabel]; ok {
path = annotation
} else if label, ok := o.GetLabels()[defaultScrapePathLabel]; ok {
path = label
} else {
path = defaultScrapePath
}

if path[0] != '/' {
if !strings.HasPrefix(path, "/") {
path = "/" + path
}

return path
}

Expand Down

0 comments on commit 1130a92

Please sign in to comment.