Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit 5411ac4

Browse files
authored
Merge pull request #70 from utkarsh-pro/utkarsh-pro/feature/osm-sample-app
Add osm sample app
2 parents 52e2546 + 95fd58c commit 5411ac4

File tree

12 files changed

+564
-105
lines changed

12 files changed

+564
-105
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ go 1.15
55
replace github.com/kudobuilder/kuttl => github.com/layer5io/kuttl v0.4.1-0.20200806180306-b7e46afd657f
66

77
require (
8-
github.com/layer5io/meshery-adapter-library v0.1.10
8+
github.com/layer5io/meshery-adapter-library v0.1.11
99
github.com/layer5io/meshkit v0.1.31
1010
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,8 @@ github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20201022191033-40468652a
549549
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20201022191033-40468652a54f/go.mod h1:LpewBZnN0QDRcC2fDiBVK+iByfFyf2HJM1B2h0rTMZo=
550550
github.com/layer5io/meshery-adapter-library v0.1.10 h1:oNbo09P+m9xWwPkbTq46Y8ujPIcef9rBfTTVM2jHpiY=
551551
github.com/layer5io/meshery-adapter-library v0.1.10/go.mod h1:AFTJZboGpCVCgG928sIA+hjdmkA5j+2oAEU7vje2A6k=
552+
github.com/layer5io/meshery-adapter-library v0.1.11 h1:ZUSI6Jf3XxXj4uy+csKa7hdrd1hdKoxMkzWNPa+qxs4=
553+
github.com/layer5io/meshery-adapter-library v0.1.11/go.mod h1:AFTJZboGpCVCgG928sIA+hjdmkA5j+2oAEU7vje2A6k=
552554
github.com/layer5io/meshkit v0.1.30/go.mod h1:AznOL6xqpUZGyExSZJ3Bdx6EZ22UnAT9V620pm7R484=
553555
github.com/layer5io/meshkit v0.1.31 h1:09kfaoEbxqJ8Rc20XPudUnXoRU2QsKcGRp87ebNd7+E=
554556
github.com/layer5io/meshkit v0.1.31/go.mod h1:pS3KsOqOFYXiKuHZCPGTgZRwhTuF5R9qemWm+1+KvjU=

internal/config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ func NewKubeconfigBuilder(provider string) (config.Handler, error) {
4444
}
4545
return nil, config.ErrEmptyConfig
4646
}
47+
48+
// RootPath returns the root config path
49+
func RootPath() string {
50+
return configRootPath
51+
}

internal/config/operations.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,35 @@ import (
2020
)
2121

2222
var (
23-
OSMOperation = "osm"
23+
OSMOperation = "osm"
24+
OSMBookStoreOperation = "osm_bookstore_app"
25+
ServiceName = "service_name"
2426
)
2527

2628
func getOperations(op adapter.Operations) adapter.Operations {
2729
op[OSMOperation] = &adapter.Operation{
2830
Type: int32(meshes.OpCategory_INSTALL),
2931
Description: "OSM Service Mesh",
30-
Versions: []adapter.Version{"v0.3.0", "v0.2.0"},
32+
Versions: []adapter.Version{"v0.6.0", "v0.5.0"},
3133
Templates: adapter.NoneTemplate,
3234
}
35+
36+
op[OSMBookStoreOperation] = &adapter.Operation{
37+
Type: int32(meshes.OpCategory_SAMPLE_APPLICATION),
38+
Description: "Bookstore Application",
39+
Versions: []adapter.Version{"v0.6.0", "v0.5.0"},
40+
Templates: []adapter.Template{
41+
"https://raw.githubusercontent.com/openservicemesh/osm/main/docs/example/manifests/apps/bookbuyer.yaml",
42+
"https://raw.githubusercontent.com/openservicemesh/osm/main/docs/example/manifests/apps/bookstore-v1.yaml",
43+
"https://raw.githubusercontent.com/openservicemesh/osm/main/docs/example/manifests/apps/bookthief.yaml",
44+
"https://raw.githubusercontent.com/openservicemesh/osm/main/docs/example/manifests/apps/bookwarehouse.yaml",
45+
"https://raw.githubusercontent.com/openservicemesh/osm/main/docs/example/manifests/apps/traffic-split.yaml",
46+
"file://templates/osm-bookstore-traffic-access-v1.yaml",
47+
},
48+
AdditionalProperties: map[string]string{
49+
ServiceName: "bookstore",
50+
},
51+
}
52+
3353
return op
3454
}

