diff --git a/go.mod b/go.mod index 7f421a7..4f8df31 100644 --- a/go.mod +++ b/go.mod @@ -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.25 - github.com/layer5io/meshkit v0.2.34 + github.com/layer5io/meshkit v0.2.36 github.com/layer5io/service-mesh-performance v0.3.3 golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f // indirect golang.org/x/sys v0.0.0-20210903071746-97244b99971b // indirect diff --git a/go.sum b/go.sum index 6f0a11e..b7305af 100644 --- a/go.sum +++ b/go.sum @@ -621,6 +621,10 @@ github.com/layer5io/meshery-adapter-library v0.1.25/go.mod h1:SLknhKksSoUtKzG2tv github.com/layer5io/meshkit v0.2.24/go.mod h1:blHAWgbcsNJ3rjKr8YvYke8jQILV75vRaARXYwSh0YA= github.com/layer5io/meshkit v0.2.34 h1:bpYMDXVV/935+kA3hp4boXzjuFpPh7oqM0MOvlQdTZM= github.com/layer5io/meshkit v0.2.34/go.mod h1:2o6I6N7XmupMvJRb1gqlRBIf51GIUqwCzPCGarZxIRU= +github.com/layer5io/meshkit v0.2.35 h1:94Xu9ql04J95JwQKCcXuF/qprYc8SRy4M/T6L/7vg2M= +github.com/layer5io/meshkit v0.2.35/go.mod h1:+Jjrktq2gvW91c3bDnonWWismXI8SvJuyOKiSpejIyE= +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= diff --git a/internal/config/operation.go b/internal/config/operation.go index 7291e10..fd25f6c 100644 --- a/internal/config/operation.go +++ b/internal/config/operation.go @@ -3,6 +3,7 @@ package config import ( "github.com/layer5io/meshery-adapter-library/adapter" "github.com/layer5io/meshery-adapter-library/meshes" + "github.com/layer5io/meshkit/utils" ) var ( @@ -10,13 +11,16 @@ var ( ) func getOperations(dev adapter.Operations) adapter.Operations { + var adapterersions []adapter.Version + versions, _ := utils.GetLatestReleaseTagsSorted("aws", "aws-app-mesh-controller-for-k8s") - versions, _ := getLatestReleaseNames(3) - + for _, v := range versions { + adapterersions = append(adapterersions, adapter.Version(v)) + } dev[AppMeshOperation] = &adapter.Operation{ Type: int32(meshes.OpCategory_INSTALL), Description: "AWS App Mesh", - Versions: versions, + Versions: adapterersions, } dev[LabelNamespace] = &adapter.Operation{ diff --git a/internal/config/releases.go b/internal/config/releases.go index 2bae7c4..f00d21d 100644 --- a/internal/config/releases.go +++ b/internal/config/releases.go @@ -1,11 +1,6 @@ package config import ( - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "github.com/layer5io/meshery-adapter-library/adapter" ) @@ -24,58 +19,3 @@ type Asset struct { State string `json:"state,omitempty"` 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 alpha -// rc releases and sorts the result lexographically (descending) -func getLatestReleaseNames(limit int) ([]adapter.Version, error) { - releases, err := GetLatestReleases(uint(limit)) - if err != nil { - return []adapter.Version{}, ErrGetLatestReleaseNames(err) - } - - var releaseNames []adapter.Version - - for _, r := range releases { - releaseNames = append(releaseNames, adapter.Version(r.TagName)) - } - - // Ensure that limit is always lesser than equal to the total - // number of releases - if limit > len(releaseNames) { - limit = len(releaseNames) - } - return releaseNames, nil -} - -// GetLatestReleases fetches the latest releases from the aws/aws-app-mesh-controller-for-k8s repository -func GetLatestReleases(releases uint) ([]*Release, error) { - releaseAPIURL := "https://api.github.com/repos/aws/aws-app-mesh-controller-for-k8s/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 -} diff --git a/main.go b/main.go index 1fa1682..4a88611 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ import ( "github.com/layer5io/meshery-app-mesh/appmesh" "github.com/layer5io/meshery-app-mesh/internal/config" "github.com/layer5io/meshkit/logger" + "github.com/layer5io/meshkit/utils" "github.com/layer5io/meshkit/utils/manifests" // "github.com/layer5io/meshkit/tracing" @@ -138,16 +139,16 @@ func registerDynamicCapabilities(port string, log logger.Handler) { } func registerWorkloads(port string, log logger.Handler) { - release, err := config.GetLatestReleases(1) + versions, err := utils.GetLatestReleaseTagsSorted("aws", "aws-app-mesh-controller-for-k8s") if err != nil { log.Info("Could not get latest stable release") } - var version string - if len(release) > 0 { - version = release[0].TagName - } else { - version = "Unknown" //The registration should continue even if the version could not have been found because the URL is independent of it + if len(versions) == 0 { + log.Info("Could not register dynamic components.Latest version could not found") + return } + version := versions[len(versions)-1] + if oam.AvailableVersions[version] { log.Info("Latest(", version, ") component already available via static component generation\n") log.Info("Skipping dynamic component registeration") diff --git a/templates/oam/workloads/workloads-v1.4.2/gatewayroute.appmesh.meshery.layer5io.schema.json b/templates/oam/workloads/v1.4.2/gatewayroute.appmesh.meshery.layer5io.schema.json similarity index 100% rename from templates/oam/workloads/workloads-v1.4.2/gatewayroute.appmesh.meshery.layer5io.schema.json rename to templates/oam/workloads/v1.4.2/gatewayroute.appmesh.meshery.layer5io.schema.json diff --git a/templates/oam/workloads/workloads-v1.4.2/gatewayroute.appmesh_definition.json b/templates/oam/workloads/v1.4.2/gatewayroute.appmesh_definition.json similarity index 100% rename from templates/oam/workloads/workloads-v1.4.2/gatewayroute.appmesh_definition.json rename to templates/oam/workloads/v1.4.2/gatewayroute.appmesh_definition.json diff --git a/templates/oam/workloads/workloads-v1.4.2/mesh.appmesh.meshery.layer5io.schema.json b/templates/oam/workloads/v1.4.2/mesh.appmesh.meshery.layer5io.schema.json similarity index 100% rename from templates/oam/workloads/workloads-v1.4.2/mesh.appmesh.meshery.layer5io.schema.json rename to templates/oam/workloads/v1.4.2/mesh.appmesh.meshery.layer5io.schema.json diff --git a/templates/oam/workloads/workloads-v1.4.2/mesh.appmesh_definition.json b/templates/oam/workloads/v1.4.2/mesh.appmesh_definition.json similarity index 100% rename from templates/oam/workloads/workloads-v1.4.2/mesh.appmesh_definition.json rename to templates/oam/workloads/v1.4.2/mesh.appmesh_definition.json diff --git a/templates/oam/workloads/workloads-v1.4.2/virtualgateway.appmesh.meshery.layer5io.schema.json b/templates/oam/workloads/v1.4.2/virtualgateway.appmesh.meshery.layer5io.schema.json similarity index 100% rename from templates/oam/workloads/workloads-v1.4.2/virtualgateway.appmesh.meshery.layer5io.schema.json rename to templates/oam/workloads/v1.4.2/virtualgateway.appmesh.meshery.layer5io.schema.json diff --git a/templates/oam/workloads/workloads-v1.4.2/virtualgateway.appmesh_definition.json b/templates/oam/workloads/v1.4.2/virtualgateway.appmesh_definition.json similarity index 100% rename from templates/oam/workloads/workloads-v1.4.2/virtualgateway.appmesh_definition.json rename to templates/oam/workloads/v1.4.2/virtualgateway.appmesh_definition.json diff --git a/templates/oam/workloads/workloads-v1.4.2/virtualnode.appmesh.meshery.layer5io.schema.json b/templates/oam/workloads/v1.4.2/virtualnode.appmesh.meshery.layer5io.schema.json similarity index 100% rename from templates/oam/workloads/workloads-v1.4.2/virtualnode.appmesh.meshery.layer5io.schema.json rename to templates/oam/workloads/v1.4.2/virtualnode.appmesh.meshery.layer5io.schema.json diff --git a/templates/oam/workloads/workloads-v1.4.2/virtualnode.appmesh_definition.json b/templates/oam/workloads/v1.4.2/virtualnode.appmesh_definition.json similarity index 100% rename from templates/oam/workloads/workloads-v1.4.2/virtualnode.appmesh_definition.json rename to templates/oam/workloads/v1.4.2/virtualnode.appmesh_definition.json diff --git a/templates/oam/workloads/workloads-v1.4.2/virtualrouter.appmesh.meshery.layer5io.schema.json b/templates/oam/workloads/v1.4.2/virtualrouter.appmesh.meshery.layer5io.schema.json similarity index 100% rename from templates/oam/workloads/workloads-v1.4.2/virtualrouter.appmesh.meshery.layer5io.schema.json rename to templates/oam/workloads/v1.4.2/virtualrouter.appmesh.meshery.layer5io.schema.json diff --git a/templates/oam/workloads/workloads-v1.4.2/virtualrouter.appmesh_definition.json b/templates/oam/workloads/v1.4.2/virtualrouter.appmesh_definition.json similarity index 100% rename from templates/oam/workloads/workloads-v1.4.2/virtualrouter.appmesh_definition.json rename to templates/oam/workloads/v1.4.2/virtualrouter.appmesh_definition.json diff --git a/templates/oam/workloads/workloads-v1.4.2/virtualservice.appmesh.meshery.layer5io.schema.json b/templates/oam/workloads/v1.4.2/virtualservice.appmesh.meshery.layer5io.schema.json similarity index 100% rename from templates/oam/workloads/workloads-v1.4.2/virtualservice.appmesh.meshery.layer5io.schema.json rename to templates/oam/workloads/v1.4.2/virtualservice.appmesh.meshery.layer5io.schema.json diff --git a/templates/oam/workloads/workloads-v1.4.2/virtualservice.appmesh_definition.json b/templates/oam/workloads/v1.4.2/virtualservice.appmesh_definition.json similarity index 100% rename from templates/oam/workloads/workloads-v1.4.2/virtualservice.appmesh_definition.json rename to templates/oam/workloads/v1.4.2/virtualservice.appmesh_definition.json