Skip to content

Commit

Permalink
remove fds stuff from pr
Browse files Browse the repository at this point in the history
Signed-off-by: clux <[email protected]>
  • Loading branch information
clux committed Oct 27, 2021
1 parent 89a574f commit 64ebaa4
Show file tree
Hide file tree
Showing 11 changed files with 1 addition and 142 deletions.
6 changes: 0 additions & 6 deletions k8s-pb-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,11 @@ license = "Apache-2.0"
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"
5 changes: 0 additions & 5 deletions k8s-pb-codegen/out/api.apps.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,3 @@ pub struct StatefulSetUpdateStrategy {
#[prost(message, optional, tag="2")]
pub rolling_update: ::core::option::Option<RollingUpdateStatefulSetStrategy>,
}
// TODO generics for controllerrevisions apps/v1
// TODO generics for daemonsets apps/v1
// TODO generics for deployments apps/v1
// TODO generics for replicasets apps/v1
// TODO generics for statefulsets apps/v1
1 change: 0 additions & 1 deletion k8s-pb-codegen/out/api.autoscaling.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,4 +482,3 @@ pub struct ScaleStatus {
#[prost(string, optional, tag="2")]
pub selector: ::core::option::Option<::prost::alloc::string::String>,
}
// TODO generics for horizontalpodautoscalers autoscaling/v1
1 change: 0 additions & 1 deletion k8s-pb-codegen/out/api.autoscaling.v2beta1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,4 +459,3 @@ pub struct ResourceMetricStatus {
#[prost(message, optional, tag="3")]
pub current_average_value: ::core::option::Option<super::super::super::apimachinery::pkg::api::resource::Quantity>,
}
// TODO generics for horizontalpodautoscalers autoscaling/v2beta1
1 change: 0 additions & 1 deletion k8s-pb-codegen/out/api.autoscaling.v2beta2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,4 +483,3 @@ pub struct ResourceMetricStatus {
#[prost(message, optional, tag="2")]
pub current: ::core::option::Option<MetricValueStatus>,
}
// TODO generics for horizontalpodautoscalers autoscaling/v2beta2
2 changes: 0 additions & 2 deletions k8s-pb-codegen/out/api.batch.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,5 +348,3 @@ pub struct UncountedTerminatedPods {
#[prost(string, repeated, tag="2")]
pub failed: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
}
// TODO generics for cronjobs batch/v1
// TODO generics for jobs batch/v1
1 change: 0 additions & 1 deletion k8s-pb-codegen/out/api.batch.v1beta1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,3 @@ pub struct JobTemplateSpec {
#[prost(message, optional, tag="2")]
pub spec: ::core::option::Option<super::v1::JobSpec>,
}
// TODO generics for cronjobs batch/v1beta1
1 change: 0 additions & 1 deletion k8s-pb-codegen/out/api.policy.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,3 @@ pub struct PodDisruptionBudgetStatus {
#[prost(message, repeated, tag="7")]
pub conditions: ::prost::alloc::vec::Vec<super::super::super::apimachinery::pkg::apis::meta::v1::Condition>,
}
// TODO generics for poddisruptionbudgets policy/v1
2 changes: 0 additions & 2 deletions k8s-pb-codegen/out/api.policy.v1beta1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,5 +415,3 @@ pub struct SupplementalGroupsStrategyOptions {
#[prost(message, repeated, tag="2")]
pub ranges: ::prost::alloc::vec::Vec<IdRange>,
}
// TODO generics for poddisruptionbudgets policy/v1beta1
// TODO generics for podsecuritypolicies policy/v1beta1
58 changes: 1 addition & 57 deletions k8s-pb-codegen/pbcodegen.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
use prost::Message;
use prost_types::{FileDescriptorProto, FileDescriptorSet};
#[macro_use]
extern crate log;
use anyhow::{Context, Result};
use pbcodegen::*;
use std::{
fs,
io::Write,
path::{Path, PathBuf},
};
use std::{fs, path::Path};

fn read_file<P: AsRef<Path>>(path: P) -> Result<String> {
Ok(fs::read_to_string(&path).with_context(|| format!("read {}", path.as_ref().display()))?)
Expand All @@ -31,55 +24,6 @@ fn main() -> Result<()> {
.out_dir("./out")
.compile_protos(protos.as_slice(), &["protos/"])?;

info!("loading api-resources");
let apif: String = read_file(root.join("openapi/api-resources.json"))?;
let apis: Vec<GenApiGroupResources> =
serde_json::from_str(&apif).with_context(|| "parse api-resources.json".to_string())?;

let buf =
std::fs::read(root.join("protos.fds")).with_context(|| "read protos.fds".to_string())?;
let fds = FileDescriptorSet::decode(&*buf).unwrap(); // pulls in proto::Message

// NB: FDS fields: https://github.com/tokio-rs/prost/blob/32bc87cd0b7301f6af1a338e9afd7717d0f42ca9/prost-types/src/protobuf.rs#L1-L7
// FDS usage: https://github.com/tokio-rs/prost/blob/32bc87cd0b7301f6af1a338e9afd7717d0f42ca9/prost-build/src/lib.rs#L765-L825
for f in fds.file {
if let Some(pkg) = f.package {
let pkgpath = Path::new("./out").join(format!("{}.rs", pkg));
// match the pkg name to a key in api-resources.json
info!("generating {}", pkg);
if let Some(apikey) = pkgname_to_api_key(&pkg) {
let mut codegen = vec![];
// find the corresponding apiGroupVersion
if let Some(apigr) = apis.iter().find(|ag| ag.apiGroupVersion == apikey) {
for dp in f.message_type {
if let Some(name) = dp.name {
let children: Vec<String> =
apigr.resources.iter().map(|gr| gr.kind.clone()).collect();
info!(" - found {:?} in {}", children, apikey);
if name.ends_with("List") {
continue;
}
// find the inner resource with matching kind name
if let Some(api) = apigr.resources.iter().find(|gr| name == gr.kind) {
codegen.push(api.generics());
} else {
debug!(" - no-generics for {}/{} (not in {})", pkg, name, apikey);
}
}
}
} else {
warn!("skipped: {} (didn't find {})", pkg, apikey);
}
let generics = codegen.join("\n");
let mut file = fs::OpenOptions::new()
.write(true)
.append(true)
.open(&pkgpath)?;
file.write(generics.as_bytes())?;
}
}
}

// Generate code in `src/` by reading files in `OUT_DIR`?
// Need to create `mod.rs` file for each level based on the filename, and write generated code in correct file.
Ok(())
Expand Down
65 changes: 0 additions & 65 deletions k8s-pb-codegen/src/lib.rs

This file was deleted.

0 comments on commit 64ebaa4

Please sign in to comment.