Skip to content

Commit

Permalink
implement GetVersion func for controllers
Browse files Browse the repository at this point in the history
Signed-off-by: MUzairS15 <[email protected]>
  • Loading branch information
MUzairS15 committed Jan 15, 2024
1 parent 868de09 commit 03ee2b1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ replace (
require (
cuelang.org/go v0.6.0
github.com/go-git/go-git/v5 v5.9.0
github.com/go-logr/logr v1.2.4
github.com/go-logr/logr v1.3.0
github.com/gofrs/uuid v4.4.0+incompatible
github.com/google/uuid v1.3.1
github.com/kubernetes/kompose v1.26.1
github.com/layer5io/meshery-operator v0.6.15
github.com/layer5io/meshery-operator v0.7.0
github.com/nats-io/nats.go v1.31.0
github.com/open-policy-agent/opa v0.57.1
github.com/pkg/errors v0.9.1
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0=
Expand Down Expand Up @@ -560,8 +560,8 @@ github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o=
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk=
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw=
github.com/layer5io/meshery-operator v0.6.15 h1:IKvqMIB/xOA42JFB1IaNu6ZZLmJ3BJSvohVYIDkOG8o=
github.com/layer5io/meshery-operator v0.6.15/go.mod h1:+lRenXgniyFfe0gVUVbuA8p+CxjywA6boybnUBsiJY8=
github.com/layer5io/meshery-operator v0.7.0 h1:YXlnsx2Xy5duM+W99vts2fFV4C1KnOCytQi2fxdQTUc=
github.com/layer5io/meshery-operator v0.7.0/go.mod h1:mVMpSrvSH1zgSmcjzk+/astXV5L34NlL/PcZMH6s2IU=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
Expand Down
13 changes: 4 additions & 9 deletions models/controllers/meshery_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ type mesheryBroker struct {
name string
status MesheryControllerStatus
kclient *mesherykube.Client
version string
}

func NewMesheryBrokerHandler(kubernetesClient *mesherykube.Client) IMesheryController {
return &mesheryBroker{
name: "MesheryBroker",
status: Unknown,
kclient: kubernetesClient,
version: "",
}
}

Expand Down Expand Up @@ -112,14 +110,11 @@ 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(), MesheryBroker, metav1.GetOptions{})
if kubeerror.IsNotFound(err) {
return "", err
}
return getImageVersionOfContainer(statefulSet.Spec.Template, "nats"), nil
statefulSet, err := mb.kclient.KubeClient.AppsV1().StatefulSets("meshery").Get(context.TODO(), MesheryBroker, metav1.GetOptions{})
if kubeerror.IsNotFound(err) {
return "", err
}
return mb.version, nil
return getImageVersionOfContainer(statefulSet.Spec.Template, "nats"), nil
}

func getImageVersionOfContainer(container v1.PodTemplateSpec, containerName string) string {
Expand Down
6 changes: 5 additions & 1 deletion models/controllers/meshery_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ func (mo *mesheryOperator) GetPublicEndpoint() (string, error) {
}

func (mo *mesheryOperator) GetVersion() (string, error) {
return "", nil
deployment, err := mo.client.KubeClient.AppsV1().Deployments("meshery").Get(context.TODO(), "meshery-operator", metav1.GetOptions{})
if err != nil {
return "", err
}
return getImageVersionOfContainer(deployment.Spec.Template, "manager"), nil
}

func (mo *mesheryOperator) setStatus(st MesheryControllerStatus) {
Expand Down
14 changes: 12 additions & 2 deletions models/controllers/meshsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"strings"

// opClient "github.com/layer5io/meshery-operator/pkg/client"
opClient "github.com/layer5io/meshery-operator/pkg/client"
mesherykube "github.com/layer5io/meshkit/utils/kubernetes"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -115,5 +114,16 @@ func (ms *meshsync) GetPublicEndpoint() (string, error) {
}

func (ms *meshsync) GetVersion() (string, error) {
return "", nil
meshsyncclient, err := opClient.New(&ms.kclient.RestConfig)
if err != nil {
return "", err
}

meshsyncresource, err := meshsyncclient.CoreV1Alpha1().MeshSyncs("meshery").Get(context.TODO(), "meshery-meshsync", metav1.GetOptions{})

if err != nil {
return "", err
}

return meshsyncresource.Spec.Version, nil
}

0 comments on commit 03ee2b1

Please sign in to comment.