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

Commit

Permalink
Merge pull request #127 from Revolyssup/usemeshkitfunc
Browse files Browse the repository at this point in the history
Usemeshkitfunc
  • Loading branch information
leecalcote authored Dec 31, 2021
2 parents ede901f + 26844f7 commit 99273f4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 80 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ replace github.com/kudobuilder/kuttl => github.com/layer5io/kuttl v0.4.1-0.20200

require (
github.com/layer5io/meshery-adapter-library v0.1.23
github.com/layer5io/meshkit v0.2.33
github.com/layer5io/meshkit v0.2.36
github.com/layer5io/service-mesh-performance v0.3.3
gopkg.in/yaml.v2 v2.4.0
k8s.io/apimachinery v0.21.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ github.com/layer5io/meshery-adapter-library v0.1.23/go.mod h1:SLknhKksSoUtKzG2tv
github.com/layer5io/meshkit v0.2.24/go.mod h1:blHAWgbcsNJ3rjKr8YvYke8jQILV75vRaARXYwSh0YA=
github.com/layer5io/meshkit v0.2.33 h1:YRCGiKauuPlJvofLxVwtzEbpWP9y+FbAZXp/FJUPyXc=
github.com/layer5io/meshkit v0.2.33/go.mod h1:2o6I6N7XmupMvJRb1gqlRBIf51GIUqwCzPCGarZxIRU=
github.com/layer5io/meshkit v0.2.36 h1:qBcwRP6WrJS0ExfxGqtd55mNxyODgDHVdu/xMrho71A=
github.com/layer5io/meshkit v0.2.36/go.mod h1:2o6I6N7XmupMvJRb1gqlRBIf51GIUqwCzPCGarZxIRU=
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
12 changes: 8 additions & 4 deletions internal/config/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/layer5io/meshery-adapter-library/adapter"
"github.com/layer5io/meshery-adapter-library/meshes"
"github.com/layer5io/meshkit/utils"
smp "github.com/layer5io/service-mesh-performance/spec"
)

Expand All @@ -15,12 +16,15 @@ var (
)

func getOperations(op adapter.Operations) adapter.Operations {
versions, _ := getLatestReleaseNames(3)

var adapterVersions []adapter.Version
versions, _ := utils.GetLatestReleaseTagsSorted("openservicemesh", "osm")
for _, v := range versions {
adapterVersions = append(adapterVersions, adapter.Version(v))
}
op[OSMOperation] = &adapter.Operation{
Type: int32(meshes.OpCategory_INSTALL),
Description: "Open Service Mesh",
Versions: versions,
Versions: adapterVersions,
Templates: []adapter.Template{
"templates/open_service_mesh.yaml",
},
Expand All @@ -29,7 +33,7 @@ func getOperations(op adapter.Operations) adapter.Operations {
op[OSMBookStoreOperation] = &adapter.Operation{
Type: int32(meshes.OpCategory_SAMPLE_APPLICATION),
Description: "Bookstore Application",
Versions: versions,
Versions: adapterVersions,
Templates: []adapter.Template{
"https://raw.githubusercontent.com/openservicemesh/osm/release-v0.6/docs/example/manifests/apps/bookbuyer.yaml",
"https://raw.githubusercontent.com/openservicemesh/osm/release-v0.6/docs/example/manifests/apps/bookstore-v1.yaml",
Expand Down
73 changes: 0 additions & 73 deletions internal/config/releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
package config

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"regexp"
"sort"
"sync"

"github.com/layer5io/meshery-adapter-library/adapter"
Expand All @@ -43,73 +37,6 @@ type Asset struct {
DownloadURL string `json:"browser_download_url,omitempty"`
}

// getLatestReleaseNames returns the names of the latest releases
// limited by the "limit" parameter. It filters out all the rc
// releases and sorts the result lexographically (descending)
func getLatestReleaseNames(limit int) ([]adapter.Version, error) {
releases, err := GetLatestReleases(30)
if err != nil {
return []adapter.Version{}, ErrGetLatestReleaseNames(err)
}

// Filter out the rc releases
result := make([]adapter.Version, limit)
r, err := regexp.Compile(`\d+(\.\d+){2,}$`)
if err != nil {
return []adapter.Version{}, ErrGetLatestReleaseNames(err)
}

for _, release := range releases {
versionStr := string(release.Name)
if r.MatchString(versionStr) {
result = append(result, adapter.Version(versionStr))
}
}

// Sort the result
sort.Slice(result, func(i, j int) bool {
return result[i] > result[j]
})

if limit > len(result) {
limit = len(result)
}

return result[:limit], nil
}

// GetLatestReleases fetches the latest releases from the traefik mesh repository
func GetLatestReleases(releases uint) ([]*Release, error) {
releaseAPIURL := "https://api.github.com/repos/openservicemesh/osm/releases?per_page=" + fmt.Sprint(releases)
// We need a variable url here hence using nosec
// #nosec
resp, err := http.Get(releaseAPIURL)
if err != nil {
return []*Release{}, ErrGetLatestReleases(err)
}

if resp.StatusCode != http.StatusOK {
return []*Release{}, ErrGetLatestReleases(fmt.Errorf("unexpected status code: %d", resp.StatusCode))
}

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return []*Release{}, ErrGetLatestReleases(err)
}

var releaseList []*Release

if err = json.Unmarshal(body, &releaseList); err != nil {
return []*Release{}, ErrGetLatestReleases(err)
}

if err = resp.Body.Close(); err != nil {
return []*Release{}, ErrGetLatestReleases(err)
}

return releaseList, nil
}

func appendThreadSafe(arr *[]string, s string, m *sync.RWMutex) {
m.Lock()
defer m.Unlock()
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ func registerWorkloads(port string, log logger.Handler) {
return
}
log.Info("CRD names fetched successfully")
rel, err := config.GetLatestReleases(1)
appVersions, err := utils.GetLatestReleaseTagsSorted("openservicemesh", "osm")
if err != nil {
log.Info("Could not get latest version ", err.Error())
return
}
appVersion := rel[0].TagName
appVersion := appVersions[len(appVersions)-1]
log.Info("Registering latest workload components for version ", appVersion)
// Register workloads
for _, manifest := range crds {
Expand Down

0 comments on commit 99273f4

Please sign in to comment.