Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
Signed-off-by: MUzairS15 <[email protected]>
  • Loading branch information
MUzairS15 committed Sep 30, 2022
1 parent 3b88f29 commit a7f6555
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
6 changes: 6 additions & 0 deletions models/controllers/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ const (
Unknown
)

const (
MeshSync = "meshsync"
MesheryBroker = "meshery-broker"
MesheryServer = "meshery-server"
)

func (mcs MesheryControllerStatus) String() string {
switch mcs {
case Deployed:
Expand Down
14 changes: 8 additions & 6 deletions models/controllers/meshery_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ func (mb *mesheryBroker) GetStatus() MesheryControllerStatus {
// 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{})
if err == nil {
if broker.Status.Endpoint.External != "" {
mb.status = Deployed
brokerEndpoint := broker.Status.Endpoint.External
hostIP := strings.Split(brokerEndpoint, ":")[0]
if broker.Status.Endpoint.External != "" && ConnectivityTest(MesheryServer, hostIP) {
mb.status = Connected
return mb.status
}
mb.status = Undeployed
mb.status = Deployed
return mb.status
} else {
if kubeerror.IsNotFound(err) {
Expand All @@ -56,7 +58,7 @@ func (mb *mesheryBroker) GetStatus() MesheryControllerStatus {
return mb.status
}
// when operatorClient is not able to get meshesry-broker, we try again with kubernetes client as a fallback
broker, err := mb.kclient.DynamicKubeClient.Resource(schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "statefulsets"}).Namespace("meshery").Get(context.TODO(), "meshery-broker", metav1.GetOptions{})
broker, err := mb.kclient.DynamicKubeClient.Resource(schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "statefulsets"}).Namespace("meshery").Get(context.TODO(), MesheryBroker, metav1.GetOptions{})
if err != nil {
// if the resource is not found, then it is NotDeployed
if kubeerror.IsNotFound(err) {
Expand Down Expand Up @@ -97,7 +99,7 @@ func (mb *mesheryBroker) GetPublicEndpoint() (string, error) {
if err != nil {
return "", ErrGetControllerPublicEndpoint(err)
}
broker, err := operatorClient.CoreV1Alpha1().Brokers("meshery").Get(context.TODO(), "meshery-broker", metav1.GetOptions{})
broker, err := operatorClient.CoreV1Alpha1().Brokers("meshery").Get(context.TODO(), MesheryBroker, metav1.GetOptions{})
if broker.Status.Endpoint.External == "" {
if err == nil {
err = fmt.Errorf("Could not get the External endpoint for meshery-broker")
Expand All @@ -111,7 +113,7 @@ func (mb *mesheryBroker) GetPublicEndpoint() (string, error) {

func (mb *mesheryBroker) GetVersion() (string, error) {
if len(mb.version) == 0 {
statefulSet, err := mb.kclient.KubeClient.AppsV1().StatefulSets("meshery").Get(context.TODO(), "meshery-broker", metav1.GetOptions{})
statefulSet, err := mb.kclient.KubeClient.AppsV1().StatefulSets("meshery").Get(context.TODO(), MesheryBroker, metav1.GetOptions{})
if kubeerror.IsNotFound(err) {
return "", err
}
Expand Down
11 changes: 11 additions & 0 deletions models/controllers/meshsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controllers

import (
"context"
"strings"

// opClient "github.com/layer5io/meshery-operator/pkg/client"
opClient "github.com/layer5io/meshery-operator/pkg/client"
Expand Down Expand Up @@ -47,6 +48,16 @@ func (ms *meshsync) GetStatus() MesheryControllerStatus {
switch meshSyncPod.Items[0].Status.Phase {
case v1.PodRunning:
ms.status = Running
broker := NewMesheryBrokerHandler(ms.kclient)
brokerEndpoint, err := broker.GetPublicEndpoint()
if err != nil {
return ms.status
}
hostIP := strings.Split(brokerEndpoint, ":")[0]
isConnected := ConnectivityTest(MeshSync, hostIP)
if isConnected {
ms.status = Connected
}
return ms.status
default:
ms.status = Deployed
Expand Down

0 comments on commit a7f6555

Please sign in to comment.