From 3d8e7beec2165ec65822792abd7f0cfc5339d5d9 Mon Sep 17 00:00:00 2001 From: kumarabd Date: Fri, 23 Oct 2020 18:41:19 +0530 Subject: [PATCH 1/2] fixes for smi Signed-off-by: kumarabd --- go.mod | 10 +- go.sum | 12 +- istio/smi/error.go | 32 ----- istio/smi/smi.go | 278 --------------------------------------- istio/smi_conformance.go | 2 +- 5 files changed, 11 insertions(+), 323 deletions(-) delete mode 100644 istio/smi/error.go delete mode 100644 istio/smi/smi.go diff --git a/go.mod b/go.mod index e0af78b3b..1d6b5c18a 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,9 @@ module github.com/layer5io/meshery-istio go 1.13 -replace github.com/kudobuilder/kuttl => github.com/layer5io/kuttl v0.4.1-0.20200723152044-916f10574334 +replace ( + github.com/kudobuilder/kuttl => github.com/layer5io/kuttl v0.4.1-0.20200723152044-916f10574334 +) require ( cloud.google.com/go v0.46.3 // indirect @@ -11,17 +13,13 @@ require ( github.com/ghodss/yaml v1.0.0 github.com/golang/protobuf v1.4.2 github.com/gophercloud/gophercloud v0.4.0 // indirect - github.com/layer5io/gokit v0.1.12 - github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20200916172547-79cf11334bd7 + github.com/layer5io/gokit v0.1.15 github.com/onsi/ginkgo v1.13.0 // indirect github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.6.0 golang.org/x/net v0.0.0-20200927032502-5d4f70055728 google.golang.org/grpc v1.32.0 - helm.sh/helm/v3 v3.3.1 istio.io/client-go v0.0.0-20200708142230-d7730fd90478 - k8s.io/api v0.18.8 k8s.io/apimachinery v0.18.8 k8s.io/client-go v0.18.8 - rsc.io/letsencrypt v0.0.3 // indirect ) diff --git a/go.sum b/go.sum index d0bd0dfe5..9b4c195ff 100644 --- a/go.sum +++ b/go.sum @@ -516,11 +516,11 @@ 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/gokit v0.1.12 h1:QGfoOHfiOpvPaCg1sGFM8ZuatXsgCkWGPD7GVVVQMyY= -github.com/layer5io/gokit v0.1.12/go.mod h1:kqwXJ5JZqHv74UCH1pVyDdpLT8muaUyRVu58WWu6wcY= +github.com/layer5io/gokit v0.1.15 h1:LlKvIa0seafCHNnmrz089sNl3DXV0WMP5aiRLAttBJU= +github.com/layer5io/gokit v0.1.15/go.mod h1:AGOtt6fbKqg1Q1a9xY7cicF10s1MZJCzBiHg6PCRQMM= github.com/layer5io/kuttl v0.4.1-0.20200723152044-916f10574334/go.mod h1:UmrVd7x+bNVKrpmKgTtfRiTKHZeNPcMjQproJ0vGwhE= -github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20200916172547-79cf11334bd7 h1:jglAwWM8pbUN43HL3tpFYPkWLFNpj1/ZsJISdqKhavg= -github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20200916172547-79cf11334bd7/go.mod h1:LpewBZnN0QDRcC2fDiBVK+iByfFyf2HJM1B2h0rTMZo= +github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20201022191033-40468652a54f h1:ZwVdDIb9RRXCRfRNUGOgwcyn5WrjfJi7NV64SwQ0Gvo= +github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20201022191033-40468652a54f/go.mod h1:LpewBZnN0QDRcC2fDiBVK+iByfFyf2HJM1B2h0rTMZo= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.7.0 h1:h93mCPfUSkaul3Ka/VG8uZdmW1uMHDGxzu0NWHuJmHY= @@ -1119,8 +1119,8 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= -helm.sh/helm/v3 v3.3.1 h1:uc+ZUthJnWNSwqyIv1KCdQm0ewi0eAf6oRaWG2X1oo0= -helm.sh/helm/v3 v3.3.1/go.mod h1:CyCGQa53/k1JFxXvXveGwtfJ4cuB9zkaBSGa5rnAiHU= +helm.sh/helm/v3 v3.3.4 h1:tbad6WQVMxEw1HlVBvI2rQqOblmI5lgXOrWAMwJ198M= +helm.sh/helm/v3 v3.3.4/go.mod h1:CyCGQa53/k1JFxXvXveGwtfJ4cuB9zkaBSGa5rnAiHU= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/istio/smi/error.go b/istio/smi/error.go deleted file mode 100644 index 65b17b3cf..000000000 --- a/istio/smi/error.go +++ /dev/null @@ -1,32 +0,0 @@ -package smi - -import ( - "fmt" - - "github.com/layer5io/gokit/errors" -) - -// ErrSmiInit is the error for smi init method -func ErrSmiInit(des string) error { - return errors.New(errors.ErrSmiInit, des) -} - -// ErrInstallSmi is the error for installing smi tool -func ErrInstallSmi(err error) error { - return errors.New(errors.ErrInstallSmi, fmt.Sprintf("Error installing smi tool: %s", err.Error())) -} - -// ErrConnectSmi is the error for connecting to smi tool -func ErrConnectSmi(err error) error { - return errors.New(errors.ErrConnectSmi, fmt.Sprintf("Error connecting to smi tool: %s", err.Error())) -} - -// ErrRunSmi is the error for running conformance test -func ErrRunSmi(err error) error { - return errors.New(errors.ErrRunSmi, fmt.Sprintf("Error running smi tool: %s", err.Error())) -} - -// ErrDeleteSmi is the error for deleteing smi tool -func ErrDeleteSmi(err error) error { - return errors.New(errors.ErrDeleteSmi, fmt.Sprintf("Error deleting smi tool: %s", err.Error())) -} diff --git a/istio/smi/smi.go b/istio/smi/smi.go deleted file mode 100644 index f4fee55e5..000000000 --- a/istio/smi/smi.go +++ /dev/null @@ -1,278 +0,0 @@ -// Package smi to create, connect and run smi conformance test -package smi - -import ( - "context" - "fmt" - "net" - "os" - "time" - - "github.com/layer5io/learn-layer5/smi-conformance/conformance" - "helm.sh/helm/v3/pkg/action" - "helm.sh/helm/v3/pkg/chart/loader" - "helm.sh/helm/v3/pkg/kube" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/client-go/kubernetes" - - "github.com/layer5io/gokit/utils" -) - -var ( - name = "smi-conformance" - helmPath = "https://github.com/layer5io/learn-layer5/raw/75a6b26cf5a5defaa0629e9bd55780fa52a82d2b/charts/smi-conformance-0.1.2.tgz" - namespace = "meshery" -) - -// Test holds the values for running the test -type Test struct { - id string - adaptorVersion string - adaptorName string - ctx context.Context - kubeClient *kubernetes.Clientset - kubeConfigPath string - smiAddress string - annotations map[string]string - labels map[string]string -} - -// Response is the response format of the result output -type Response struct { - ID string `json:"id,omitempty"` - Date string `json:"date,omitempty"` - MeshName string `json:"mesh_name,omitempty"` - MeshVersion string `json:"mesh_version,omitempty"` - CasesPassed string `json:"cases_passed,omitempty"` - PassingPercentage string `json:"passing_percentage,omitempty"` - Status string `json:"status,omitempty"` - MoreDetails []*Detail `json:"more_details,omitempty"` -} - -// Detail is the format of every test spec -type Detail struct { - SmiSpecification string `json:"smi_specification,omitempty"` - SmiVersion string `json:"smi_version,omitempty"` - Time string `json:"time,omitempty"` - Assertions string `json:"assertions,omitempty"` - Result string `json:"result,omitempty"` - Reason string `json:"reason,omitempty"` - Capability string `json:"capability,omitempty"` - Status string `json:"status,omitempty"` -} - -// New initializes the test -func New(ctx context.Context, id string, version string, name string, client *kubernetes.Clientset) (*Test, error) { - - if len(name) < 2 { - return nil, ErrSmiInit("Adaptor name is nil") - } - - if client == nil { - return nil, ErrSmiInit("Client set is nil") - } - - test := &Test{ - ctx: ctx, - id: id, - adaptorVersion: version, - kubeClient: client, - kubeConfigPath: fmt.Sprintf("%s/.kube/config", utils.GetHome()), - adaptorName: name, - labels: map[string]string{}, - annotations: map[string]string{}, - } - - return test, nil -} - -// Run runs the test -func (test *Test) Run(labels, annotations map[string]string) (Response, error) { - - if labels != nil { - test.labels = labels - } - - if annotations != nil { - test.annotations = annotations - } - - response := Response{ - ID: test.id, - Date: time.Now().String(), - MeshName: test.adaptorName, - MeshVersion: test.adaptorVersion, - CasesPassed: "0", - PassingPercentage: "0", - Status: "deploying", - } - - err := test.installConformanceTool() - if err != nil { - response.Status = "installing" - return response, ErrInstallSmi(err) - } - - err = test.connectConformanceTool() - if err != nil { - response.Status = "connecting" - return response, ErrConnectSmi(err) - } - - err = test.runConformanceTest(&response) - if err != nil { - response.Status = "running" - return response, ErrRunSmi(err) - } - - err = test.deleteConformanceTool() - if err != nil { - response.Status = "deleting" - return response, ErrDeleteSmi(err) - } - - response.Status = "completed" - return response, nil -} - -// installConformanceTool installs the smi conformance tool -func (test *Test) installConformanceTool() error { - - _, err := test.kubeClient.CoreV1().Namespaces().Create(context.TODO(), &corev1.Namespace{ - ObjectMeta: metav1.ObjectMeta{ - Name: namespace, - Annotations: map[string]string{ - "meta.helm.sh/release-name": name, - "meta.helm.sh/release-namespace": namespace, - }, - Labels: map[string]string{ - "app.kubernetes.io/managed-by": "Helm", - }, - }}, metav1.CreateOptions{}) - if err != nil { - return err - } - - localpath := "/tmp/smi-conformance.tar.gz" - err = utils.DownloadFile(localpath, helmPath) - if err != nil { - return err - } - - chart, err := loader.Load(localpath) - if err != nil { - return err - } - - actionConfig := &action.Configuration{} - if err := actionConfig.Init(kube.GetConfig(test.kubeConfigPath, "", namespace), namespace, os.Getenv("HELM_DRIVER"), nil); err != nil { - return err - } - - iCli := action.NewInstall(actionConfig) - iCli.Namespace = namespace - iCli.ReleaseName = name - _, err = iCli.Run(chart, nil) - if err != nil { - return err - } - - time.Sleep(10 * time.Second) // Required for all the resources to be created - - return nil -} - -// deleteConformanceTool deletes the smi conformance tool -func (test *Test) deleteConformanceTool() error { - err := test.kubeClient.CoreV1().Namespaces().Delete(context.TODO(), namespace, metav1.DeleteOptions{}) - if err != nil { - return err - } - return nil -} - -// connectConformanceTool initiates the connection -func (test *Test) connectConformanceTool() error { - var host string - var port int32 - - svc, err := test.kubeClient.CoreV1().Services(namespace).Get(test.ctx, name, metav1.GetOptions{}) - if err != nil { - return err - } - - nodes, err := test.kubeClient.CoreV1().Nodes().List(test.ctx, metav1.ListOptions{}) - if err != nil { - return err - } - addresses := map[string]string{} - for _, addr := range nodes.Items[0].Status.Addresses { - addresses[string(addr.Type)] = addr.Address - } - host = addresses["ExternalIP"] - port = svc.Spec.Ports[0].NodePort - if tcpCheck(addresses["InternalIP"], port) { - host = addresses["InternalIP"] - } - - test.smiAddress = fmt.Sprintf("%s:%d", host, port) - return nil -} - -func tcpCheck(ip string, port int32) bool { - timeout := 5 * time.Second - conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", ip, port), timeout) - if err != nil { - return false - } - if conn != nil { - return true - } - return false -} - -// runConformanceTest runs the conformance test -func (test *Test) runConformanceTest(response *Response) error { - - cClient, err := conformance.CreateClient(context.TODO(), test.smiAddress) - if err != nil { - return err - } - - result, err := cClient.CClient.RunTest(context.TODO(), &conformance.Request{ - Annotations: test.annotations, - Labels: test.labels, - Meshname: test.adaptorName, - Meshversion: test.adaptorVersion, - }) - if err != nil { - return err - } - - response.CasesPassed = result.Casespassed - response.PassingPercentage = result.Passpercent - - details := make([]*Detail, 0) - - for _, d := range result.Details { - details = append(details, &Detail{ - SmiSpecification: d.Smispec, - Time: d.Time, - Assertions: d.Assertions, - Result: d.Result, - Reason: d.Reason, - Capability: d.Capability, - Status: d.Status, - }) - } - - response.MoreDetails = details - - err = cClient.Close() - if err != nil { - return err - } - - return nil -} diff --git a/istio/smi_conformance.go b/istio/smi_conformance.go index 3a5f7357c..711fec832 100644 --- a/istio/smi_conformance.go +++ b/istio/smi_conformance.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" - "github.com/layer5io/meshery-istio/istio/smi" + "github.com/layer5io/gokit/smi" "github.com/layer5io/meshery-istio/meshes" ) From 72565e46d648347a474bf00128c1983baec7995d Mon Sep 17 00:00:00 2001 From: kumarabd Date: Fri, 23 Oct 2020 19:06:10 +0530 Subject: [PATCH 2/2] fixes for smi Signed-off-by: kumarabd --- go.mod | 6 ++---- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 1d6b5c18a..3641b67a6 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,7 @@ module github.com/layer5io/meshery-istio go 1.13 -replace ( - github.com/kudobuilder/kuttl => github.com/layer5io/kuttl v0.4.1-0.20200723152044-916f10574334 -) +replace github.com/kudobuilder/kuttl => github.com/layer5io/kuttl v0.4.1-0.20200723152044-916f10574334 require ( cloud.google.com/go v0.46.3 // indirect @@ -13,7 +11,7 @@ require ( github.com/ghodss/yaml v1.0.0 github.com/golang/protobuf v1.4.2 github.com/gophercloud/gophercloud v0.4.0 // indirect - github.com/layer5io/gokit v0.1.15 + github.com/layer5io/gokit v0.1.16 github.com/onsi/ginkgo v1.13.0 // indirect github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.6.0 diff --git a/go.sum b/go.sum index 9b4c195ff..0e1350550 100644 --- a/go.sum +++ b/go.sum @@ -516,8 +516,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/gokit v0.1.15 h1:LlKvIa0seafCHNnmrz089sNl3DXV0WMP5aiRLAttBJU= -github.com/layer5io/gokit v0.1.15/go.mod h1:AGOtt6fbKqg1Q1a9xY7cicF10s1MZJCzBiHg6PCRQMM= +github.com/layer5io/gokit v0.1.16 h1:EHwYsDi7jBKXIZI4Fes9yMPiTDo+5IyXIwAC9nw5JH4= +github.com/layer5io/gokit v0.1.16/go.mod h1:teEDjx0chMsXpV1ZvIkGM3Q7qi+aCstzan/OWoZgmvU= github.com/layer5io/kuttl v0.4.1-0.20200723152044-916f10574334/go.mod h1:UmrVd7x+bNVKrpmKgTtfRiTKHZeNPcMjQproJ0vGwhE= github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20201022191033-40468652a54f h1:ZwVdDIb9RRXCRfRNUGOgwcyn5WrjfJi7NV64SwQ0Gvo= github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20201022191033-40468652a54f/go.mod h1:LpewBZnN0QDRcC2fDiBVK+iByfFyf2HJM1B2h0rTMZo= @@ -1119,8 +1119,8 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= -helm.sh/helm/v3 v3.3.4 h1:tbad6WQVMxEw1HlVBvI2rQqOblmI5lgXOrWAMwJ198M= -helm.sh/helm/v3 v3.3.4/go.mod h1:CyCGQa53/k1JFxXvXveGwtfJ4cuB9zkaBSGa5rnAiHU= +helm.sh/helm/v3 v3.3.1 h1:uc+ZUthJnWNSwqyIv1KCdQm0ewi0eAf6oRaWG2X1oo0= +helm.sh/helm/v3 v3.3.1/go.mod h1:CyCGQa53/k1JFxXvXveGwtfJ4cuB9zkaBSGa5rnAiHU= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=