|
6 | 6 | "strings" |
7 | 7 |
|
8 | 8 | opClient "github.com/layer5io/meshery-operator/pkg/client" |
| 9 | + "github.com/meshery/meshkit/utils" |
9 | 10 | mesherykube "github.com/meshery/meshkit/utils/kubernetes" |
10 | 11 | v1 "k8s.io/api/core/v1" |
11 | 12 | kubeerror "k8s.io/apimachinery/pkg/api/errors" |
@@ -130,14 +131,22 @@ func (mb *mesheryBroker) GetEndpointForPort(portName string) (string, error) { |
130 | 131 | PortSelector: portName, |
131 | 132 | }) |
132 | 133 | if err != nil { |
133 | | - return "", err |
| 134 | + return "", ErrGetControllerEndpointForPort(err) |
134 | 135 | } |
135 | | - if endpoint.Internal == nil || endpoint.Internal.Address == "" { |
136 | | - return "", ErrGetControllerEndpointForPort( |
137 | | - fmt.Errorf("internal endpoint for meshery-broker is not available"), |
138 | | - ) |
| 136 | + |
| 137 | + // Try endpoints in order of preference: external first, then internal |
| 138 | + endpoints := []*utils.HostPort{endpoint.External, endpoint.Internal} |
| 139 | + for _, ep := range endpoints { |
| 140 | + if ep != nil && ep.Address != "" { |
| 141 | + if utils.TcpCheck(ep, nil) { |
| 142 | + return ep.String(), nil |
| 143 | + } |
| 144 | + } |
139 | 145 | } |
140 | | - return endpoint.Internal.String(), nil |
| 146 | + |
| 147 | + return "", ErrGetControllerEndpointForPort( |
| 148 | + fmt.Errorf("neither external not internal endpoint is reachable for meshery-broker port %s", portName), |
| 149 | + ) |
141 | 150 | } |
142 | 151 |
|
143 | 152 | func getImageVersionOfContainer(container v1.PodTemplateSpec, containerName string) string { |
|
0 commit comments