in pkg/gcp/gcp-kubeconfig.go [369:424]
func findCluster(kr *k8s.K8S, cll []*Cluster, myRegion string, cl *Cluster) *Cluster {
if kr.Mesh.ClusterName != "" {
for _, c := range cll {
if myRegion != "" && !strings.HasPrefix(c.ClusterLocation, myRegion) {
continue
}
if c.ClusterName == kr.Mesh.ClusterName {
cl = c
break
}
}
if cl == nil {
for _, c := range cll {
if c.ClusterName == kr.Mesh.ClusterName {
cl = c
break
}
}
}
}
// First attempt to find a cluster in same region, with the name prefix istio (TODO: label or other way to identify
// preferred config clusters)
if cl == nil {
for _, c := range cll {
if myRegion != "" && !strings.HasPrefix(c.ClusterLocation, myRegion) {
continue
}
if strings.HasPrefix(c.ClusterName, "istio") {
cl = c
break
}
}
}
if cl == nil {
for _, c := range cll {
if myRegion != "" && !strings.HasPrefix(c.ClusterLocation, myRegion) {
continue
}
cl = c
break
}
}
if cl == nil {
for _, c := range cll {
if strings.HasPrefix(c.ClusterName, "istio") {
cl = c
}
}
}
// Nothing in same region, pick the first
if cl == nil {
cl = cll[0]
}
return cl
}