1
1
Experimenting with Kubernetes protobufs.
2
2
3
- ## Protobufs
3
+ ## Build Dependencies
4
4
5
- ### Download
5
+ - [ gron] ( https://github.com/tomnomnom/gron )
6
+ - [ just] ( https://github.com/casey/just )
7
+ - [ sd] ( https://github.com/chmln/sd )
8
+ - [ jq] ( https://stedolan.github.io/jq/ )
6
9
7
- Get protos by extracting them from Kubernetes releases:
10
+ ## Protobufs
11
+ We get protos by extracting them from pinned Kubernetes releases:
8
12
9
13
- https://github.com/kubernetes/api/releases
10
14
- https://github.com/kubernetes/apimachinery/releases
11
15
- https://github.com/kubernetes/apiextensions-apiserver/releases
12
16
- https://github.com/kubernetes/kube-aggregator/releases
13
17
- https://github.com/kubernetes/metrics/releases
14
18
15
- ``` bash
16
- # In `protos/`
17
- VERSION=1.22.0
18
- for x in api apimachinery apiextensions-apiserver kube-aggregator metrics; do
19
- mkdir ./$x -p;
20
- curl -sSL https://github.com/kubernetes/$x /archive/refs/tags/kubernetes-$VERSION .tar.gz | tar xzf - -C ./$x / --strip-components=1;
21
- fd -e proto -x sh -c " mkdir -p k8s.io/'{//}'; mv '{}' k8s.io/'{}'" ' ;' . ./$x ;
22
- rm -rf ./$x ;
23
- done
24
- ```
19
+ We then do minor transforms on top of that to prepare for building.
20
+ Results of this step is committed already. But to run, invoke ` just protos `
25
21
26
- ### Patch
22
+ ## Openapi
23
+ To complement the protos with generic information, we also download the swagger schema, patch it, and transform it as described below.
27
24
28
- Removing ` k8s.io. ` :
25
+ Results of this step is committed already. But to run, invoke ` just swagger ` .
29
26
30
- ``` bash
31
- fd -e proto -x sd ' k8s\.io\.(.+);' ' $1;' {}
32
- fd -e proto -x sd ' import "k8s\.io/(.+)";' ' import "$1";' {}
33
- mv protos/k8s.io/* protos/
34
- rmdir protos/k8s.io/
35
- ```
36
27
37
- ### Generate
38
- Refresh input paths to generate, then build :
28
+ ## Building
29
+ With all dependent ` swagger ` and ` protos ` files built, run :
39
30
40
31
``` bash
41
- fd -e proto | sort > protos.list
42
32
cargo build
43
33
```
44
34
@@ -68,7 +58,7 @@ See [`prost_build`](https://github.com/tokio-rs/prost/blob/32bc87cd0b7301f6af1a3
68
58
[ `FileDescriptorSet` ] : https://github.com/tokio-rs/prost/blob/32bc87cd0b7301f6af1a338e9afd7717d0f42ca9/prost-types/src/protobuf.rs#L1-L7
69
59
70
60
71
- ## OpenAPI
61
+ ## OpenAPI Strategy
72
62
73
63
We need to use ` swagger.json ` to fill in some information.
74
64
@@ -91,28 +81,6 @@ We should be able to find the following:
91
81
- May also have paths for all namespaces for some verbs (e.g., ` list ` all pods)
92
82
- Subresource if path contains ` /{name}/ ` (` / ` after ` {name} ` )
93
83
94
- ### Download
95
-
96
- In ` openapi/ `
97
-
98
- ``` bash
99
- VERSION=1.22.0
100
- curl -sSL -o swagger.json \
101
- https://raw.githubusercontent.com/kubernetes/kubernetes/v$VERSION /api/openapi-spec/swagger.json
102
- ```
103
-
104
- ### Bug Fix
105
-
106
- Fix path operation annotated with a ` x-kubernetes-group-version-kind ` that references a type that doesn't exist in the schema. (See [ ` k8s-openapi ` ] ( https://github.com/Arnavion/k8s-openapi/blob/445e89ec444ebb1c68e61361e64eec4c4a3f4785/k8s-openapi-codegen/src/fixups/upstream_bugs.rs#L9 ) ).
107
-
108
- ``` bash
109
- gron swagger.json \
110
- | perl -pe ' s/(?<=kind = ")(Pod|Node|Service)(?:Attach|Exec|PortForward|Proxy)Options(?=")/$1/' \
111
- | gron -u \
112
- > swagger-patched.json
113
- mv swagger-patched.json swagger.json
114
- ```
115
-
116
84
### Transforming
117
85
118
86
Transform ` swagger.json ` to something easier to explore.
0 commit comments