Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Zanda256/meshery-consul into add-…
Browse files Browse the repository at this point in the history
…e2e-tests/meshery#249
  • Loading branch information
Zanda256 committed Sep 22, 2022
2 parents 3b9a6da + ef5b57a commit e1d8bd7
Show file tree
Hide file tree
Showing 13 changed files with 216 additions and 693 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.17'
go-version: '1.19'
- run: GOPROXY=direct GOSUMDB=off GO111MODULE=on go build .
error_check:
name: Error check
Expand All @@ -56,8 +56,8 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- run: GOPROXY=https://proxy.golang.org,direct GOSUMDB=off GO111MODULE=on go get -u github.com/kisielk/errcheck; /home/runner/go/bin/errcheck -tags draft ./...
go-version: 1.19
- run: GOPROXY=https://proxy.golang.org,direct GOSUMDB=off GO111MODULE=on go install github.com/kisielk/errcheck@latest; /home/runner/go/bin/errcheck -tags draft ./...
error_code_check:
name: Error code utility check
runs-on: ubuntu-latest
Expand All @@ -69,7 +69,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: 1.19
- run: |
errWillHave="level=error"
GOPROXY=https://proxy.golang.org,direct GOSUMDB=off GO111MODULE=on go install github.com/layer5io/meshkit/cmd/errorutil;
Expand All @@ -93,7 +93,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.19
- uses: dominikh/[email protected]
with:
version: "2022.1"
Expand All @@ -109,7 +109,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.19
- run: GOPROXY=https://proxy.golang.org,direct GOSUMDB=off GO111MODULE=on go vet -tags draft ./...
sec_check:
name: Security check
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.19
- name: Create cluster using KinD
uses: engineerd/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-oam-defs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: 1.17
go-version: 1.19
- name: Run adapter to create components
run: |
touch log.txt
Expand Down
8 changes: 4 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ linters:
# TODO: consider continuously if more should be enabled.
# Can also be useful to run with more strict settings before commit locally, i.e. to test for TODOs (godox)
# - bodyclose
- deadcode
# - deadcode
- dogsled
# - dupl
- errcheck
Expand All @@ -87,7 +87,7 @@ linters:
# - gocyclo
- gofmt
- goimports
- golint
# - golint
- gomodguard
- gosec
# - gomnd
Expand All @@ -103,13 +103,13 @@ linters:
# - rowserrcheck
# - scopelint
- staticcheck
- structcheck
# - structcheck
- stylecheck
- typecheck
# - unconvert
# - unparam
- unused
- varcheck
# - varcheck
- whitespace
- asciicheck
# - gochecknoglobals
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17 as bd
FROM golang:1.19 as bd
ARG VERSION
ARG GIT_COMMITSHA
WORKDIR /github.com/layer5io/meshery-consul
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ include build/Makefile.show-help.mk
# Environment Setup
#-----------------------------------------------------------------------------
BUILDER=buildx-multi-arch
ADAPTER=istio
ADAPTER=consul

v ?= 1.17.8 # Default go version to be used
v ?= 1.19.1 # Default go version to be used


#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -57,7 +57,7 @@ docker-run:

## Build and run Adapter locally
run:
go$(v) mod tidy -compat=1.17; \
go$(v) mod tidy; \
DEBUG=true GOPROXY=direct GOSUMDB=off go run main.go

## Build and run Adapter locally; force component registration
Expand Down
2 changes: 1 addition & 1 deletion build/Makefile.core.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ GIT_VERSION = $(shell git describe --tags `git rev-list --tags --max-count=1`)
GIT_COMMITSHA = $(shell git rev-list -1 HEAD)
GIT_STRIPPED_VERSION=$(shell git describe --tags `git rev-list --tags --max-count=1` | cut -c 2-)

GOVERSION = 1.17.8
GOVERSION = 1.19.1
GOPATH = $(shell go env GOPATH)
GOBIN = $(GOPATH)/bin

Expand Down
2 changes: 1 addition & 1 deletion build/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var CRDnames []string
var OverrideURL string
var AllVersions []Versions

