Skip to content

Commit 61baaa4

Browse files
committed
move build.rs into a codegen crate
Signed-off-by: clux <[email protected]>
1 parent 159d347 commit 61baaa4

File tree

139 files changed

+213
-301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+213
-301
lines changed

Cargo.toml

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
1-
[package]
2-
name = "k8s-pb"
3-
version = "0.1.0"
4-
license = "Apache-2.0"
5-
edition = "2018"
6-
include = ["/openapi", "/protos", "./protos.fds", "protos.list", "justfile"]
7-
8-
[dependencies]
9-
bytes = "1.0.1"
10-
prost = "0.8.0"
11-
12-
[build-dependencies]
13-
prost-build = "0.8.0"
14-
prost-types = "0.8.0"
15-
prost = "0.8.0"
16-
serde_json = "1.0.67"
17-
serde = { version = "1.0.130", features = ["derive"] }
1+
[workspace]
2+
default-members = ["k8s-pb"]
3+
members = [
4+
"k8s-pb-codegen",
5+
"k8s-pb"
6+
]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ Results of this step is committed already. But to run, invoke `just swagger`.
2828
## Building
2929
To build the [out](./out) directory from [build.rs](./build.rs) we will use the outputs from the `swagger`, `protobuf`, and `protobuf-fds` targets.
3030

31-
Results of this step is committed already. But to run, invoke `just build`
31+
Results of this step is committed already. But to run, invoke `just codegen`
3232

3333
### Hack
3434

35-
Generate a [`FileDescriptorSet`] containing all of the input files wih `just build-fds`
35+
Generate a [`FileDescriptorSet`] containing all of the input files wih `just codegen-fds`
3636

3737

3838
## OpenAPI Strategy

build.rs

Lines changed: 0 additions & 125 deletions
This file was deleted.

justfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,33 @@ protos: protos-dl protos-patch protos-list
3535
swagger-dl:
3636
#!/usr/bin/env bash
3737
set -exuo pipefail
38-
curl -sSL -o openapi/swagger.json \
38+
curl -sSL -o k8s-pb-codegen/openapi/swagger.json \
3939
https://raw.githubusercontent.com/kubernetes/kubernetes/v{{VERSION}}/api/openapi-spec/swagger.json
4040

4141
# Patch swagger schema for upstream bugs
4242
swagger-patch:
4343
#!/usr/bin/env bash
4444
set -exuo pipefail
45-
cd openapi
45+
cd k8s-pb-codegen/openapi
4646
jq -f patches/patch-nonexistent-gvk.jq < swagger.json > swagger-patched.json
4747
mv swagger-patched.json swagger.json
4848

4949
# Transform swagger schema into api-resources.json
5050
swagger-transform:
5151
#!/usr/bin/env bash
5252
set -exuo pipefail
53-
cd openapi
53+
cd k8s-pb-codegen/openapi
5454
jq -f list-resources.jq < swagger.json > api-resources.json
5555

5656
# Download and generate all swagger dependent files
5757
swagger: swagger-dl swagger-patch swagger-transform
5858

5959
# Build a FileDescriptorSet for custom code generation
60-
build-fds:
60+
codegen-fds:
6161
#!/usr/bin/env bash
6262
set -exuo pipefail
6363
shopt -s globstar
64+
cd k8s-pb-codegen
6465
protoc \
6566
--include_imports \
6667
--include_source_info \
@@ -69,9 +70,8 @@ build-fds:
6970
./protos/**/*.proto
7071

7172
# Generate the library code from completed swagger and protos
72-
build: build-fds
73+
codegen: codegen-fds
7374
#!/usr/bin/env bash
7475
set -exuo pipefail
7576
rm -rf out/ && mkdir out
76-
touch justfile
77-
cargo build
77+
cd k8s-pb-codegen && cargo run

