Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automation and filedescriptorset usage #1

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move build.rs into a codegen crate
Signed-off-by: clux <[email protected]>
  • Loading branch information
clux committed Sep 16, 2021
commit 61baaa4fce17615b9a726eac80ebdd173560ea7a
23 changes: 6 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
[package]
name = "k8s-pb"
version = "0.1.0"
license = "Apache-2.0"
edition = "2018"
include = ["/openapi", "/protos", "./protos.fds", "protos.list", "justfile"]

[dependencies]
bytes = "1.0.1"
prost = "0.8.0"

[build-dependencies]
prost-build = "0.8.0"
prost-types = "0.8.0"
prost = "0.8.0"
serde_json = "1.0.67"
serde = { version = "1.0.130", features = ["derive"] }
[workspace]
default-members = ["k8s-pb"]
members = [
"k8s-pb-codegen",
"k8s-pb"
]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ Results of this step is committed already. But to run, invoke `just swagger`.
## Building
To build the [out](./out) directory from [build.rs](./build.rs) we will use the outputs from the `swagger`, `protobuf`, and `protobuf-fds` targets.

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

### Hack

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


## OpenAPI Strategy
Expand Down
125 changes: 0 additions & 125 deletions build.rs

This file was deleted.

14 changes: 7 additions & 7 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,33 @@ protos: protos-dl protos-patch protos-list
swagger-dl:
#!/usr/bin/env bash
set -exuo pipefail
curl -sSL -o openapi/swagger.json \
curl -sSL -o k8s-pb-codegen/openapi/swagger.json \
https://raw.githubusercontent.com/kubernetes/kubernetes/v{{VERSION}}/api/openapi-spec/swagger.json

# Patch swagger schema for upstream bugs
swagger-patch:
#!/usr/bin/env bash
set -exuo pipefail
cd openapi
cd k8s-pb-codegen/openapi
jq -f patches/patch-nonexistent-gvk.jq < swagger.json > swagger-patched.json
mv swagger-patched.json swagger.json

# Transform swagger schema into api-resources.json
swagger-transform:
#!/usr/bin/env bash
set -exuo pipefail
cd openapi
cd k8s-pb-codegen/openapi
jq -f list-resources.jq < swagger.json > api-resources.json

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

# Build a FileDescriptorSet for custom code generation
build-fds:
codegen-fds:
#!/usr/bin/env bash
set -exuo pipefail
shopt -s globstar
cd k8s-pb-codegen
protoc \
--include_imports \
--include_source_info \
Expand All @@ -69,9 +70,8 @@ build-fds:
./protos/**/*.proto

# Generate the library code from completed swagger and protos
build: build-fds
codegen: codegen-fds
#!/usr/bin/env bash
set -exuo pipefail
rm -rf out/ && mkdir out
touch justfile
cargo build
cd k8s-pb-codegen && cargo run
24 changes: 24 additions & 0 deletions k8s-pb-codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "k8s-pb-codegen"
version = "0.1.0"
edition = "2018"
license = "Apache-2.0"

[[bin]]
name = "pbcodegen"
path = "pbcodegen.rs"

[lib]
name = "pbcodegen"
path = "src/lib.rs"

