Skip to content

Commit 5f46ee6

Browse files
authored
Merge pull request #795 from n2h9/chore-use-internal-external-endpoints-for-GetEndpointForPort
chore: GetEndpointForPort: check external endpoint first and then check internal
2 parents 15446a8 + 7513215 commit 5f46ee6

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

models/controllers/meshery_broker.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77

88
opClient "github.com/layer5io/meshery-operator/pkg/client"
9+
"github.com/meshery/meshkit/utils"
910
mesherykube "github.com/meshery/meshkit/utils/kubernetes"
1011
v1 "k8s.io/api/core/v1"
1112
kubeerror "k8s.io/apimachinery/pkg/api/errors"
@@ -130,14 +131,22 @@ func (mb *mesheryBroker) GetEndpointForPort(portName string) (string, error) {
130131
PortSelector: portName,
131132
})
132133
if err != nil {
133-
return "", err
134+
return "", ErrGetControllerEndpointForPort(err)
134135
}
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+
}
139145
}
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+
)
141150
}
142151

143152
func getImageVersionOfContainer(container v1.PodTemplateSpec, containerName string) string {

0 commit comments

Comments
 (0)