k8s-pb-codegen/Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "k8s-pb-codegen"
3+
version = "0.1.0"
4+
edition = "2018"
5+
license = "Apache-2.0"
6+
7+
[[bin]]
8+
name = "pbcodegen"
9+
path = "pbcodegen.rs"
10+
11+
[lib]
12+
name = "pbcodegen"
13+
path = "src/lib.rs"
14+
15+
[dependencies]
16+
bytes = "1.0.1"
17+
prost = "0.8.0"
18+
prost-build = "0.8.0"
19+
prost-types = "0.8.0"
20+
serde_json = "1.0.67"
21+
serde = { version = "1.0.130", features = ["derive"] }
22+
log = "0.4.14"
23+
anyhow = "1.0.44"
24+
env_logger = "0.9.0"
File renamed without changes.
File renamed without changes.
File renamed without changes.

out/api.admission.v1.rs renamed to k8s-pb-codegen/out/api.admission.v1.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,3 @@ pub struct AdmissionReview {
137137
#[prost(message, optional, tag="2")]
138138
pub response: ::core::option::Option<AdmissionResponse>,
139139
}
140-
// didn't find admission/v1

out/api.admission.v1beta1.rs renamed to k8s-pb-codegen/out/api.admission.v1beta1.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,3 @@ pub struct AdmissionReview {
137137
#[prost(message, optional, tag="2")]
138138
pub response: ::core::option::Option<AdmissionResponse>,
139139
}
140-
// didn't find admission/v1beta1

out/api.admissionregistration.v1.rs renamed to k8s-pb-codegen/out/api.admissionregistration.v1.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,4 +457,3 @@ pub struct WebhookClientConfig {
457457
#[prost(bytes="vec", optional, tag="2")]
458458
pub ca_bundle: ::core::option::Option<::prost::alloc::vec::Vec<u8>>,
459459
}
460-
// didn't find admissionregistration/v1

out/api.admissionregistration.v1beta1.rs renamed to k8s-pb-codegen/out/api.admissionregistration.v1beta1.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,4 +465,3 @@ pub struct WebhookClientConfig {
465465
#[prost(bytes="vec", optional, tag="2")]
466466
pub ca_bundle: ::core::option::Option<::prost::alloc::vec::Vec<u8>>,
467467
}
468-
// didn't find admissionregistration/v1beta1

out/api.apiserverinternal.v1alpha1.rs renamed to k8s-pb-codegen/out/api.apiserverinternal.v1alpha1.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,3 @@ pub struct StorageVersionStatus {
9797
#[prost(message, repeated, tag="3")]
9898
pub conditions: ::prost::alloc::vec::Vec<StorageVersionCondition>,
9999
}
100-
// didn't find apiserverinternal/v1alpha1

out/api.apps.v1.rs renamed to k8s-pb-codegen/out/api.apps.v1.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -739,24 +739,6 @@ pub struct StatefulSetUpdateStrategy {
739739
}
740740
// TODO generics for controllerrevisions apps/v1
741741
// TODO generics for daemonsets apps/v1
742-
// NB: no-generics for api.apps.v1/DaemonSetCondition (not in apps/v1)
743-
// NB: no-generics for api.apps.v1/DaemonSetSpec (not in apps/v1)
744-
// NB: no-generics for api.apps.v1/DaemonSetStatus (not in apps/v1)
745-
// NB: no-generics for api.apps.v1/DaemonSetUpdateStrategy (not in apps/v1)
746742
// TODO generics for deployments apps/v1
747-
// NB: no-generics for api.apps.v1/DeploymentCondition (not in apps/v1)
748-
// NB: no-generics for api.apps.v1/DeploymentSpec (not in apps/v1)
749-
// NB: no-generics for api.apps.v1/DeploymentStatus (not in apps/v1)
750-
// NB: no-generics for api.apps.v1/DeploymentStrategy (not in apps/v1)
751743
// TODO generics for replicasets apps/v1
752-
// NB: no-generics for api.apps.v1/ReplicaSetCondition (not in apps/v1)
753-
// NB: no-generics for api.apps.v1/ReplicaSetSpec (not in apps/v1)
754-
// NB: no-generics for api.apps.v1/ReplicaSetStatus (not in apps/v1)
755-
// NB: no-generics for api.apps.v1/RollingUpdateDaemonSet (not in apps/v1)
756-
// NB: no-generics for api.apps.v1/RollingUpdateDeployment (not in apps/v1)
757-
// NB: no-generics for api.apps.v1/RollingUpdateStatefulSetStrategy (not in apps/v1)
758-
// TODO generics for statefulsets apps/v1
759-
// NB: no-generics for api.apps.v1/StatefulSetCondition (not in apps/v1)
760-
// NB: no-generics for api.apps.v1/StatefulSetSpec (not in apps/v1)
761-
// NB: no-generics for api.apps.v1/StatefulSetStatus (not in apps/v1)
762-
// NB: no-generics for api.apps.v1/StatefulSetUpdateStrategy (not in apps/v1)
744+
// TODO generics for statefulsets apps/v1

