Skip to content

Commit

Permalink
fix usage of client port instead of monitor port
Browse files Browse the repository at this point in the history
Signed-off-by: MUzairS15 <muzair.shaikh810@gmail.com>
  • Loading branch information
MUzairS15 committed Feb 1, 2024
1 parent 05aa7f4 commit fb68d6b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
1 change: 1 addition & 0 deletions models/controllers/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ type IMesheryController interface {
Undeploy() error
GetPublicEndpoint() (string, error)
GetVersion() (string, error)
GeEndpointForPort(portName string) (string, error)
}
6 changes: 3 additions & 3 deletions models/controllers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
mesherykube "github.com/layer5io/meshkit/utils/kubernetes"
)

const BrokerPingEndpoint = "8222/connz"
const BrokerPingEndpoint = "/connz"

type Connections struct {
Connections []connection `json:"connections"`
Expand Down Expand Up @@ -88,8 +88,8 @@ func applyOperatorHelmChart(chartRepo string, client mesherykube.Client, meshery
return nil
}

func ConnectivityTest(clientName, externalIP string) bool {
endpoint, err := url.Parse("http://" + externalIP + ":" + BrokerPingEndpoint)
func ConnectivityTest(clientName, hostPort string) bool {
endpoint, err := url.Parse("http://" + hostPort + BrokerPingEndpoint)
if err != nil {
return false
}
Expand Down
29 changes: 23 additions & 6 deletions models/controllers/meshery_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

opClient "github.com/layer5io/meshery-operator/pkg/client"
"github.com/layer5io/meshkit/utils/kubernetes"
mesherykube "github.com/layer5io/meshkit/utils/kubernetes"
v1 "k8s.io/api/core/v1"
kubeerror "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -14,6 +15,9 @@ import (
"k8s.io/kubectl/pkg/polymorphichelpers"
)

var (
brokerMonitoringPortName = "monitor"
)
type mesheryBroker struct {
name string
status MesheryControllerStatus
Expand All @@ -38,13 +42,14 @@ func (mb *mesheryBroker) GetStatus() MesheryControllerStatus {
return Unknown
}
// TODO: Confirm if the presence of operator is needed to use the operator client sdk
broker, err := operatorClient.CoreV1Alpha1().Brokers("meshery").Get(context.TODO(), "meshery-broker", metav1.GetOptions{})
_, err = operatorClient.CoreV1Alpha1().Brokers("meshery").Get(context.TODO(), "meshery-broker", metav1.GetOptions{})
if err == nil {
brokerEndpoint := broker.Status.Endpoint.External
hostIP := strings.Split(brokerEndpoint, ":")[0]
if broker.Status.Endpoint.External != "" && ConnectivityTest(MesheryServer, hostIP) {
mb.status = Connected
return mb.status
monitoringEndpoint, err := mb.GeEndpointForPort(brokerMonitoringPortName)
if err == nil {
if ConnectivityTest(MesheryServer, monitoringEndpoint) {
mb.status = Connected
return mb.status
}
}
mb.status = Deployed
return mb.status
Expand Down Expand Up @@ -117,6 +122,18 @@ func (mb *mesheryBroker) GetVersion() (string, error) {
return getImageVersionOfContainer(statefulSet.Spec.Template, "nats"), nil
}

func (mb *mesheryBroker) GeEndpointForPort(portName string) (string, error) {
endpoint, err := kubernetes.GetServiceEndpoint(context.TODO(), mb.kclient.KubeClient, &mesherykube.ServiceOptions{
Name: "meshery-broker",
Namespace: "meshery",
PortSelector: portName,
})
if err != nil {
return "", err
}
return endpoint.External.String(), nil
}

func getImageVersionOfContainer(container v1.PodTemplateSpec, containerName string) string {
var version string
for _, container := range container.Spec.Containers {
Expand Down
4 changes: 4 additions & 0 deletions models/controllers/meshery_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,7 @@ func (mo *mesheryOperator) setStatus(st MesheryControllerStatus) {
defer mo.mx.Unlock()
mo.status = st
}

func (mo *mesheryOperator) GeEndpointForPort(portName string) (string, error) {
return "", nil
}
12 changes: 7 additions & 5 deletions models/controllers/meshsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package controllers

import (
"context"
"strings"

opClient "github.com/layer5io/meshery-operator/pkg/client"
mesherykube "github.com/layer5io/meshkit/utils/kubernetes"
Expand Down Expand Up @@ -50,12 +49,11 @@ func (ms *meshsync) GetStatus() MesheryControllerStatus {
case v1.PodRunning:
ms.status = Running
broker := NewMesheryBrokerHandler(ms.kclient)
brokerEndpoint, errOfEndpoint := broker.GetPublicEndpoint()
if errOfEndpoint != nil {
brokerEndpoint, err := broker.GeEndpointForPort(brokerMonitoringPortName)
if err != nil {
return ms.status
}
hostIP := strings.Split(brokerEndpoint, ":")[0]
isConnected := ConnectivityTest(MeshSync, hostIP)
isConnected := ConnectivityTest(MeshSync, brokerEndpoint)
if isConnected {
ms.status = Connected
}
Expand Down Expand Up @@ -127,3 +125,7 @@ func (ms *meshsync) GetVersion() (string, error) {

return meshsyncresource.Spec.Version, nil
}

func (mb *meshsync) GeEndpointForPort(portName string) (string, error) {
return "", nil
}
4 changes: 4 additions & 0 deletions utils/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ type HostPort struct {
Port int32
}

func (hp *HostPort) String() string {
return fmt.Sprintf("%s:%d", hp.Address, hp.Port)
}

type MockOptions struct {
DesiredEndpoint string
}
Expand Down

0 comments on commit fb68d6b

Please sign in to comment.