//NewConfig creates the configuration for creating components
// NewConfig creates the configuration for creating components
func NewConfig(version string) manifests.Config {
return manifests.Config{
Name: smp.ServiceMesh_Type_name[int32(smp.ServiceMesh_CONSUL)],
Expand Down
10 changes: 5 additions & 5 deletions consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@ import (
"github.com/layer5io/meshkit/logger"
"github.com/layer5io/meshkit/models"
"github.com/layer5io/meshkit/models/oam/core/v1alpha1"
"github.com/layer5io/meshkit/utils/events"
"gopkg.in/yaml.v2"
)

type Consul struct {
adapter.Adapter
}

func New(config config.Handler, log logger.Handler, kubeConfig config.Handler) adapter.Handler {
func New(config config.Handler, log logger.Handler, kubeConfig config.Handler, e *events.EventStreamer) adapter.Handler {
return &Consul{
adapter.Adapter{Config: config, Log: log, KubeconfigHandler: kubeConfig},
adapter.Adapter{Config: config, Log: log, KubeconfigHandler: kubeConfig, EventStreamer: e},
}
}

//CreateKubeconfigs creates and writes passed kubeconfig onto the filesystem
// CreateKubeconfigs creates and writes passed kubeconfig onto the filesystem
func (h *Consul) CreateKubeconfigs(kubeconfigs []string) error {
var errs = make([]error, 0)
for _, kubeconfig := range kubeconfigs {
Expand Down Expand Up @@ -82,12 +83,11 @@ func (h *Consul) CreateKubeconfigs(kubeconfigs []string) error {
}

// ProcessOAM will handles the grpc invocation for handling OAM objects
func (h *Consul) ProcessOAM(ctx context.Context, oamReq adapter.OAMRequest, hchan *chan interface{}) (string, error) {
func (h *Consul) ProcessOAM(ctx context.Context, oamReq adapter.OAMRequest) (string, error) {
err := h.CreateKubeconfigs(oamReq.K8sConfigs)
if err != nil {
return "", err
}
h.SetChannel(hchan)
kubeconfigs := oamReq.K8sConfigs
var comps []v1alpha1.Component
for _, acomp := range oamReq.OamComps {
Expand Down
27 changes: 24 additions & 3 deletions consul/oam.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"strings"
"sync"

"github.com/google/uuid"
"github.com/layer5io/meshery-adapter-library/meshes"
"github.com/layer5io/meshery-consul/internal/config"
"github.com/layer5io/meshkit/models/oam/core/v1alpha1"
mesherykube "github.com/layer5io/meshkit/utils/kubernetes"
"gopkg.in/yaml.v2"
Expand All @@ -16,29 +19,47 @@ type CompHandler func(*Consul, v1alpha1.Component, bool, []string) (string, erro
func (h *Consul) HandleComponents(comps []v1alpha1.Component, isDel bool, kubeconfigs []string) (string, error) {
var errs []error
var msgs []string

stat1 := "deploying"
stat2 := "deployed"
if isDel {
stat1 = "removing"
stat2 = "removed"
}
compFuncMap := map[string]CompHandler{
"ConsulMesh": handleComponentConsulMesh,
}
for _, comp := range comps {
ee := &meshes.EventsResponse{
OperationId: uuid.New().String(),
Component: config.ServerDefaults["type"],
ComponentName: config.ServerDefaults["name"],
}
fnc, ok := compFuncMap[comp.Spec.Type]
if !ok {
msg, err := handleConsulCoreComponents(h, comp, isDel, "", "", kubeconfigs)
if err != nil {
ee.Summary = fmt.Sprintf("Error while %s %s", stat1, comp.Spec.Type)
h.streamErr(ee.Summary, ee, err)
errs = append(errs, err)
continue
}

ee.Summary = fmt.Sprintf("%s %s successfully", comp.Spec.Type, stat2)
ee.Details = fmt.Sprintf("The %s is now %s.", comp.Spec.Type, stat2)
h.StreamInfo(ee)
msgs = append(msgs, msg)
continue
}

msg, err := fnc(h, comp, isDel, kubeconfigs)
if err != nil {
ee.Summary = fmt.Sprintf("Error while %s %s", stat1, comp.Spec.Type)
h.streamErr(ee.Summary, ee, err)
errs = append(errs, err)
continue
}

ee.Summary = fmt.Sprintf("%s %s %s successfully", comp.Name, comp.Spec.Type, stat2)
ee.Details = fmt.Sprintf("The %s %s is now %s.", comp.Name, comp.Spec.Type, stat2)
h.StreamInfo(ee)
msgs = append(msgs, msg)
}
if err := mergeErrors(errs); err != nil {
Expand Down
15 changes: 7 additions & 8 deletions consul/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ import (
mesherykube "github.com/layer5io/meshkit/utils/kubernetes"
)

func (h *Consul) ApplyOperation(ctx context.Context, request adapter.OperationRequest, hchan *chan interface{}) error {
func (h *Consul) ApplyOperation(ctx context.Context, request adapter.OperationRequest) error {
err := h.CreateKubeconfigs(request.K8sConfigs)
if err != nil {
return err
}
h.SetChannel(hchan)
kubeconfigs := request.K8sConfigs
operations := make(adapter.Operations)
err = h.Config.GetObject(adapter.OperationsKey, &operations)
Expand All @@ -42,10 +41,10 @@ func (h *Consul) ApplyOperation(ctx context.Context, request adapter.OperationRe

//status := opstatus.Deploying
e := &meshes.EventsResponse{
OperationId: request.OperationID,
Summary: "Deploying",
Details: "None",
Component: config.ServerDefaults["type"],
OperationId: request.OperationID,
Summary: "Deploying",
Details: "None",
Component: config.ServerDefaults["type"],
ComponentName: config.ServerDefaults["name"],
}

Expand Down Expand Up @@ -114,7 +113,7 @@ func (h *Consul) ApplyOperation(ctx context.Context, request adapter.OperationRe
APIServerURL: kClient.RestConfig.Host,
})
if err1 != nil {
summary := fmt.Sprintf("Unable to retrieve service endpoint for the service %s.", svc)
summary := fmt.Sprintf("Unable to retrieve service endpoint for the service %s.", svc)
h.streamErr(summary, e, err1)
} else {
external := "N/A"
Expand Down Expand Up @@ -142,7 +141,7 @@ func (h *Consul) ApplyOperation(ctx context.Context, request adapter.OperationRe
return nil
}

func(h *Consul) streamErr(summary string, e *meshes.EventsResponse, err error) {
func (h *Consul) streamErr(summary string, e *meshes.EventsResponse, err error) {
e.Summary = summary
e.Details = err.Error()
e.ErrorCode = errors.GetCode(err)
Expand Down
Loading

0 comments on commit e1d8bd7

Please sign in to comment.