Skip to content

Commit

Permalink
Merge pull request #71 from layer5io/remove-meshkit
Browse files Browse the repository at this point in the history
Remove meshkit
  • Loading branch information
kumarabd authored Jan 20, 2021
2 parents 9b11b2a + bcff0c5 commit 91dab06
Show file tree
Hide file tree
Showing 13 changed files with 265 additions and 155 deletions.
45 changes: 45 additions & 0 deletions smi-conformance/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
run:
tests: true

linters:
enable:
- goconst
- gocyclo
- gofmt
- goimports
- golint
- gosec
- govet
- misspell
- unused
- whitespace

linters-settings:
goimports:
local-prefixes: github.com/openservicemesh/osm

issues:
exclude-rules:
# Ignore error for ginkgo and gomega dot imports
- linters:
- golint
source: ". \"github.com/onsi/(ginkgo|gomega)\""
text: "dot imports"
# Ignore error for test framework imports
- linters:
- golint
source: ". \"github.com/openservicemesh/osm/tests/framework\""
text: "dot imports"
# ignore unused linters on keyvault as this code isn't being used
# TODO: disable this rule once keyvault is integrated
- path: pkg/certificate/providers/keyvault/
linters:
- unused
- deadcode
# Exclude staticcheck messages for deprecated function, variable or constant
# This causes issues with package github.com/golang/protobuf/proto
- linters:
- staticcheck
text: "SA1019:"
exclude-use-default: false

3 changes: 3 additions & 0 deletions smi-conformance/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: go-lint
go-lint:
go run github.com/golangci/golangci-lint/cmd/golangci-lint run --config .golangci.yml
23 changes: 16 additions & 7 deletions smi-conformance/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@ module github.com/layer5io/learn-layer5/smi-conformance

go 1.13

replace github.com/kudobuilder/kuttl => github.com/layer5io/kuttl v0.4.1-0.20200806180306-b7e46afd657f

require (
cloud.google.com/go v0.46.3 // indirect
github.com/golang/protobuf v1.4.2
github.com/google/go-cmp v0.5.1 // indirect
github.com/google/go-cmp v0.5.2 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4
github.com/kr/text v0.2.0 // indirect
github.com/kudobuilder/kuttl v0.0.0-00010101000000-000000000000
github.com/kumarabd/gokit v0.2.0
github.com/sirupsen/logrus v1.6.0
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/onsi/ginkgo v1.14.1 // indirect
github.com/onsi/gomega v1.10.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.7.0
github.com/stretchr/testify v1.6.1 // indirect
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 // indirect
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03 // indirect
golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a // indirect
google.golang.org/grpc v1.30.0
google.golang.org/protobuf v1.23.0
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
k8s.io/api v0.17.3
k8s.io/client-go v0.17.3
sigs.k8s.io/controller-runtime v0.5.1
)

replace github.com/kudobuilder/kuttl => github.com/layer5io/kuttl v0.4.1-0.20200806180306-b7e46afd657f
177 changes: 105 additions & 72 deletions smi-conformance/go.sum

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions smi-conformance/grpc/grpc.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package grpc

import (
"errors"
"fmt"
"net"
"time"

middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"

"google.golang.org/grpc"

"github.com/layer5io/learn-layer5/smi-conformance/conformance"
Expand All @@ -19,18 +17,17 @@ type Service struct {
Name string `json:"name"`
Port string `json:"port"`
Version string `json:"version"`
StartedAt time.Time `json:"startedat,string"`
StartedAt time.Time `json:"startedat"`
}

// panicHandler is the handler function to handle panic errors
func panicHandler(r interface{}) error {
fmt.Println("500 panic Error")
return errors.New(fmt.Sprintf("Panic error for: %+v", r))
return fmt.Errorf("Panic error for: %+v", r)
}

// StartServer starts grpc server
// Start grpc server
func Start(s *Service) error {

address := fmt.Sprintf(":%s", s.Port)
listener, err := net.Listen("tcp", address)
if err != nil {
Expand All @@ -55,5 +52,4 @@ func Start(s *Service) error {
return err
}
return nil

}
3 changes: 2 additions & 1 deletion smi-conformance/grpc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
}
)

