Skip to content

Commit

Permalink
Merge pull request #33 from dhruv0000/smiProto
Browse files Browse the repository at this point in the history
SMI protobuf Update
  • Loading branch information
leecalcote authored Jan 27, 2021
2 parents 9ef565e + da9998c commit 50f4c3b
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 153 deletions.
89 changes: 59 additions & 30 deletions adapter/smi.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,27 @@ package adapter

import (
"context"
"encoding/json"
"fmt"
"strings"
"time"

"github.com/layer5io/learn-layer5/smi-conformance/conformance"

"github.com/layer5io/meshery-adapter-library/status"
"github.com/layer5io/meshkit/utils"
mesherykube "github.com/layer5io/meshkit/utils/kubernetes"
smp "github.com/layer5io/service-mesh-performance/spec"
)

type SMITest struct {
id string
adaptorVersion string
adaptorName string
ctx context.Context
kclient *mesherykube.Client
smiAddress string
annotations map[string]string
labels map[string]string
id string
meshVersion string
meshType smp.ServiceMesh_Type
ctx context.Context
kclient *mesherykube.Client
smiAddress string
annotations map[string]string
labels map[string]string
}

type Response struct {
Expand Down Expand Up @@ -81,8 +84,14 @@ type SMITestOptions struct {

// RunSMITest runs the SMI test on the adapter's service mesh
func (h *Adapter) RunSMITest(opts SMITestOptions) (Response, error) {
adapterName := h.GetName()
adapterVersion := h.GetVersion()
e := &Event{
Operationid: opts.OperationID,
Summary: status.Deploying,
Details: "None",
}

meshVersion := h.GetVersion()
meshType := smp.ServiceMesh_Type(smp.ServiceMesh_Type_value[h.GetType()])
name := "smi-conformance"

kclient, err := mesherykube.New(h.KubeClient, h.RestConfig)
Expand All @@ -91,20 +100,20 @@ func (h *Adapter) RunSMITest(opts SMITestOptions) (Response, error) {
}

test := &SMITest{
ctx: opts.Ctx,
id: opts.OperationID,
adaptorName: adapterName,
adaptorVersion: adapterVersion,
labels: opts.Labels,
annotations: opts.Annotations,
kclient: kclient,
ctx: opts.Ctx,
id: opts.OperationID,
meshType: meshType,
meshVersion: meshVersion,
labels: opts.Labels,
annotations: opts.Annotations,
kclient: kclient,
}

response := Response{
ID: test.id,
Date: time.Now().Format(time.RFC3339),
MeshName: test.adaptorName,
MeshVersion: test.adaptorVersion,
MeshName: strings.Title(strings.ToLower(strings.ReplaceAll(test.meshType.String(), "_", " "))),
MeshVersion: test.meshVersion,
CasesPassed: "0",
PassingPercentage: "0",
Status: "deploying",
Expand All @@ -131,6 +140,12 @@ func (h *Adapter) RunSMITest(opts SMITestOptions) (Response, error) {
}

response.Status = "completed"

e.Summary = fmt.Sprintf("Smi conformance test %s successfully", response.Status)
jsondata, _ := json.Marshal(response)
e.Details = string(jsondata)
h.StreamInfo(e)

return response, nil
}

Expand Down Expand Up @@ -187,10 +202,12 @@ func (test *SMITest) runConformanceTest(response *Response) error {
}

result, err := cClient.CClient.RunTest(context.TODO(), &conformance.Request{
Annotations: test.annotations,
Labels: test.labels,
Meshname: test.adaptorName,
Meshversion: test.adaptorVersion,
Mesh: &smp.ServiceMesh{
Annotations: test.annotations,
Labels: test.labels,
Type: test.meshType,
Version: test.meshVersion,
},
})
if err != nil {
return err
Expand All @@ -202,14 +219,26 @@ func (test *SMITest) runConformanceTest(response *Response) error {
details := make([]*Detail, 0)

for _, d := range result.Details {
result := ""
reason := ""

if d.Result.GetMessage() != "" {
result = d.Result.GetMessage()
reason = ""
} else {
result = d.Result.GetError().ShortDescription
reason = d.Result.GetError().LongDescription
}

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,
SmiVersion: d.Specversion,
Time: d.Duration,
Assertions: d.Assertion,
Result: result,
Reason: reason,
Capability: d.Capability.String(),
Status: d.Status.String(),
})
}

Expand Down
10 changes: 10 additions & 0 deletions adapter/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (

type Spec struct {
Name string `json:"name"`
Type string `json:"type"`
Status string `json:"status"`
Version string `json:"version"`
}
Expand All @@ -44,3 +45,12 @@ func (h *Adapter) GetVersion() string {
}
return spec.Version
}

func (h *Adapter) GetType() string {
spec := &Spec{}
err := h.Config.GetObject(MeshSpecKey, &spec)
if err != nil && len(spec.Type) > 0 {
return "INVALID_MESH"
}
return spec.Type
}
63 changes: 0 additions & 63 deletions adapter/validate.go

This file was deleted.

7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ replace github.com/kudobuilder/kuttl => github.com/layer5io/kuttl v0.4.1-0.20200
require (
github.com/golang/protobuf v1.4.2
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20201022191033-40468652a54f
github.com/layer5io/meshkit v0.1.30
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210125055931-43e1dc9563c4
github.com/layer5io/meshkit v0.2.1-0.20210127211805-88e99ca45457
github.com/layer5io/service-mesh-performance v0.3.2
github.com/spf13/viper v1.7.1
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc v0.11.0
go.opentelemetry.io/otel v0.11.0
go.opentelemetry.io/otel/exporters/trace/jaeger v0.11.0
go.opentelemetry.io/otel/sdk v0.11.0
golang.org/x/net v0.0.0-20200707034311-ab3426394381
golang.org/x/net v0.0.0-20200822124328-c89045814202
google.golang.org/grpc v1.31.0
gopkg.in/yaml.v2 v2.3.0
k8s.io/client-go v0.18.12
Expand Down
Loading

0 comments on commit 50f4c3b

Please sign in to comment.