Skip to content

Commit

Permalink
Merge pull request #269 from Revolyssup/Revolyssup/runtimeComponent
Browse files Browse the repository at this point in the history
added runtime component generation
  • Loading branch information
tangledbytes authored Oct 6, 2021
2 parents 491b956 + 9ec8d76 commit 7c5875c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ replace (
require (
github.com/aspenmesh/istio-vet v0.0.0-20200806222806-9c8e9a962b9f
github.com/layer5io/meshery-adapter-library v0.1.24
github.com/layer5io/meshkit v0.2.28
github.com/layer5io/meshkit v0.2.29
github.com/layer5io/service-mesh-performance v0.3.3
gopkg.in/yaml.v2 v2.4.0
istio.io/client-go v1.8.0
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,17 @@ github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6Fm
github.com/layer5io/kuttl v0.4.1-0.20200723152044-916f10574334/go.mod h1:UmrVd7x+bNVKrpmKgTtfRiTKHZeNPcMjQproJ0vGwhE=
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3e34 h1:QaViadDOBCMDUwYx78kfRvHMkzRVnh/GOhm3s2gxoP4=
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3e34/go.mod h1:BQPLwdJt7v7y0fXIejI4whR9zMyX07Wjt5xrbgEmHLw=
github.com/layer5io/meshery-adapter-library v0.1.23 h1:7eGxHJL4Ag6gU2ZBqsYrbBkQBJFv7Tcob8SZ3wgwrNI=
github.com/layer5io/meshery-adapter-library v0.1.23/go.mod h1:SLknhKksSoUtKzG2tvJKkN/DsMnGV+O+etmuj5Qew48=
github.com/layer5io/meshery-adapter-library v0.1.24 h1:3U5oIZCyfPCqVeorTUqZnOhnwcdA/gUHtsDVShhpzaU=
github.com/layer5io/meshery-adapter-library v0.1.24/go.mod h1:SLknhKksSoUtKzG2tvJKkN/DsMnGV+O+etmuj5Qew48=
github.com/layer5io/meshkit v0.2.24 h1:ILWDRmnDPtXyLiNGxn5OTu1iF/XyBDQLgz/Y8paVwsc=
github.com/layer5io/meshkit v0.2.24/go.mod h1:blHAWgbcsNJ3rjKr8YvYke8jQILV75vRaARXYwSh0YA=
github.com/layer5io/meshkit v0.2.28 h1:ZAMMRVuK2f2v+URlfgiy+uMPp99O7ygK/lrdK8GN3cc=
github.com/layer5io/meshkit v0.2.28/go.mod h1:blHAWgbcsNJ3rjKr8YvYke8jQILV75vRaARXYwSh0YA=
github.com/layer5io/meshkit v0.2.29 h1:Sdp40Jmwq78i3NAaQb6+pkaaiBTfRD+oQhOz91SAxlc=
github.com/layer5io/meshkit v0.2.29/go.mod h1:blHAWgbcsNJ3rjKr8YvYke8jQILV75vRaARXYwSh0YA=

github.com/layer5io/service-mesh-performance v0.3.2-0.20210122142912-a94e0658b021/go.mod h1:W153amv8aHAeIWxO7b7d7Vibt9RhaEVh4Uh+RG+BumQ=
github.com/layer5io/service-mesh-performance v0.3.2/go.mod h1:W153amv8aHAeIWxO7b7d7Vibt9RhaEVh4Uh+RG+BumQ=
github.com/layer5io/service-mesh-performance v0.3.3 h1:KtouYXg64y+G0soPJwDeB0sM6PXolBpkV6Ke15aqwmk=
Expand Down
53 changes: 51 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (

"github.com/layer5io/meshery-istio/istio"
"github.com/layer5io/meshkit/logger"
"github.com/layer5io/meshkit/utils/manifests"
smp "github.com/layer5io/service-mesh-performance/spec"

// "github.com/layer5io/meshkit/tracing"
"github.com/layer5io/meshery-adapter-library/adapter"
Expand Down Expand Up @@ -105,8 +107,8 @@ func main() {
service.StartedAt = time.Now()
service.Version = version
service.GitSHA = gitsha

go registerCapabilities(service.Port, log)
go registerCapabilities(service.Port, log) //Registering static capabilities
go registerDynamicCapabilities(service.Port, log) //Registering latest capabilities periodically

// Server Initialization
log.Info("Adaptor Listening at port: ", service.Port)
Expand Down Expand Up @@ -156,3 +158,50 @@ func registerCapabilities(port string, log logger.Handler) {
log.Info(err.Error())
}
}

func registerDynamicCapabilities(port string, log logger.Handler) {
registerWorkloads(port, log)
//Start the ticker
const reRegisterAfter = 24
ticker := time.NewTicker(reRegisterAfter * time.Hour)
for {
<-ticker.C
registerWorkloads(port, log)
}

}
func registerWorkloads(port string, log logger.Handler) {
release, err := config.GetLatestReleases(1)
if err != nil {
log.Info("Could not get latest stable release")
return
}
version := release[0].TagName
log.Info("Registering latest workload components for version ", version)
// Register workloads
if err := adapter.RegisterWorkLoadsDynamically(mesheryServerAddress(), serviceAddress()+":"+port, &adapter.DynamicComponentsConfig{
TimeoutInMinutes: 30,
URL: "https://raw.githubusercontent.com/istio/istio/" + version + "/manifests/charts/base/crds/crd-all.gen.yaml",
GenerationMethod: adapter.Manifests,
Config: manifests.Config{
Name: smp.ServiceMesh_Type_name[int32(smp.ServiceMesh_ISTIO)],
MeshVersion: version,
Filter: manifests.CrdFilter{
RootFilter: []string{"$[?(@.kind==\"CustomResourceDefinition\")]"},
NameFilter: []string{"$..[\"spec\"][\"names\"][\"kind\"]"},
VersionFilter: []string{"$[0]..spec.versions[0]"},
GroupFilter: []string{"$[0]..spec"},
SpecFilter: []string{"$[0]..openAPIV3Schema.properties.spec"},
ItrFilter: []string{"$[?(@.spec.names.kind"},
ItrSpecFilter: []string{"$[?(@.spec.names.kind"},
VField: "name",
GField: "group",
},
},
Operation: config.IstioOperation,
}); err != nil {
log.Info(err.Error())
return
}
log.Info("Latest workload components successfully registered.")
}

0 comments on commit 7c5875c

Please sign in to comment.