-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move scripts into something that tracks script dependencies
trying just here as well because we are already doing cool stuff with sd and gron. Signed-off-by: clux <[email protected]>
- Loading branch information
Showing
2 changed files
with
77 additions
and
47 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
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,62 @@ | ||
VERSION := "1.22.0" | ||
|
||
default: | ||
@just --list | ||
|
||
# download proto schemas from upstream | ||
protos-sync: | ||
#!/usr/bin/env bash | ||
set -exuo pipefail | ||
rm -rf protos && mkdir protos && cd protos | ||
for x in api apimachinery apiextensions-apiserver kube-aggregator metrics; do | ||
mkdir ./$x -p | ||
curl -sSL https://github.com/kubernetes/$x/archive/refs/tags/kubernetes-{{VERSION}}.tar.gz | tar xzf - -C ./$x/ --strip-components=1 | ||
fd -e proto -x sh -c "mkdir -p k8s.io/'{//}'; mv '{}' k8s.io/'{}'" ';' . ./$x | ||
rm -rf ./$x | ||
done | ||
# fix import paths in downloaded schemas | ||
protos-patch: | ||
#!/usr/bin/env bash | ||
set -exuo pipefail | ||
fd -e proto -x sd 'k8s\.io\.(.+);' '$1;' {} | ||
fd -e proto -x sd 'import "k8s\.io/(.+)";' 'import "$1";' {} | ||
mv protos/k8s.io/* protos/ | ||
rmdir protos/k8s.io/ | ||
# Generate path list for prost | ||
protos-list: | ||
fd -e proto | sort > protos.list | ||
|
||
# Download and generate all protos dependent files | ||
protos: protos-sync protos-patch protos-list | ||
|
||
# Download swagger | ||
swagger-sync: | ||
#!/usr/bin/env bash | ||
set -exuo pipefail | ||
curl -sSL -o openapi/swagger.json \ | ||
https://raw.githubusercontent.com/kubernetes/kubernetes/v{{VERSION}}/api/openapi-spec/swagger.json | ||
# Fix patch operation | ||
swagger-patch: | ||
#!/usr/bin/env bash | ||
set -exuo pipefail | ||
cd openapi | ||
# Fix path operation annotated with a `x-kubernetes-group-version-kind` that references a type that doesn't exist in the schema. | ||
# See https://github.com/Arnavion/k8s-openapi/blob/445e89ec444ebb1c68e61361e64eec4c4a3f4785/k8s-openapi-codegen/src/fixups/upstream_bugs.rs#L9 | ||
gron swagger.json \ | ||
| perl -pe 's/(?<=kind = ")(Pod|Node|Service)(?:Attach|Exec|PortForward|Proxy)Options(?=")/$1/' \ | ||
| gron -u \ | ||
> swagger-patched.json | ||
mv swagger-patched.json swagger.json | ||
# Generate api-resources from patched swagger | ||
swagger-transform: | ||
#!/usr/bin/env bash | ||
set -exuo pipefail | ||
cd openapi | ||
jq -f list-resources.jq < swagger.json > api-resources.json | ||
# Download and generate all swagger dependent files | ||
swagger: swagger-sync swagger-patch swagger-transform |