This repository has been archived by the owner on Sep 27, 2023. It is now read-only.
generated from meshery/meshery-adapter-template
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add build time and modify run time comp generation
Signed-off-by: ashish <[email protected]>
- Loading branch information
1 parent
5d98a12
commit 7ccde37
Showing
815 changed files
with
45,211 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,12 @@ | ||
name: Meshery Open Service Mesh Pattern Components Generator | ||
name: Meshery OSM Pattern Components Generator | ||
on: | ||
push: | ||
branches: | ||
- "master" | ||
- 'master' | ||
schedule: | ||
- cron: "0 0 * * *" | ||
jobs: | ||
check_osm_version: | ||
name: Check OSM Version | ||
runs-on: ubuntu-latest | ||
outputs: | ||
NEW_OSM_VERSION: ${{ steps.glrt.outputs.release }} | ||
EXISTS: ${{ env.EXISTS }} | ||
steps: | ||
- name: Get latest release tag | ||
id: glrt | ||
uses: pozetroninc/github-action-get-latest-release@master | ||
with: | ||
repository: openservicemesh/osm | ||
excludes: prerelease, draft | ||
- name: Check out code | ||
uses: actions/checkout@master | ||
with: | ||
fetch-depth: 1 | ||
- name: Check if manifests for latest release exist | ||
run: | | ||
if [ -d templates/oam/workloads/workloads-${{ steps.glrt.outputs.release }} ] | ||
then | ||
echo "EXISTS=true" > $GITHUB_ENV | ||
else | ||
export "EXISTS=false" > $GITHUB_ENV | ||
fi | ||
generator: | ||
name: Generate and push OAM definitions | ||
needs: [check_osm_version] | ||
if: ${{ !needs.check_osm_version.outputs.EXISTS }} | ||
env: | ||
NEW_OSM_VERSION: ${{ needs.check_osm_version.outputs.NEW_OSM_VERSION }} | ||
GenerateComponents: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out code | ||
|
@@ -43,55 +15,23 @@ jobs: | |
fetch-depth: 1 | ||
token: ${{ secrets.GH_ACCESS_TOKEN }} | ||
ref: "master" | ||
- name: Get OSM manifests | ||
run: | | ||
mkdir ./osm-crds | ||
cd ./osm-crds | ||
curl --remote-name-all `curl -H "Accept: application/vnd.github.VERSION.raw" https://api.github.com/repos/openservicemesh/osm/contents/cmd/osm-bootstrap/crds\?ref\=$NEW_OSM_VERSION | jq 'map(.download_url) | .[]' | tr -d '"'` | ||
cd .. | ||
awk 'FNR==1 && NR>1 { printf("\n%s\n\n","---") } 1' osm-crds/*.yaml > ~/osm.yaml | ||
- name: Build jsonschema util | ||
run: | | ||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash | ||
export NVM_DIR="$HOME/.nvm" | ||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm | ||
nvm install v14.15.3 | ||
nvm install-latest-npm | ||
git clone https://github.com/layer5io/kubeopenapi-jsonschema util | ||
cd util | ||
npm i; npm i nexe -g | ||
make linux | ||
- name: Generate Workload definitions | ||
- name: Setup Go | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: 1.17 | ||
- name: Run adapter to create components | ||
run: | | ||
dirPath=../templates/oam/workloads/workloads-$NEW_OSM_VERSION | ||
cd util | ||
mkdir -p $dirPath | ||
meshName=osm | ||
smpMeshName=OPEN_SERVICE_MESH | ||
template='{"apiVersion":"core.oam.dev/v1alpha1","kind":"WorkloadDefinition","metadata":{},"spec":{"definitionRef":{},"metadata":{"@type":"pattern.meshery.io/mesh/workload","meshVersion":"'$NEW_OSM_VERSION'","meshName":"'$smpMeshName'","k8sAPIVersion":null,"k8sKind":""}}}' | ||
crds=$(./kubeopenapi-jsonschema --location ~/osm.yaml -t yaml --filter '$[?(@.kind=="CustomResourceDefinition")]' -o json --o-filter '$..["spec"]["names"]["kind"]' | jq '.[]') | ||
for t in ${crds[@]}; do | ||
nameUpper=`echo $t | tr -d '"'` | ||
nameLower=`echo $t | tr -d '"' | tr '[:upper:]' '[:lower:]'` | ||
definitionRef=$(printf %s.osm.meshery.layer5.io $nameLower) | ||
apiVersion=$(./kubeopenapi-jsonschema --location ~/osm.yaml -t yaml --filter '$[?(@.kind=="CustomResourceDefinition" && @.spec.names.kind=='$t')]..spec.versions[0]' --o-filter "$[].name" -o json | jq '.[]' | tr -d '"') | ||
apiGroup=$(./kubeopenapi-jsonschema --location ~/osm.yaml -t yaml --filter '$[?(@.kind=="CustomResourceDefinition" && @.spec.names.kind=='$t')]..spec' --o-filter "$[].group" -o json | jq '.[]' | tr -d '"') | ||
./kubeopenapi-jsonschema --location ~/osm.yaml -t yaml --filter '$[?(@.kind=="CustomResourceDefinition" && @.spec.names.kind=='$t')]..openAPIV3Schema.properties.spec' --o-filter "$[]" -o json |\ | ||
jq ' | ||
.[] | ||
| .version = "'$NEW_OSM_VERSION'" | ||
| ."object-type" = "'$nameUpper'" | ||
| ."service-mesh" = "'$meshName'" ' > $dirPath/$nameLower.osm.meshery.layer5io.schema.json | ||
echo $template |\ | ||
jq ' | ||
."metadata"."name" = "'$(printf %s.OSM $nameUpper)'" | ||
| ."spec"."metadata"."k8sAPIVersion" = "'$(printf $apiGroup/$apiVersion $apiGroup $apiVersion)'" | ||
| ."spec"."metadata"."k8sKind" = "'$nameUpper'" | ||
| ."spec"."definitionRef"."name"="'$definitionRef'"' > $dirPath/$nameLower.osm_definition.json | ||
touch log.txt | ||
mkdir -p ~/.meshery/bin | ||
(FORCE_DYNAMIC_REG=true DEBUG=true go run main.go > log.txt 2>&1) & | ||
end=$((SECONDS+300)) | ||
while [ $SECONDS -lt $end ]; do | ||
if [ "$(cat log.txt | grep "Component Creation completed for version")" != "" ];then | ||
echo "New components created" | ||
break | ||
fi | ||
done | ||
- name: Cleanup | ||
run: | | ||
rm -rf util | ||
rm log.txt | ||
- name: Commit changes | ||
uses: stefanzweifel/git-auto-commit-action@v4 | ||
with: | ||
|
@@ -100,5 +40,5 @@ jobs: | |
commit_user_email: [email protected] | ||
commit_author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> | ||
commit_options: "--signoff" | ||
commit_message: "[Patterns] Pattern components generated from latest osm manifests" | ||
commit_message: "[Patterns] Pattern components generated from latest OSM manifests" | ||
branch: master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package build | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/layer5io/meshery-adapter-library/adapter" | ||
"github.com/layer5io/meshery-osm/internal/config" | ||
|
||
"github.com/layer5io/meshkit/utils" | ||
"github.com/layer5io/meshkit/utils/manifests" | ||
smp "github.com/layer5io/service-mesh-performance/spec" | ||
) | ||
|
||
var DefaultGenerationMethod string | ||
var LatestVersion string | ||
var WorkloadPath string | ||
var CRDnames []string | ||
var OverrideURL string | ||
var AllVersions []string | ||
|
||
//NewConfig creates the configuration for creating components | ||
func NewConfig(version string) manifests.Config { | ||
return manifests.Config{ | ||
Name: smp.ServiceMesh_Type_name[int32(smp.ServiceMesh_OPEN_SERVICE_MESH)], | ||
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", | ||
}, | ||
} | ||
} | ||
func GetDefaultURL(crd string) string { | ||
if OverrideURL != "" { | ||
return OverrideURL | ||
} | ||
return strings.Join([]string{"https://raw.githubusercontent.com/openservicemesh/osm/main/cmd/osm-bootstrap/crds", crd}, "/") | ||
} | ||
func init() { | ||
wd, _ := os.Getwd() | ||
WorkloadPath = filepath.Join(wd, "templates", "oam", "workloads") | ||
AllVersions, _ = utils.GetLatestReleaseTagsSorted("openservicemesh", "osm") | ||
if len(AllVersions) == 0 { | ||
return | ||
} | ||
CRDnames, _ = config.GetFileNames("openservicemesh", "osm", "/cmd/osm-bootstrap/crds/**") | ||
LatestVersion = AllVersions[len(AllVersions)-1] | ||
DefaultGenerationMethod = adapter.Manifests | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.