From 03ee2b184d7ae8dd850a261460b04ec5488d96cb Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Mon, 15 Jan 2024 18:40:27 +0530 Subject: [PATCH 1/2] implement GetVersion func for controllers Signed-off-by: MUzairS15 --- go.mod | 4 ++-- go.sum | 8 ++++---- models/controllers/meshery_broker.go | 13 ++++--------- models/controllers/meshery_operator.go | 6 +++++- models/controllers/meshsync.go | 14 ++++++++++++-- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 26a85faa..3ec3ae4a 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index ea68ddde..1e2284ae 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/models/controllers/meshery_broker.go b/models/controllers/meshery_broker.go index 09ab1215..a4f10360 100644 --- a/models/controllers/meshery_broker.go +++ b/models/controllers/meshery_broker.go @@ -18,7 +18,6 @@ type mesheryBroker struct { name string status MesheryControllerStatus kclient *mesherykube.Client - version string } func NewMesheryBrokerHandler(kubernetesClient *mesherykube.Client) IMesheryController { @@ -26,7 +25,6 @@ func NewMesheryBrokerHandler(kubernetesClient *mesherykube.Client) IMesheryContr name: "MesheryBroker", status: Unknown, kclient: kubernetesClient, - version: "", } } @@ -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 { diff --git a/models/controllers/meshery_operator.go b/models/controllers/meshery_operator.go index b6094e80..750e9326 100644 --- a/models/controllers/meshery_operator.go +++ b/models/controllers/meshery_operator.go @@ -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) { diff --git a/models/controllers/meshsync.go b/models/controllers/meshsync.go index 595c38a2..c1712047 100644 --- a/models/controllers/meshsync.go +++ b/models/controllers/meshsync.go @@ -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" @@ -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 } From aa42b80957c2e50a32b6767b7acd4bb8db15a54f Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Mon, 15 Jan 2024 18:43:38 +0530 Subject: [PATCH 2/2] lint fixes Signed-off-by: MUzairS15 --- models/controllers/meshsync.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/controllers/meshsync.go b/models/controllers/meshsync.go index c1712047..b661a088 100644 --- a/models/controllers/meshsync.go +++ b/models/controllers/meshsync.go @@ -118,9 +118,9 @@ func (ms *meshsync) GetVersion() (string, error) { if err != nil { return "", err } - + meshsyncresource, err := meshsyncclient.CoreV1Alpha1().MeshSyncs("meshery").Get(context.TODO(), "meshery-meshsync", metav1.GetOptions{}) - + if err != nil { return "", err }