-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from Revolyssup/abc
Add static and dynamic comp gen via new method
- Loading branch information
Showing
6 changed files
with
138 additions
and
213 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 |
---|---|---|
|
@@ -3,118 +3,42 @@ on: | |
push: | ||
branches: | ||
- 'master' | ||
|
||
schedule: | ||
- cron: "0 0 * * *" | ||
jobs: | ||
check_consul_version: | ||
name: Check Consul Version | ||
GenerateComponents: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
NEW_CONSUL_VERSION: ${{ env.NEW_CONSUL_VERSION }} | ||
NEW_CONSUL_CHART_VERSION: ${{ env.NEW_CONSUL_CHART_VERSION }} | ||
EXISTS: ${{ env.EXISTS }} | ||
steps: | ||
- name: Setup Helm | ||
id: sh | ||
uses: azure/setup-helm@v1 | ||
|
||
# retrieves consul version from helm charts | ||
- name: Get Consul Latest Release Metadata | ||
id: glrt | ||
run: | ||
helm repo add hashicorp https://helm.releases.hashicorp.com; | ||
helm repo update; | ||
RELEASE_METADATA=$(helm search repo hashicorp/consul --versions | sed -n 2p$'\n' | sed -e 's/\s/;/g' | tr -s ';'); | ||
echo "NEW_CONSUL_CHART_VERSION=`echo $RELEASE_METADATA | cut -d ';' -f2`" >> $GITHUB_ENV; | ||
echo "NEW_CONSUL_VERSION=`echo $RELEASE_METADATA | cut -d ';' -f3`" >> $GITHUB_ENV; | ||
|
||
- 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/${{ env.NEW_CONSUL_VERSION }} ] | ||
then | ||
echo "EXISTS=true" >> $GITHUB_ENV | ||
else | ||
export "EXISTS=false" >> $GITHUB_ENV | ||
fi | ||
generator: | ||
name: Generate and push OAM definitions | ||
needs: [ check_consul_version ] | ||
if: ${{ !needs.check_consul_version.outputs.EXISTS }} | ||
env: | ||
NEW_CONSUL_VERSION: ${{ needs.check_consul_version.outputs.NEW_CONSUL_VERSION }} | ||
NEW_CONSUL_CHART_VERSION: ${{ needs.check_consul_version.outputs.NEW_CONSUL_CHART_VERSION }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@master | ||
token: ${{ secrets.GH_ACCESS_TOKEN }} | ||
ref: "master" | ||
- name: Setup Go | ||
uses: actions/setup-go@v1 | ||
with: | ||
fetch-depth: 1 | ||
token: ${{secrets.GH_ACCESS_TOKEN}} | ||
|
||
- name: Get Consul manifests | ||
run: | | ||
mkdir ./consul-crds | ||
cd ./consul-crds | ||
curl --silent --remote-name-all `curl --silent -H "Accept: application/vnd.github.VERSION.raw" https://api.github.com/repos/hashicorp/consul-k8s/contents/control-plane/config/crd/bases\?ref\=$(printf v%s $NEW_CONSUL_CHART_VERSION) | jq 'map(.download_url) | .[]' | tr -d '"'`; | ||
cd .. | ||
awk 'FNR==1 && NR>1 { printf("\n%s\n\n","---") } 1' consul-crds/*.yaml > ~/consul.yaml | ||
- name: Build jsonschema util | ||
go-version: 1.17 | ||
- name: Run adapter to create components | ||
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 | ||
run: | | ||
dirPath=../templates/oam/workloads/$NEW_CONSUL_VERSION | ||
cd util | ||
mkdir -p $dirPath | ||
meshName=Consul | ||
smpMeshName=CONSUL | ||
template='{"apiVersion":"core.oam.dev/v1alpha1","kind":"WorkloadDefinition","metadata":{},"spec":{"definitionRef":{},"metadata":{"@type":"pattern.meshery.io/mesh/workload","meshVersion":"'v$NEW_CONSUL_VERSION'","meshName":"'$smpMeshName'","k8sAPIVersion":null,"k8sKind":""}}}' | ||
crds=$(./kubeopenapi-jsonschema --location ~/consul.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.consul.meshery.layer5.io $nameLower) | ||
apiVersion=$(./kubeopenapi-jsonschema --location ~/consul.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 ~/consul.yaml -t yaml --filter '$[?(@.kind=="CustomResourceDefinition" && @.spec.names.kind=='$t')]..spec' --o-filter "$[].group" -o json | jq '.[]' | tr -d '"') | ||
./kubeopenapi-jsonschema --location ~/consul.yaml -t yaml --filter '$[?(@.kind=="CustomResourceDefinition" && @.spec.names.kind=='$t')]..openAPIV3Schema.properties.spec' --o-filter "$[]" -o json |\ | ||
jq '.[]' > $dirPath/$nameLower.consul.meshery.layer5io.schema.json | ||
echo $template |\ | ||
jq ' | ||
."metadata"."name" = "'$(printf %s.Consul $nameUpper)'" | ||
| ."spec"."metadata"."k8sAPIVersion" = "'$(printf $apiGroup/$apiVersion $apiGroup $apiVersion)'" | ||
| ."spec"."metadata"."k8sKind" = "'$nameUpper'" | ||
| ."spec"."definitionRef"."name"="'$definitionRef'"' > $dirPath/$nameLower.consul_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: | ||
file_pattern: templates/ | ||
commit_user_name: l5io | ||
commit_user_email: [email protected] | ||
commit_author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> | ||
commit_options: '--signoff' | ||
commit_options: "--signoff" | ||
commit_message: "[Patterns] Pattern components generated from latest Consul 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
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-consul/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_CONSUL)], | ||
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/hashicorp/consul-k8s/main/control-plane/config/crd/bases", crd}, "/") | ||
} | ||
func init() { | ||
wd, _ := os.Getwd() | ||
WorkloadPath = filepath.Join(wd, "templates", "oam", "workloads") | ||
AllVersions, _ = utils.GetLatestReleaseTagsSorted("hashicorp", "consul-k8s") | ||
if len(AllVersions) == 0 { | ||
return | ||
} | ||
CRDnames, _ = config.GetFileNames("hashicorp", "consul-k8s", "control-plane/config/crd/bases/") | ||
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
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.