out/api.apps.v1beta1.rs renamed to k8s-pb-codegen/out/api.apps.v1beta1.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,4 +484,3 @@ pub struct StatefulSetUpdateStrategy {
484484
#[prost(message, optional, tag="2")]
485485
pub rolling_update: ::core::option::Option<RollingUpdateStatefulSetStrategy>,
486486
}
487-
// didn't find apps/v1beta1

out/api.apps.v1beta2.rs renamed to k8s-pb-codegen/out/api.apps.v1beta2.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,4 +785,3 @@ pub struct StatefulSetUpdateStrategy {
785785
#[prost(message, optional, tag="2")]
786786
pub rolling_update: ::core::option::Option<RollingUpdateStatefulSetStrategy>,
787787
}
788-
// didn't find apps/v1beta2

out/api.authentication.v1.rs renamed to k8s-pb-codegen/out/api.authentication.v1.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,3 @@ pub struct UserInfo {
165165
#[prost(map="string, message", tag="4")]
166166
pub extra: ::std::collections::HashMap<::prost::alloc::string::String, ExtraValue>,
167167
}
168-
// didn't find authentication/v1

out/api.authentication.v1beta1.rs renamed to k8s-pb-codegen/out/api.authentication.v1beta1.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,3 @@ pub struct UserInfo {
9393
#[prost(map="string, message", tag="4")]
9494
pub extra: ::std::collections::HashMap<::prost::alloc::string::String, ExtraValue>,
9595
}
96-
// didn't find authentication/v1beta1

out/api.authorization.v1.rs renamed to k8s-pb-codegen/out/api.authorization.v1.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,3 @@ pub struct SubjectRulesReviewStatus {
263263
#[prost(string, optional, tag="4")]
264264
pub evaluation_error: ::core::option::Option<::prost::alloc::string::String>,
265265
}
266-
// didn't find authorization/v1

out/api.authorization.v1beta1.rs renamed to k8s-pb-codegen/out/api.authorization.v1beta1.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,3 @@ pub struct SubjectRulesReviewStatus {
263263
#[prost(string, optional, tag="4")]
264264
pub evaluation_error: ::core::option::Option<::prost::alloc::string::String>,
265265
}
266-
// didn't find authorization/v1beta1

