Skip to content

Commit

Permalink
Merge pull request #450 from MUzairS15/MUzairS15/controllers
Browse files Browse the repository at this point in the history
Implement `GetVersion` func for controllers
  • Loading branch information
Mohd Uzair authored Jan 15, 2024
2 parents ec96441 + 912e37f commit b15a4e1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/google/go-containerregistry v0.17.0
github.com/google/uuid v1.4.0
github.com/kubernetes/kompose v1.31.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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,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 b15a4e1

Please sign in to comment.