[dependencies]
bytes = "1.0.1"
prost = "0.8.0"
prost-build = "0.8.0"
prost-types = "0.8.0"
serde_json = "1.0.67"
serde = { version = "1.0.130", features = ["derive"] }
log = "0.4.14"
anyhow = "1.0.44"
env_logger = "0.9.0"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,3 @@ pub struct AdmissionReview {
#[prost(message, optional, tag="2")]
pub response: ::core::option::Option<AdmissionResponse>,
}
// didn't find admission/v1
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,3 @@ pub struct AdmissionReview {
#[prost(message, optional, tag="2")]
pub response: ::core::option::Option<AdmissionResponse>,
}
// didn't find admission/v1beta1
Original file line number Diff line number Diff line change
Expand Up @@ -457,4 +457,3 @@ pub struct WebhookClientConfig {
#[prost(bytes="vec", optional, tag="2")]
pub ca_bundle: ::core::option::Option<::prost::alloc::vec::Vec<u8>>,
}
// didn't find admissionregistration/v1
Original file line number Diff line number Diff line change
Expand Up @@ -465,4 +465,3 @@ pub struct WebhookClientConfig {
#[prost(bytes="vec", optional, tag="2")]
pub ca_bundle: ::core::option::Option<::prost::alloc::vec::Vec<u8>>,
}
// didn't find admissionregistration/v1beta1
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,3 @@ pub struct StorageVersionStatus {
#[prost(message, repeated, tag="3")]
pub conditions: ::prost::alloc::vec::Vec<StorageVersionCondition>,
}
// didn't find apiserverinternal/v1alpha1
20 changes: 1 addition & 19 deletions out/api.apps.v1.rs → k8s-pb-codegen/out/api.apps.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,24 +739,6 @@ pub struct StatefulSetUpdateStrategy {
}
// TODO generics for controllerrevisions apps/v1
// TODO generics for daemonsets apps/v1
// NB: no-generics for api.apps.v1/DaemonSetCondition (not in apps/v1)
// NB: no-generics for api.apps.v1/DaemonSetSpec (not in apps/v1)
// NB: no-generics for api.apps.v1/DaemonSetStatus (not in apps/v1)
// NB: no-generics for api.apps.v1/DaemonSetUpdateStrategy (not in apps/v1)
// TODO generics for deployments apps/v1
// NB: no-generics for api.apps.v1/DeploymentCondition (not in apps/v1)
// NB: no-generics for api.apps.v1/DeploymentSpec (not in apps/v1)
// NB: no-generics for api.apps.v1/DeploymentStatus (not in apps/v1)
// NB: no-generics for api.apps.v1/DeploymentStrategy (not in apps/v1)
// TODO generics for replicasets apps/v1
// NB: no-generics for api.apps.v1/ReplicaSetCondition (not in apps/v1)
// NB: no-generics for api.apps.v1/ReplicaSetSpec (not in apps/v1)
// NB: no-generics for api.apps.v1/ReplicaSetStatus (not in apps/v1)
// NB: no-generics for api.apps.v1/RollingUpdateDaemonSet (not in apps/v1)
// NB: no-generics for api.apps.v1/RollingUpdateDeployment (not in apps/v1)
// NB: no-generics for api.apps.v1/RollingUpdateStatefulSetStrategy (not in apps/v1)
// TODO generics for statefulsets apps/v1
// NB: no-generics for api.apps.v1/StatefulSetCondition (not in apps/v1)
// NB: no-generics for api.apps.v1/StatefulSetSpec (not in apps/v1)
// NB: no-generics for api.apps.v1/StatefulSetStatus (not in apps/v1)
// NB: no-generics for api.apps.v1/StatefulSetUpdateStrategy (not in apps/v1)
// TODO generics for statefulsets apps/v1
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,3 @@ pub struct StatefulSetUpdateStrategy {
#[prost(message, optional, tag="2")]
pub rolling_update: ::core::option::Option<RollingUpdateStatefulSetStrategy>,
}
// didn't find apps/v1beta1
Original file line number Diff line number Diff line change
Expand Up @@ -785,4 +785,3 @@ pub struct StatefulSetUpdateStrategy {
#[prost(message, optional, tag="2")]
pub rolling_update: ::core::option::Option<RollingUpdateStatefulSetStrategy>,
}
// didn't find apps/v1beta2
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,3 @@ pub struct UserInfo {
#[prost(map="string, message", tag="4")]
pub extra: ::std::collections::HashMap<::prost::alloc::string::String, ExtraValue>,
}
// didn't find authentication/v1
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,3 @@ pub struct UserInfo {
#[prost(map="string, message", tag="4")]
pub extra: ::std::collections::HashMap<::prost::alloc::string::String, ExtraValue>,
}
// didn't find authentication/v1beta1
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,3 @@ pub struct SubjectRulesReviewStatus {
#[prost(string, optional, tag="4")]
pub evaluation_error: ::core::option::Option<::prost::alloc::string::String>,
}
// didn't find authorization/v1
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,3 @@ pub struct SubjectRulesReviewStatus {
#[prost(string, optional, tag="4")]
pub evaluation_error: ::core::option::Option<::prost::alloc::string::String>,
}
// didn't find authorization/v1beta1
Original file line number Diff line number Diff line change
Expand Up @@ -482,23 +482,4 @@ pub struct ScaleStatus {
#[prost(string, optional, tag="2")]
pub selector: ::core::option::Option<::prost::alloc::string::String>,
}
// NB: no-generics for api.autoscaling.v1/ContainerResourceMetricSource (not in autoscaling/v1)
// NB: no-generics for api.autoscaling.v1/ContainerResourceMetricStatus (not in autoscaling/v1)
// NB: no-generics for api.autoscaling.v1/CrossVersionObjectReference (not in autoscaling/v1)
// NB: no-generics for api.autoscaling.v1/ExternalMetricSource (not in autoscaling/v1)
// NB: no-generics for api.autoscaling.v1/ExternalMetricStatus (not in autoscaling/v1)
// TODO generics for horizontalpodautoscalers autoscaling/v1
// NB: no-generics for api.autoscaling.v1/HorizontalPodAutoscalerCondition (not in autoscaling/v1)
// NB: no-generics for api.autoscaling.v1/HorizontalPodAutoscalerSpec (not in autoscaling/v1)
// NB: no-generics for api.autoscaling.v1/HorizontalPodAutoscalerStatus (not in autoscaling/v1)
// NB: no-generics for api.autoscaling.v1/MetricSpec (not in autoscaling/v1)
// NB: no-generics for api.autoscaling.v1/MetricStatus (not in autoscaling/v1)
// NB: no-generics for api.autoscaling.v1/ObjectMetricSource (not in autoscaling/v1)
// NB: no-generics for api.autoscaling.v1/ObjectMetricStatus (not in autoscaling/v1)
// NB: no-generics for api.autoscaling.v1/PodsMetricSource (not in autoscaling/v1)
// NB: no-generics for api.autoscaling.v1/PodsMetricStatus (not in autoscaling/v1)
// NB: no-generics for api.autoscaling.v1/ResourceMetricSource (not in autoscaling/v1)
// NB: no-generics for api.autoscaling.v1/ResourceMetricStatus (not in autoscaling/v1)
// NB: no-generics for api.autoscaling.v1/Scale (not in autoscaling/v1)
// NB: no-generics for api.autoscaling.v1/ScaleSpec (not in autoscaling/v1)
// NB: no-generics for api.autoscaling.v1/ScaleStatus (not in autoscaling/v1)
// TODO generics for horizontalpodautoscalers autoscaling/v1
Original file line number Diff line number Diff line change
Expand Up @@ -459,20 +459,4 @@ pub struct ResourceMetricStatus {
#[prost(message, optional, tag="3")]
pub current_average_value: ::core::option::Option<super::super::super::apimachinery::pkg::api::resource::Quantity>,
}
// NB: no-generics for api.autoscaling.v2beta1/ContainerResourceMetricSource (not in autoscaling/v2beta1)
// NB: no-generics for api.autoscaling.v2beta1/ContainerResourceMetricStatus (not in autoscaling/v2beta1)
// NB: no-generics for api.autoscaling.v2beta1/CrossVersionObjectReference (not in autoscaling/v2beta1)
// NB: no-generics for api.autoscaling.v2beta1/ExternalMetricSource (not in autoscaling/v2beta1)
// NB: no-generics for api.autoscaling.v2beta1/ExternalMetricStatus (not in autoscaling/v2beta1)
// TODO generics for horizontalpodautoscalers autoscaling/v2beta1
// NB: no-generics for api.autoscaling.v2beta1/HorizontalPodAutoscalerCondition (not in autoscaling/v2beta1)
// NB: no-generics for api.autoscaling.v2beta1/HorizontalPodAutoscalerSpec (not in autoscaling/v2beta1)
// NB: no-generics for api.autoscaling.v2beta1/HorizontalPodAutoscalerStatus (not in autoscaling/v2beta1)
// NB: no-generics for api.autoscaling.v2beta1/MetricSpec (not in autoscaling/v2beta1)
// NB: no-generics for api.autoscaling.v2beta1/MetricStatus (not in autoscaling/v2beta1)
// NB: no-generics for api.autoscaling.v2beta1/ObjectMetricSource (not in autoscaling/v2beta1)
// NB: no-generics for api.autoscaling.v2beta1/ObjectMetricStatus (not in autoscaling/v2beta1)
// NB: no-generics for api.autoscaling.v2beta1/PodsMetricSource (not in autoscaling/v2beta1)
// NB: no-generics for api.autoscaling.v2beta1/PodsMetricStatus (not in autoscaling/v2beta1)
// NB: no-generics for api.autoscaling.v2beta1/ResourceMetricSource (not in autoscaling/v2beta1)
// NB: no-generics for api.autoscaling.v2beta1/ResourceMetricStatus (not in autoscaling/v2beta1)
// TODO generics for horizontalpodautoscalers autoscaling/v2beta1
Loading