out/api.autoscaling.v1.rs renamed to k8s-pb-codegen/out/api.autoscaling.v1.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -482,23 +482,4 @@ pub struct ScaleStatus {
482482
#[prost(string, optional, tag="2")]
483483
pub selector: ::core::option::Option<::prost::alloc::string::String>,
484484
}
485-
// NB: no-generics for api.autoscaling.v1/ContainerResourceMetricSource (not in autoscaling/v1)
486-
// NB: no-generics for api.autoscaling.v1/ContainerResourceMetricStatus (not in autoscaling/v1)
487-
// NB: no-generics for api.autoscaling.v1/CrossVersionObjectReference (not in autoscaling/v1)
488-
// NB: no-generics for api.autoscaling.v1/ExternalMetricSource (not in autoscaling/v1)
489-
// NB: no-generics for api.autoscaling.v1/ExternalMetricStatus (not in autoscaling/v1)
490-
// TODO generics for horizontalpodautoscalers autoscaling/v1
491-
// NB: no-generics for api.autoscaling.v1/HorizontalPodAutoscalerCondition (not in autoscaling/v1)
492-
// NB: no-generics for api.autoscaling.v1/HorizontalPodAutoscalerSpec (not in autoscaling/v1)
493-
// NB: no-generics for api.autoscaling.v1/HorizontalPodAutoscalerStatus (not in autoscaling/v1)
494-
// NB: no-generics for api.autoscaling.v1/MetricSpec (not in autoscaling/v1)
495-
// NB: no-generics for api.autoscaling.v1/MetricStatus (not in autoscaling/v1)
496-
// NB: no-generics for api.autoscaling.v1/ObjectMetricSource (not in autoscaling/v1)
497-
// NB: no-generics for api.autoscaling.v1/ObjectMetricStatus (not in autoscaling/v1)
498-
// NB: no-generics for api.autoscaling.v1/PodsMetricSource (not in autoscaling/v1)
499-
// NB: no-generics for api.autoscaling.v1/PodsMetricStatus (not in autoscaling/v1)
500-
// NB: no-generics for api.autoscaling.v1/ResourceMetricSource (not in autoscaling/v1)
501-
// NB: no-generics for api.autoscaling.v1/ResourceMetricStatus (not in autoscaling/v1)
502-
// NB: no-generics for api.autoscaling.v1/Scale (not in autoscaling/v1)
503-
// NB: no-generics for api.autoscaling.v1/ScaleSpec (not in autoscaling/v1)
504-
// NB: no-generics for api.autoscaling.v1/ScaleStatus (not in autoscaling/v1)
485+
// TODO generics for horizontalpodautoscalers autoscaling/v1

out/api.autoscaling.v2beta1.rs renamed to k8s-pb-codegen/out/api.autoscaling.v2beta1.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -459,20 +459,4 @@ pub struct ResourceMetricStatus {
459459
#[prost(message, optional, tag="3")]
460460
pub current_average_value: ::core::option::Option<super::super::super::apimachinery::pkg::api::resource::Quantity>,
461461
}
462-
// NB: no-generics for api.autoscaling.v2beta1/ContainerResourceMetricSource (not in autoscaling/v2beta1)
463-
// NB: no-generics for api.autoscaling.v2beta1/ContainerResourceMetricStatus (not in autoscaling/v2beta1)
464-
// NB: no-generics for api.autoscaling.v2beta1/CrossVersionObjectReference (not in autoscaling/v2beta1)
465-
// NB: no-generics for api.autoscaling.v2beta1/ExternalMetricSource (not in autoscaling/v2beta1)
466-
// NB: no-generics for api.autoscaling.v2beta1/ExternalMetricStatus (not in autoscaling/v2beta1)
467-
// TODO generics for horizontalpodautoscalers autoscaling/v2beta1
468-
// NB: no-generics for api.autoscaling.v2beta1/HorizontalPodAutoscalerCondition (not in autoscaling/v2beta1)
469-
// NB: no-generics for api.autoscaling.v2beta1/HorizontalPodAutoscalerSpec (not in autoscaling/v2beta1)
470-
// NB: no-generics for api.autoscaling.v2beta1/HorizontalPodAutoscalerStatus (not in autoscaling/v2beta1)
471-
// NB: no-generics for api.autoscaling.v2beta1/MetricSpec (not in autoscaling/v2beta1)
472-
// NB: no-generics for api.autoscaling.v2beta1/MetricStatus (not in autoscaling/v2beta1)
473-
// NB: no-generics for api.autoscaling.v2beta1/ObjectMetricSource (not in autoscaling/v2beta1)
474-
// NB: no-generics for api.autoscaling.v2beta1/ObjectMetricStatus (not in autoscaling/v2beta1)
475-
// NB: no-generics for api.autoscaling.v2beta1/PodsMetricSource (not in autoscaling/v2beta1)
476-
// NB: no-generics for api.autoscaling.v2beta1/PodsMetricStatus (not in autoscaling/v2beta1)
477-
// NB: no-generics for api.autoscaling.v2beta1/ResourceMetricSource (not in autoscaling/v2beta1)
478-
// NB: no-generics for api.autoscaling.v2beta1/ResourceMetricStatus (not in autoscaling/v2beta1)
462+
// TODO generics for horizontalpodautoscalers autoscaling/v2beta1

0 commit comments

Comments
 (0)