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 #136 from Revolyssup/abc
Browse files Browse the repository at this point in the history
Add build time and modify run time comp generation
  • Loading branch information
leecalcote authored Jan 24, 2022
2 parents 5d98a12 + 3bd83bb commit bd30cad
Show file tree
Hide file tree
Showing 815 changed files with 45,219 additions and 205 deletions.
102 changes: 21 additions & 81 deletions .github/workflows/update-oam-defs.yml
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
Expand All @@ -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:
Expand All @@ -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
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ RUN go mod download
COPY main.go main.go
COPY internal/ internal/
COPY osm/ osm/
COPY build/ build/
RUN GOPROXY=https://proxy.golang.org,direct CGO_ENABLED=1 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -ldflags="-w -s -X main.version=$VERSION -X main.gitsha=$GIT_COMMITSHA" -a -o meshery-osm main.go

FROM alpine:3.15 as jsonschema-util
Expand Down
57 changes: 57 additions & 0 deletions build/config.go
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
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.15
replace github.com/kudobuilder/kuttl => github.com/layer5io/kuttl v0.4.1-0.20200806180306-b7e46afd657f

require (
github.com/layer5io/meshery-adapter-library v0.1.23
github.com/layer5io/meshkit v0.2.36
github.com/layer5io/meshery-adapter-library v0.5.2
github.com/layer5io/meshkit v0.5.1
github.com/layer5io/service-mesh-performance v0.3.3
gopkg.in/yaml.v2 v2.4.0
k8s.io/apimachinery v0.21.0
Expand Down
Loading

0 comments on commit bd30cad

Please sign in to comment.