main.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,40 @@ package main
1616

1717
import (
1818
"fmt"
19+
"os"
20+
"path"
21+
"time"
22+
1923
"github.com/layer5io/meshery-adapter-library/adapter"
2024
"github.com/layer5io/meshery-adapter-library/api/grpc"
2125
configprovider "github.com/layer5io/meshery-adapter-library/config/provider"
2226
internalconfig "github.com/layer5io/meshery-osm/internal/config"
2327
"github.com/layer5io/meshery-osm/osm"
2428
"github.com/layer5io/meshkit/logger"
2529
"github.com/layer5io/meshkit/utils"
26-
"os"
27-
"path"
28-
"time"
2930
)
3031

3132
const (
3233
serviceName = "osm-adapter"
3334
)
3435

3536
func main() {
36-
log, err := logger.New(serviceName, logger.Options{Format: logger.JsonLogFormat, DebugLevel: false})
37+
log, err := logger.New(serviceName, logger.Options{Format: logger.SyslogLogFormat, DebugLevel: displayDebugLogs()})
3738
if err != nil {
3839
fmt.Println("Logger Init Failed", err.Error())
3940
os.Exit(1)
4041
}
4142

43+
if err = os.Setenv("KUBECONFIG", path.Join(
44+
internalconfig.KubeConfigDefaults[configprovider.FilePath],
45+
fmt.Sprintf("%s.%s", internalconfig.KubeConfigDefaults[configprovider.FileName],
46+
internalconfig.KubeConfigDefaults[configprovider.FileType],
47+
)),
48+
); err != nil {
49+
// Fail silently
50+
log.Warn(err)
51+
}
52+
4253
cfg, err := internalconfig.New(configprovider.ViperKey)
4354
if err != nil {
4455
log.Error(err)
@@ -57,6 +68,9 @@ func main() {
5768
service.Handler = osm.New(cfg, log, kubeconfigHandler)
5869
service.Channel = make(chan interface{}, 100)
5970
service.StartedAt = time.Now()
71+
72+
// Server Initialization
73+
log.Info("Adaptor Listening at port: ", service.Port)
6074
err = grpc.Start(service, nil)
6175
if err != nil {
6276
log.Error(grpc.ErrGrpcServer(err))
@@ -73,3 +87,9 @@ func init() {
7387
os.Exit(0)
7488
}
7589
}
90+
91+
// displayDebugLogs will return true if the "DEBUG" env var
92+
// is set to "true"
93+
func displayDebugLogs() bool {
94+
return os.Getenv("DEBUG") == "true"
95+
}

osm/error.go

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Package osm - Error codes for the adapter
2+
package osm
3+
4+
import (
5+
"fmt"
6+
7+
"github.com/layer5io/meshkit/errors"
8+
)
9+
10+
var (
11+
// Error code for failed service mesh installation
12+
13+
// ErrInstallOSMCode represents the errors which are generated
14+
// during open service mesh install process
15+
ErrInstallOSMCode = "osm_test_code"
16+
17+
// ErrTarXZFCode represents the errors which are generated
18+
// during decompressing and extracting tar.gz file
19+
ErrTarXZFCode = "osm_test_code"
20+
21+
// ErrMeshConfigCode represents the errors which are generated
22+
// when an invalid mesh config is found
23+
ErrMeshConfigCode = "osm_test_code"
24+
25+
// ErrRunOsmCtlCmdCode represents the errors which are generated
26+
// during fetch manifest process
27+
ErrRunOsmCtlCmdCode = "osm_test_code"
28+
29+
// ErrDownloadBinaryCode represents the errors which are generated
30+
// during binary download process
31+
ErrDownloadBinaryCode = "osm_test_code"
32+
33+
// ErrInstallBinaryCode represents the errors which are generated
34+
// during binary installation process
35+
ErrInstallBinaryCode = "osm_test_code"
36+
37+
// ErrSampleAppCode represents the errors which are generated
38+
// duing sample app installation
39+
ErrSampleAppCode = "osm_test_code"
40+
41+
// ErrCustomOperationCode represents the errors which are generated
42+
// when an invalid addon operation is requested
43+
ErrCustomOperationCode = "osm_test_code"
44+
45+
// ErrCreatingNSCode represents the errors which are generated
46+
// during the process of creating a namespace
47+
ErrCreatingNSCode = "osm_test_code"
48+
49+
// ErrRunExecutableCode represents the errors which are generated
50+
// during the running a executable
51+
ErrRunExecutableCode = "osm_test_code"
52+
53+
// ErrSidecarInjectionCode represents the errors which are generated
54+
// during the process of enabling/disabling sidecar injection
55+
ErrSidecarInjectionCode = "osm_test_code"
56+
57+
// ErrOpInvalid represents the errors which are generated
58+
// when an invalid operation is requested
59+
ErrOpInvalid = errors.NewDefault(errors.ErrOpInvalid, "Invalid operation")
60+
)
61+
62+
// ErrInstallOSM is the error for install mesh
63+
func ErrInstallOSM(err error) error {
64+
return errors.NewDefault(ErrInstallOSMCode, fmt.Sprintf("Error with osm operation: %s", err.Error()))
65+
}
66+
67+
// ErrTarXZF is the error for unzipping the file
68+
func ErrTarXZF(err error) error {
69+
return errors.NewDefault(ErrTarXZFCode, fmt.Sprintf("Error while extracting file: %s", err.Error()))
70+
}
71+
72+
// ErrMeshConfig is the error for mesh config
73+
func ErrMeshConfig(err error) error {
74+
return errors.NewDefault(ErrMeshConfigCode, fmt.Sprintf("Error configuration mesh: %s", err.Error()))
75+
}
76+
77+
// ErrRunOsmCtlCmd is the error for mesh port forward
78+
func ErrRunOsmCtlCmd(err error, des string) error {
79+
return errors.NewDefault(ErrRunOsmCtlCmdCode, fmt.Sprintf("Error running osmctl command: %s", des))
80+
}
81+
82+
// ErrDownloadBinary is the error while downloading osm binary
83+
func ErrDownloadBinary(err error) error {
84+
return errors.NewDefault(ErrDownloadBinaryCode, fmt.Sprintf("Error downloading osmctl binary: %s", err.Error()))
85+
}
86+
87+
// ErrInstallBinary is the error while downloading osm binary
88+
func ErrInstallBinary(err error) error {
89+
return errors.NewDefault(ErrInstallBinaryCode, fmt.Sprintf("Error installing osmctl binary: %s", err.Error()))
90+
}
91+
92+
// ErrSampleApp is the error for streaming event
93+
func ErrSampleApp(err error) error {
94+
return errors.NewDefault(ErrSampleAppCode, fmt.Sprintf("Error with sample app operation: %s", err.Error()))
95+
}
96+
97+
// ErrCustomOperation is the error for streaming event
98+
func ErrCustomOperation(err error) error {
99+
return errors.NewDefault(ErrCustomOperationCode, fmt.Sprintf("Error with custom operation: %s", err.Error()))
100+
}
101+
102+
// ErrCreatingNS is the error while creating the namespace
103+
func ErrCreatingNS(err error) error {
104+
return errors.NewDefault(ErrCreatingNSCode, fmt.Sprintf("error creating namespace: %s", err.Error()))
105+
}
106+
107+
// ErrRunExecutable is the error while running an executable
108+
func ErrRunExecutable(err error) error {
109+
return errors.NewDefault(ErrRunExecutableCode, fmt.Sprintf("error running executable: %s", err.Error()))
110+
}
111+
112+
// ErrSidecarInjection is the error while enabling/disabling sidecar injection
113+
// on a particular namespace
114+
func ErrSidecarInjection(err error) error {
115+
return errors.NewDefault(ErrSidecarInjectionCode, fmt.Sprintf("error sidecar injection: %s", err.Error()))
116+
}

0 commit comments

Comments
 (0)