diff --git a/plugin/kubernetes/autopath.go b/plugin/kubernetes/autopath.go index f20f03c7c..af6502c7f 100644 --- a/plugin/kubernetes/autopath.go +++ b/plugin/kubernetes/autopath.go @@ -33,16 +33,21 @@ func (k *Kubernetes) AutoPath(state request.Request) []string { return nil } - totalSize := 3 + len(k.autoPathSearch) + 1 // +1 for sentinel - search := make([]string, 0, totalSize) + totalSize := 4 + len(k.autoPathSearch) + search := make([]string, totalSize) if zone == "." { - search = append(search, pod.Namespace+".svc.", "svc.", ".") + search[0] = pod.Namespace + ".svc." + search[1] = "svc." + search[2] = "." } else { - search = append(search, pod.Namespace+".svc."+zone, "svc."+zone, zone) + svcZone := "svc." + zone + search[0] = pod.Namespace + "." + svcZone + search[1] = svcZone + search[2] = zone } - search = append(search, k.autoPathSearch...) - search = append(search, "") // sentinel + copy(search[3:], k.autoPathSearch) + search[totalSize-1] = "" // sentinel return search }