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

Commit edc2f0c

Browse files
authored
Merge pull request #210 from gr455/meshmodel-components
Add Meshmodel support
2 parents 1bd3de6 + 979fa53 commit edc2f0c

File tree

2,348 files changed

+125305
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,348 files changed

+125305
-13
lines changed

build/config.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package build
22

33
import (
4+
"encoding/json"
5+
"fmt"
6+
"io"
47
"os"
58
"path/filepath"
69
"strings"
@@ -16,12 +19,21 @@ import (
1619
var DefaultGenerationMethod string
1720
var LatestVersion string
1821
var WorkloadPath string
22+
var MeshModelPath string
1923
var CRDnames []string
2024
var OverrideURL string
2125
var AllVersions []string
2226

2327
const Component = "OSM"
2428

29+
var meshmodelmetadata = make(map[string]interface{})
30+
31+
var MeshModelConfig = adapter.MeshModelConfig{ //Move to build/config.go
32+
Category: "Orchestration & Management",
33+
SubCategory: "Service Mesh",
34+
Metadata: meshmodelmetadata,
35+
}
36+
2537
// NewConfig creates the configuration for creating components
2638
func NewConfig(version string) manifests.Config {
2739
return manifests.Config{
@@ -48,7 +60,18 @@ func GetDefaultURL(crd string) string {
4860
}
4961
func init() {
5062
wd, _ := os.Getwd()
63+
f, _ := os.Open("./build/meshmodel_metadata.json")
64+
defer func() {
65+
err := f.Close()
66+
if err != nil {
67+
fmt.Println(err.Error())
68+
}
69+
}()
70+
byt, _ := io.ReadAll(f)
71+
72+
_ = json.Unmarshal(byt, &meshmodelmetadata)
5173
WorkloadPath = filepath.Join(wd, "templates", "oam", "workloads")
74+
MeshModelPath = filepath.Join(wd, "templates", "meshmodel", "components")
5275
AllVersions, _ = utils.GetLatestReleaseTagsSorted("openservicemesh", "osm")
5376
if len(AllVersions) == 0 {
5477
return

build/meshmodel_component.json

Lines changed: 7 additions & 0 deletions
Large diffs are not rendered by default.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ replace (
1010

1111
require (
1212
github.com/google/uuid v1.3.0
13-
github.com/layer5io/meshery-adapter-library v0.6.0
14-
github.com/layer5io/meshkit v0.6.15
13+
github.com/layer5io/meshery-adapter-library v0.6.3
14+
github.com/layer5io/meshkit v0.6.16
1515
github.com/layer5io/service-mesh-performance v0.3.4
1616
gopkg.in/yaml.v2 v2.4.0
1717
k8s.io/apimachinery v0.25.3

go.sum

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -628,10 +628,12 @@ github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6Fm
628628
github.com/layer5io/kuttl v0.4.1-0.20200806180306-b7e46afd657f/go.mod h1:UmrVd7x+bNVKrpmKgTtfRiTKHZeNPcMjQproJ0vGwhE=
629629
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3e34 h1:QaViadDOBCMDUwYx78kfRvHMkzRVnh/GOhm3s2gxoP4=
630630
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3e34/go.mod h1:BQPLwdJt7v7y0fXIejI4whR9zMyX07Wjt5xrbgEmHLw=
631-
github.com/layer5io/meshery-adapter-library v0.6.0 h1:Tg3/e7qqVDOWtj1ZHEq8/dvQ/MG7Ebg5Q3dS6qvA0Is=
632-
github.com/layer5io/meshery-adapter-library v0.6.0/go.mod h1:uEAy+N9/50nnmH3kdTU+J1ZaKAn5ajL4hSHyQYHeasM=
633-
github.com/layer5io/meshkit v0.6.15 h1:W6eaIPZrccYjtewjQHfZS9xKZrIGsv5dX3IZfj5Zr/k=
634-
github.com/layer5io/meshkit v0.6.15/go.mod h1:9ZXmiP0dxRCNlVYgchrOnfFcNrdHVXuayiuN8RRTQ68=
631+
github.com/layer5io/meshery-adapter-library v0.6.3 h1:5tsbgrB1q84X2rM1TsRVe3pSBZ8kztjo4lPsHuPBe/Y=
632+
github.com/layer5io/meshery-adapter-library v0.6.3/go.mod h1:x9/295iLiWab88uOwjgyZbJTX8aqkxfUlVZhqQKabew=
633+
github.com/layer5io/meshkit v0.6.11 h1:VS2k34BALzYzHbsikyqii7J/v9bDKC4QdfHjeBgocnU=
634+
github.com/layer5io/meshkit v0.6.11/go.mod h1:9ZXmiP0dxRCNlVYgchrOnfFcNrdHVXuayiuN8RRTQ68=
635+
github.com/layer5io/meshkit v0.6.16 h1:bU9Q4Fl31yPqPjNJkf91wT7bM5LtLh+7P0eQix9f22I=
636+
github.com/layer5io/meshkit v0.6.16/go.mod h1:9ZXmiP0dxRCNlVYgchrOnfFcNrdHVXuayiuN8RRTQ68=
635637
github.com/layer5io/service-mesh-performance v0.3.2-0.20210122142912-a94e0658b021/go.mod h1:W153amv8aHAeIWxO7b7d7Vibt9RhaEVh4Uh+RG+BumQ=
636638
github.com/layer5io/service-mesh-performance v0.3.4 h1:aw/elsx0wkry7SyiQRIj31wW7TPCP4YfhINdNOLXVg8=
637639
github.com/layer5io/service-mesh-performance v0.3.4/go.mod h1:W153amv8aHAeIWxO7b7d7Vibt9RhaEVh4Uh+RG+BumQ=

main.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strings"
2323
"time"
2424

25+
"github.com/google/uuid"
2526
"github.com/layer5io/meshery-adapter-library/adapter"
2627
"github.com/layer5io/meshery-adapter-library/api/grpc"
2728
"github.com/layer5io/meshery-osm/build"
@@ -38,6 +39,7 @@ var (
3839
serviceName = "osm-adapter"
3940
version = "edge"
4041
gitsha = "none"
42+
instanceID = uuid.NewString()
4143
)
4244

4345
func main() {
@@ -139,6 +141,11 @@ func registerCapabilities(port string, log logger.Handler) {
139141
if err := oam.RegisterTraits(mesheryServerAddress(), serviceAddress()+":"+port); err != nil {
140142
log.Info(err.Error())
141143
}
144+
145+
// Register meshmodel components
146+
if err := oam.RegisterMeshModelComponents(instanceID, mesheryServerAddress(), serviceAddress(), port); err != nil {
147+
log.Info(err.Error())
148+
}
142149
}
143150

144151
func registerDynamicCapabilities(port string, log logger.Handler) {
@@ -174,11 +181,13 @@ func registerWorkloads(port string, log logger.Handler) {
174181
for _, crd := range build.CRDnames {
175182
log.Info("Generating components for ", crd)
176183
if err := adapter.CreateComponents(adapter.StaticCompConfig{
177-
URL: build.GetDefaultURL(crd),
178-
Method: gm,
179-
Path: build.WorkloadPath,
180-
DirName: version,
181-
Config: build.NewConfig(version),
184+
URL: build.GetDefaultURL(crd),
185+
Method: gm,
186+
OAMPath: build.WorkloadPath,
187+
MeshModelPath: build.MeshModelPath,
188+
MeshModelConfig: build.MeshModelConfig,
189+
DirName: version,
190+
Config: build.NewConfig(version),
182191
}); err != nil {
183192
log.Error(err)
184193
return

osm/oam/register.go

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,59 @@ import (
44
"fmt"
55
"os"
66
"path/filepath"
7+
"strconv"
78
"strings"
9+
"sync"
810

911
"github.com/layer5io/meshery-adapter-library/adapter"
1012
"github.com/layer5io/meshery-osm/internal/config"
13+
"github.com/layer5io/meshkit/models/meshmodel/core/types"
1114
)
1215

1316
var (
1417
basePath, _ = os.Getwd()
1518
//WorkloadPath will be used by both static and component generation
16-
WorkloadPath = filepath.Join(basePath, "templates", "oam", "workloads")
17-
traitPath = filepath.Join(basePath, "templates", "oam", "traits")
19+
WorkloadPath = filepath.Join(basePath, "templates", "oam", "workloads")
20+
MeshmodelComponents = filepath.Join(basePath, "templates", "meshmodel", "components")
21+
traitPath = filepath.Join(basePath, "templates", "oam", "traits")
1822
)
1923

2024
// AvailableVersions denote the component versions available statically
2125
var AvailableVersions = map[string]bool{}
2226
var pathSets []schemaDefinitionPathSet
27+
var availableVersionGlobalMutex sync.Mutex
2328

2429
type schemaDefinitionPathSet struct {
2530
oamDefinitionPath string
2631
jsonSchemaPath string
2732
name string
2833
}
2934

35+
type meshmodelDefinitionPathSet struct {
36+
meshmodelDefinitionPath string
37+
}
38+
39+
func RegisterMeshModelComponents(uuid, runtime, host, port string) error {
40+
meshmodelRDP := []adapter.MeshModelRegistrantDefinitionPath{}
41+
pathSets, err := loadMeshmodelComponents(MeshmodelComponents)
42+
if err != nil {
43+
return err
44+
}
45+
portint, _ := strconv.Atoi(port)
46+
for _, pathSet := range pathSets {
47+
meshmodelRDP = append(meshmodelRDP, adapter.MeshModelRegistrantDefinitionPath{
48+
EntityDefintionPath: pathSet.meshmodelDefinitionPath,
49+
Host: host,
50+
Port: portint,
51+
Type: types.ComponentDefinition,
52+
})
53+
}
54+
55+
return adapter.
56+
NewMeshModelRegistrant(meshmodelRDP, fmt.Sprintf("%s/api/meshmodel/components/register", runtime)).
57+
Register(uuid)
58+
}
59+
3060
// RegisterWorkloads will register all of the workload definitions
3161
// present in the path oam/workloads
3262
//
@@ -86,6 +116,31 @@ func RegisterTraits(runtime, host string) error {
86116
Register()
87117
}
88118

119+
func loadMeshmodelComponents(basepath string) ([]meshmodelDefinitionPathSet, error) {
120+
res := []meshmodelDefinitionPathSet{}
121+
if err := filepath.Walk(basepath, func(path string, info os.FileInfo, err error) error {
122+
if err != nil {
123+
return err
124+
}
125+
126+
if info.IsDir() {
127+
return nil
128+
}
129+
130+
res = append(res, meshmodelDefinitionPathSet{
131+
meshmodelDefinitionPath: path,
132+
})
133+
availableVersionGlobalMutex.Lock()
134+
AvailableVersions[filepath.Base(filepath.Dir(path))] = true // Getting available versions already existing on file system
135+
availableVersionGlobalMutex.Unlock()
136+
return nil
137+
}); err != nil {
138+
return nil, err
139+
}
140+
141+
return res, nil
142+
}
143+
89144
func load(basePath string) ([]schemaDefinitionPathSet, error) {
90145
res := []schemaDefinitionPathSet{}
91146

@@ -108,7 +163,9 @@ func load(basePath string) ([]schemaDefinitionPathSet, error) {
108163
jsonSchemaPath: fmt.Sprintf("%s.meshery.layer5io.schema.json", nameWithPath),
109164
name: filepath.Base(nameWithPath),
110165
})
166+
availableVersionGlobalMutex.Lock()
111167
AvailableVersions[filepath.Base(filepath.Dir(path))] = true
168+
availableVersionGlobalMutex.Unlock()
112169
}
113170

114171
return nil

templates/meshmodel/components/v0.0.1/egress.OSM.meshery.layer5.io_meshmodel.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

templates/meshmodel/components/v0.0.1/extensionservice.OSM.meshery.layer5.io_meshmodel.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

templates/meshmodel/components/v0.0.1/httproutegroup.OSM.meshery.layer5.io_meshmodel.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

templates/meshmodel/components/v0.0.1/ingressbackend.OSM.meshery.layer5.io_meshmodel.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)