Skip to content

Commit 7c5875c

Browse files
authored
Merge pull request #269 from Revolyssup/Revolyssup/runtimeComponent
added runtime component generation
2 parents 491b956 + 9ec8d76 commit 7c5875c

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ replace (
1313
require (
1414
github.com/aspenmesh/istio-vet v0.0.0-20200806222806-9c8e9a962b9f
1515
github.com/layer5io/meshery-adapter-library v0.1.24
16-
github.com/layer5io/meshkit v0.2.28
16+
github.com/layer5io/meshkit v0.2.29
1717
github.com/layer5io/service-mesh-performance v0.3.3
1818
gopkg.in/yaml.v2 v2.4.0
1919
istio.io/client-go v1.8.0

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,17 @@ github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6Fm
570570
github.com/layer5io/kuttl v0.4.1-0.20200723152044-916f10574334/go.mod h1:UmrVd7x+bNVKrpmKgTtfRiTKHZeNPcMjQproJ0vGwhE=
571571
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3e34 h1:QaViadDOBCMDUwYx78kfRvHMkzRVnh/GOhm3s2gxoP4=
572572
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3e34/go.mod h1:BQPLwdJt7v7y0fXIejI4whR9zMyX07Wjt5xrbgEmHLw=
573+
github.com/layer5io/meshery-adapter-library v0.1.23 h1:7eGxHJL4Ag6gU2ZBqsYrbBkQBJFv7Tcob8SZ3wgwrNI=
574+
github.com/layer5io/meshery-adapter-library v0.1.23/go.mod h1:SLknhKksSoUtKzG2tvJKkN/DsMnGV+O+etmuj5Qew48=
573575
github.com/layer5io/meshery-adapter-library v0.1.24 h1:3U5oIZCyfPCqVeorTUqZnOhnwcdA/gUHtsDVShhpzaU=
574576
github.com/layer5io/meshery-adapter-library v0.1.24/go.mod h1:SLknhKksSoUtKzG2tvJKkN/DsMnGV+O+etmuj5Qew48=
577+
github.com/layer5io/meshkit v0.2.24 h1:ILWDRmnDPtXyLiNGxn5OTu1iF/XyBDQLgz/Y8paVwsc=
575578
github.com/layer5io/meshkit v0.2.24/go.mod h1:blHAWgbcsNJ3rjKr8YvYke8jQILV75vRaARXYwSh0YA=
576579
github.com/layer5io/meshkit v0.2.28 h1:ZAMMRVuK2f2v+URlfgiy+uMPp99O7ygK/lrdK8GN3cc=
577580
github.com/layer5io/meshkit v0.2.28/go.mod h1:blHAWgbcsNJ3rjKr8YvYke8jQILV75vRaARXYwSh0YA=
581+
github.com/layer5io/meshkit v0.2.29 h1:Sdp40Jmwq78i3NAaQb6+pkaaiBTfRD+oQhOz91SAxlc=
582+
github.com/layer5io/meshkit v0.2.29/go.mod h1:blHAWgbcsNJ3rjKr8YvYke8jQILV75vRaARXYwSh0YA=
583+
578584
github.com/layer5io/service-mesh-performance v0.3.2-0.20210122142912-a94e0658b021/go.mod h1:W153amv8aHAeIWxO7b7d7Vibt9RhaEVh4Uh+RG+BumQ=
579585
github.com/layer5io/service-mesh-performance v0.3.2/go.mod h1:W153amv8aHAeIWxO7b7d7Vibt9RhaEVh4Uh+RG+BumQ=
580586
github.com/layer5io/service-mesh-performance v0.3.3 h1:KtouYXg64y+G0soPJwDeB0sM6PXolBpkV6Ke15aqwmk=

main.go

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222

2323
"github.com/layer5io/meshery-istio/istio"
2424
"github.com/layer5io/meshkit/logger"
25+
"github.com/layer5io/meshkit/utils/manifests"
26+
smp "github.com/layer5io/service-mesh-performance/spec"
2527

2628
// "github.com/layer5io/meshkit/tracing"
2729
"github.com/layer5io/meshery-adapter-library/adapter"
@@ -105,8 +107,8 @@ func main() {
105107
service.StartedAt = time.Now()
106108
service.Version = version
107109
service.GitSHA = gitsha
108-
109-
go registerCapabilities(service.Port, log)
110+
go registerCapabilities(service.Port, log) //Registering static capabilities
111+
go registerDynamicCapabilities(service.Port, log) //Registering latest capabilities periodically
110112

111113
// Server Initialization
112114
log.Info("Adaptor Listening at port: ", service.Port)
@@ -156,3 +158,50 @@ func registerCapabilities(port string, log logger.Handler) {
156158
log.Info(err.Error())
157159
}
158160
}
161+
162+
func registerDynamicCapabilities(port string, log logger.Handler) {
163+
registerWorkloads(port, log)
164+
//Start the ticker
165+
const reRegisterAfter = 24
166+
ticker := time.NewTicker(reRegisterAfter * time.Hour)
167+
for {
168+
<-ticker.C
169+
registerWorkloads(port, log)
170+
}
171+
172+
}
173+
func registerWorkloads(port string, log logger.Handler) {
174+
release, err := config.GetLatestReleases(1)
175+
if err != nil {
176+
log.Info("Could not get latest stable release")
177+
return
178+
}
179+
version := release[0].TagName
180+
log.Info("Registering latest workload components for version ", version)
181+
// Register workloads
182+
if err := adapter.RegisterWorkLoadsDynamically(mesheryServerAddress(), serviceAddress()+":"+port, &adapter.DynamicComponentsConfig{
183+
TimeoutInMinutes: 30,
184+
URL: "https://raw.githubusercontent.com/istio/istio/" + version + "/manifests/charts/base/crds/crd-all.gen.yaml",
185+
GenerationMethod: adapter.Manifests,
186+
Config: manifests.Config{
187+
Name: smp.ServiceMesh_Type_name[int32(smp.ServiceMesh_ISTIO)],
188+
MeshVersion: version,
189+
Filter: manifests.CrdFilter{
190+
RootFilter: []string{"$[?(@.kind==\"CustomResourceDefinition\")]"},
191+
NameFilter: []string{"$..[\"spec\"][\"names\"][\"kind\"]"},
192+
VersionFilter: []string{"$[0]..spec.versions[0]"},
193+
GroupFilter: []string{"$[0]..spec"},
194+
SpecFilter: []string{"$[0]..openAPIV3Schema.properties.spec"},
195+
ItrFilter: []string{"$[?(@.spec.names.kind"},
196+
ItrSpecFilter: []string{"$[?(@.spec.names.kind"},
197+
VField: "name",
198+
GField: "group",
199+
},
200+
},
201+
Operation: config.IstioOperation,
202+
}); err != nil {
203+
log.Info(err.Error())
204+
return
205+
}
206+
log.Info("Latest workload components successfully registered.")
207+
}

0 commit comments

Comments
 (0)