Skip to content

Commit

Permalink
Merge pull request #187 from layer5io/meshworks
Browse files Browse the repository at this point in the history
Meshworks
  • Loading branch information
leecalcote authored Feb 14, 2021
2 parents c48a78b + 80e23ad commit 1bbc7f8
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -ldflags="-w -
FROM gcr.io/distroless/base
ENV DISTRO="debian"
ENV GOARCH="amd64"
ENV SERVICE_ADDR="meshery-istio"
ENV MESHERY_SERVER="http://meshery:9081"
WORKDIR /templates
COPY templates/* .
COPY templates/* ./
WORKDIR /
COPY oam/ oam/
COPY --from=builder /build/meshery-istio .
ENTRYPOINT ["/meshery-istio"]
16 changes: 16 additions & 0 deletions istio/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,25 @@ var (
// during istio-vet process
ErrIstioVetCode = "istio_test_code"

// ErrParseOAMComponentCode represents the error code which is
// generated during the OAM component parsing
ErrParseOAMComponentCode = "istio_test_code"

// ErrParseOAMConfigCode represents the error code which is
// generated during the OAM configuration parsing
ErrParseOAMConfigCode = "istio_test_code"

// ErrOpInvalid represents the errors which are generated
// when an invalid operation is requested
ErrOpInvalid = errors.NewDefault(errors.ErrOpInvalid, "Invalid operation")

// ErrParseOAMComponent represents the error which is
// generated during the OAM component parsing
ErrParseOAMComponent = errors.NewDefault(ErrParseOAMComponentCode, "error parsing the component")

// ErrParseOAMConfig represents the error which is
// generated during the OAM configuration parsing
ErrParseOAMConfig = errors.NewDefault(ErrParseOAMConfigCode, "error parsing the configuration")
)

// ErrInstallIstio is the error for install mesh
Expand Down
21 changes: 19 additions & 2 deletions istio/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (istio *Istio) ProcessOAM(ctx context.Context, oamReq adapter.OAMRequest) (
for _, acomp := range oamReq.OamComps {
comp, err := oam.ParseApplicationComponent(acomp)
if err != nil {
fmt.Println("error parsing the component")
istio.Log.Error(ErrParseOAMComponent)
continue
}

Expand All @@ -218,7 +218,24 @@ func (istio *Istio) ProcessOAM(ctx context.Context, oamReq adapter.OAMRequest) (

config, err := oam.ParseApplicationConfiguration(oamReq.OamConfig)
if err != nil {
fmt.Println("error parsing the conifguration")
istio.Log.Error(ErrParseOAMConfig)
}

// If operation is delete then first HandleConfiguration and then handle the deployment
if oamReq.DeleteOp {
// Process configuration
msg2, err := istio.HandleApplicationConfiguration(config, oamReq.DeleteOp)
if err != nil {
return msg2, err
}

// Process components
msg1, err := istio.HandleComponents(comps, oamReq.DeleteOp)
if err != nil {
return msg1 + "\n" + msg2, err
}

return msg1 + "\n" + msg2, nil
}

// Process components
Expand Down
33 changes: 29 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"fmt"
"os"
"path"
"strings"
"time"

"github.com/layer5io/meshery-istio/istio"
Expand Down Expand Up @@ -102,13 +103,13 @@ func main() {
service.StartedAt = time.Now()

// Register workloads
if err := oam.RegisterWorkloads("http://localhost:9081", "mesherylocal.layer5.io:"+service.Port); err != nil {
fmt.Println(err)
if err := oam.RegisterWorkloads(mesheryServerAddress(), serviceAddress()+":"+service.Port); err != nil {
log.Info(err.Error())
}

// Register traits
if err := oam.RegisterTraits("http://localhost:9081", "mesherylocal.layer5.io:"+service.Port); err != nil {
fmt.Println(err)
if err := oam.RegisterTraits(mesheryServerAddress(), serviceAddress()+":"+service.Port); err != nil {
log.Info(err.Error())
}

// Server Initialization
Expand All @@ -123,3 +124,27 @@ func main() {
func isDebug() bool {
return os.Getenv("DEBUG") == "true"
}

func mesheryServerAddress() string {
meshReg := os.Getenv("MESHERY_SERVER")

if meshReg != "" {
if strings.HasPrefix(meshReg, "http") {
return meshReg
}

return "http://" + meshReg
}

return "http://localhost:9081"
}

func serviceAddress() string {
svcAddr := os.Getenv("SERVICE_ADDR")

if svcAddr != "" {
return svcAddr
}

return "mesherylocal.layer5.io"
}

0 comments on commit 1bbc7f8

Please sign in to comment.