// RunTest return conformance response
func (s *Service) RunTest(ctx context.Context, req *conformance.Request) (*conformance.Response, error) {
var config test_gen.ServiceMesh

Expand Down Expand Up @@ -68,7 +69,7 @@ func (s *Service) RunTest(ctx context.Context, req *conformance.Request) (*confo
d.Result = res.Failure.Message
d.Status = "Failing"
d.Capability = "None"
failures += 1
failures++
if (res.Assertions - failures) > (res.Assertions / 2) {
d.Capability = "Half"
}
Expand Down
21 changes: 6 additions & 15 deletions smi-conformance/main.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
package main

import (
"fmt"
"github.com/layer5io/learn-layer5/smi-conformance/grpc"
"os"
"sigs.k8s.io/controller-runtime/pkg/log"
"time"

"github.com/layer5io/gokit/logger"
"github.com/layer5io/learn-layer5/smi-conformance/grpc"
)

func main() {

service := &grpc.Service{
Name: "smi-conformance",
Port: "10011",
Version: "v1.0.0",
StartedAt: time.Now(),
}

// Initialize Logger instance
log, err := logger.New(service.Name)
if err != nil {
fmt.Println("Logger Init Failed", err.Error())
os.Exit(1)
}

logger := log.Log.WithName(service.Name)
logger.Info("Conformance tool Started")
// Server Initialization
log.Info("Conformance tool Started")
err = grpc.Start(service)
err := grpc.Start(service)
if err != nil {
log.Err("Conformance tool crashed!!", err.Error())
logger.Error(err, "Conformance tool crashed!!")
os.Exit(1)
}
}
24 changes: 12 additions & 12 deletions smi-conformance/test-gen/service-mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ type Maesh struct {
}

func (sm Maesh) SvcAGetInternalName(namespace string) string {
return fmt.Sprintf("http://%s.%s.maesh:%s", SERVICE_A_NAME, namespace, sm.PortSvcA)
return fmt.Sprintf("http://%s.%s.maesh:%s", SvcNameA, namespace, sm.PortSvcA)
}

func (sm Maesh) SvcBGetInternalName(namespace string) string {
return fmt.Sprintf("http://%s.%s.maesh:%s", SERVICE_B_NAME, namespace, sm.PortSvcB)
return fmt.Sprintf("http://%s.%s.maesh:%s", SvcNameB, namespace, sm.PortSvcB)
}

func (sm Maesh) SvcCGetInternalName(namespace string) string {
return fmt.Sprintf("http://%s.%s.maesh:%s", SERVICE_C_NAME, namespace, sm.PortSvcC)
return fmt.Sprintf("http://%s.%s.maesh:%s", SvcNameC, namespace, sm.PortSvcC)
}

func (sm Maesh) SvcAGetPort() string {
Expand All @@ -56,15 +56,15 @@ type Linkerd struct {
}

func (sm Linkerd) SvcAGetInternalName(namespace string) string {
return fmt.Sprintf("http://%s.%s..svc.cluster.local.:%s", SERVICE_A_NAME, namespace, sm.PortSvcA)
return fmt.Sprintf("http://%s.%s..svc.cluster.local.:%s", SvcNameA, namespace, sm.PortSvcA)
}

func (sm Linkerd) SvcBGetInternalName(namespace string) string {
return fmt.Sprintf("http://%s.%s..svc.cluster.local.:%s", SERVICE_B_NAME, namespace, sm.PortSvcB)
return fmt.Sprintf("http://%s.%s..svc.cluster.local.:%s", SvcNameB, namespace, sm.PortSvcB)
}

func (sm Linkerd) SvcCGetInternalName(namespace string) string {
return fmt.Sprintf("http://%s.%s..svc.cluster.local.:%s", SERVICE_C_NAME, namespace, sm.PortSvcC)
return fmt.Sprintf("http://%s.%s..svc.cluster.local.:%s", SvcNameC, namespace, sm.PortSvcC)
}

func (sm Linkerd) SvcAGetPort() string {
Expand All @@ -86,15 +86,15 @@ type Istio struct {
}

func (sm Istio) SvcAGetInternalName(namespace string) string {
return fmt.Sprintf("http://%s.%s..svc.cluster.local.:%s", SERVICE_A_NAME, namespace, sm.PortSvcA)
return fmt.Sprintf("http://%s.%s..svc.cluster.local.:%s", SvcNameA, namespace, sm.PortSvcA)
}

func (sm Istio) SvcBGetInternalName(namespace string) string {
return fmt.Sprintf("http://%s.%s..svc.cluster.local.:%s", SERVICE_B_NAME, namespace, sm.PortSvcB)
return fmt.Sprintf("http://%s.%s..svc.cluster.local.:%s", SvcNameB, namespace, sm.PortSvcB)
}

func (sm Istio) SvcCGetInternalName(namespace string) string {
return fmt.Sprintf("http://%s.%s..svc.cluster.local.:%s", SERVICE_C_NAME, namespace, sm.PortSvcC)
return fmt.Sprintf("http://%s.%s..svc.cluster.local.:%s", SvcNameC, namespace, sm.PortSvcC)
}

func (sm Istio) SvcAGetPort() string {
Expand All @@ -116,15 +116,15 @@ type OSM struct {
}

func (sm OSM) SvcAGetInternalName(namespace string) string {
return fmt.Sprintf("http://%s.%s..svc.cluster.local.:%s", SERVICE_A_NAME, namespace, sm.PortSvcA)
return fmt.Sprintf("http://%s.%s..svc.cluster.local.:%s", SvcNameA, namespace, sm.PortSvcA)
}

func (sm OSM) SvcBGetInternalName(namespace string) string {
return fmt.Sprintf("http://%s.%s..svc.cluster.local.:%s", SERVICE_B_NAME, namespace, sm.PortSvcB)
return fmt.Sprintf("http://%s.%s..svc.cluster.local.:%s", SvcNameB, namespace, sm.PortSvcB)
}

func (sm OSM) SvcCGetInternalName(namespace string) string {
return fmt.Sprintf("http://%s.%s..svc.cluster.local.:%s", SERVICE_C_NAME, namespace, sm.PortSvcC)
return fmt.Sprintf("http://%s.%s..svc.cluster.local.:%s", SvcNameC, namespace, sm.PortSvcC)
}

func (sm OSM) SvcAGetPort() string {
Expand Down
5 changes: 1 addition & 4 deletions smi-conformance/test-gen/test_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,5 @@ func RunTest(meshConfig ServiceMesh, annotations, labels map[string]string) Resu
time.Sleep(30 * time.Second)
})
}()
select {
case x := <-c:
return x
}
return <-c
}
21 changes: 14 additions & 7 deletions smi-conformance/test-gen/traffic-access.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ func (smi *SMIConformance) trafficBlocked(
return []error{err}
}
clusterIPs, err := GetClusterIPs(kubeClient, namespace)

if err != nil {
t.Fail()
return []error{err}
}
ClearAllMetrics(clusterIPs, smi.SMObj)

// This test will make SERVICE A make a request to SERVICE B
svcBTestURL := fmt.Sprintf("%s/%s", smi.SMObj.SvcBGetInternalName(namespace), ECHO)
var jsonStr = []byte(`{"url":"` + svcBTestURL + `", "body":"", "method": "GET", "headers": {}}`)

url := fmt.Sprintf("http://%s:%s/%s", clusterIPs[SERVICE_A_NAME], smi.SMObj.SvcAGetPort(), CALL)
url := fmt.Sprintf("http://%s:%s/%s", clusterIPs[SvcNameA], smi.SMObj.SvcAGetPort(), CALL)
_, err = httpClient.Post(url, "application/json", bytes.NewBuffer(jsonStr))

Logger.Logf("URL : \n", url)
Expand All @@ -56,7 +59,7 @@ func (smi *SMIConformance) trafficBlocked(
return []error{err}
}

metricsSvcA, err := GetMetrics(clusterIPs[SERVICE_A_NAME], "9091")
metricsSvcA, err := GetMetrics(clusterIPs[SvcNameA], "9091")
if err != nil {
t.Fail()
Logger.Logf("Error : %s", err.Error())
Expand Down Expand Up @@ -100,14 +103,18 @@ func (smi *SMIConformance) trafficAllow(
return []error{err}
}
clusterIPs, err := GetClusterIPs(kubeClient, namespace)

if err!=nil{
t.Fail()
Logger.Logf("Error : %s", err.Error())
return []error{err}
}
ClearAllMetrics(clusterIPs, smi.SMObj)

// This test will make SERVICE A make a request to SERVICE B
svcBTestURL := fmt.Sprintf("%s/%s", smi.SMObj.SvcBGetInternalName(namespace), ECHO)
var jsonStr = []byte(`{"url":"` + svcBTestURL + `", "body":"", "method": "GET", "headers": {}}`)

url := fmt.Sprintf("http://%s:%s/%s", clusterIPs[SERVICE_A_NAME], smi.SMObj.SvcAGetPort(), CALL)
url := fmt.Sprintf("http://%s:%s/%s", clusterIPs[SvcNameA], smi.SMObj.SvcAGetPort(), CALL)
_, err = httpClient.Post(url, "application/json", bytes.NewBuffer(jsonStr))

Logger.Logf("URL : \n", url)
Expand All @@ -118,7 +125,7 @@ func (smi *SMIConformance) trafficAllow(
return []error{err}
}

metricsSvcA, err := GetMetrics(clusterIPs[SERVICE_A_NAME], "9091")
metricsSvcA, err := GetMetrics(clusterIPs[SvcNameA], "9091")

if err != nil {
t.Fail()
Expand All @@ -143,7 +150,7 @@ func (smi *SMIConformance) trafficAllow(
}
Logger.Log("Validated: Response destination")

metricsSvcB, err := GetMetrics(clusterIPs[SERVICE_B_NAME], "9091")
metricsSvcB, err := GetMetrics(clusterIPs[SvcNameB], "9091")
if err != nil {
t.Fail()
Logger.Log("Error: ", err)
Expand Down
Loading

0 comments on commit 91dab06

Please sign in to comment.