Last active
October 10, 2021 17:43
-
-
Save DelusionalOptimist/36e639fcf0e68cbeef85386198985791 to your computer and use it in GitHub Desktop.
Shell script for extracting JSON schema and generating OAM workloads from service mesh 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
#!/usr/env bash | |
# change these vars according to needs | |
NEW_ISTIO_VERSION=1.10.3 | |
UTILPATH=~/dev/kubeopenapi-jsonschema | |
meshName=Istio | |
smpMeshName=ISTIO | |
resourceType=CustomResourceDefinition | |
dirName=./templates/oam/workloads/$NEW_ISTIO_VERSION | |
# change this according to the link for fetching manifests | |
curl https://raw.githubusercontent.com/istio/istio/$NEW_ISTIO_VERSION/manifests/charts/base/crds/crd-all.gen.yaml > ~/istio.yml | |
template='{"apiVersion":"core.oam.dev/v1alpha1","kind":"WorkloadDefinition","metadata":{},"spec":{"definitionRef":{},"metadata":{"@type":"pattern.meshery.io/mesh/workload","meshVersion":"'$NEW_ISTIO_VERSION'","meshName":"'$smpMeshName'","k8sAPIVersion":null,"k8sKind":""}}}' | |
crds=$($UTILPATH/kubeopenapi-jsonschema --location ~/istio.yml -t yaml --filter '$[?(@.kind=="CustomResourceDefinition")]' -o json --o-filter '$..["spec"]["names"]["kind"]' | jq '.[]') | |
mkdir -p $dirName | |
for t in ${crds[@]}; do | |
nameUpper=`echo $t | tr -d '"'` | |
nameLower=`echo $t | tr -d '"' | tr '[:upper:]' '[:lower:]'` | |
definitionRef=$(printf %s.istio.meshery.layer5.io $nameLower) | |
apiVersion=$($UTILPATH/kubeopenapi-jsonschema --location ~/istio.yml -t yaml --filter '$[?(@.kind=="CustomResourceDefinition" && @.spec.names.kind=='$t')]..spec.versions[0]' --o-filter "$[].name" -o json | jq '.[]' | tr -d '"') | |
apiGroup=$($UTILPATH/kubeopenapi-jsonschema --location ~/istio.yml -t yaml --filter '$[?(@.kind=="CustomResourceDefinition" && @.spec.names.kind=='$t')]..spec' --o-filter "$[].group" -o json | jq '.[]' | tr -d '"') | |
$UTILPATH/kubeopenapi-jsonschema --location ~/istio.yml -t yaml --filter '$[?(@.kind=="CustomResourceDefinition" && @.spec.names.kind=='$t')]..openAPIV3Schema.properties.spec' --o-filter "$[]" -o json |\ | |
jq ' | |
.[] | |
| .version = "'$NEW_ISTIO_VERSION'" | |
| ."object-type" = "'$nameUpper'" | |
| ."service-mesh" = "'$meshName'" ' > $dirName/$nameLower.istio.meshery.layer5io.schema.json | |
echo $template |\ | |
jq ' | |
."metadata"."name" = "'$(printf %s.Istio $nameUpper)'" | |
| ."spec"."metadata"."k8sAPIVersion" = "'$(printf $apiGroup/$apiVersion $apiGroup $apiVersion)'" | |
| ."spec"."metadata"."k8sKind" = "'$nameUpper'" | |
| ."spec"."definitionRef"."name"="'$definitionRef'"' > $dirName/$nameLower.istio_definition.json | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks @Shreyas220 👍