Skip to content

Commit

Permalink
Fix up some properties incorrectly marked as non-nullable.
Browse files Browse the repository at this point in the history
Fixes #9
  • Loading branch information
Arnavion committed Jun 23, 2018
1 parent e6bda30 commit 059fed3
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 64 deletions.
21 changes: 21 additions & 0 deletions k8s-openapi-tests/src/api_versions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#[test]
fn list() {
#[cfg(feature = "v1_7")] use ::k8s_openapi::v1_7 as k8s;

#[cfg(feature = "v1_8")] use ::k8s_openapi::v1_8 as k8s;

#[cfg(feature = "v1_9")] use ::k8s_openapi::v1_9 as k8s;

#[cfg(feature = "v1_10")] use ::k8s_openapi::v1_10 as k8s;

let client = ::Client::new().expect("couldn't create client");

let api_versions =
k8s::get_api_versions(&client)
.expect("couldn't get API versions");
let api_versions = match api_versions {
k8s::GetAPIVersionsResponse::Ok(api_versions) => api_versions,
other => panic!("couldn't get API versions: {:?}", other),
};
assert_eq!(api_versions.kind, Some("APIGroupList".to_string()));
}
53 changes: 53 additions & 0 deletions k8s-openapi-tests/src/custom_resource_definition.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#[test]
fn list() {
#[cfg(feature = "v1_8")] use ::k8s_openapi::v1_8::apiextensions_apiserver::pkg::apis::apiextensions::v1beta1 as apiextensions;
#[cfg(feature = "v1_8")] use ::k8s_openapi::v1_8::apimachinery::pkg::apis::meta::v1 as meta;

#[cfg(feature = "v1_9")] use ::k8s_openapi::v1_9::apiextensions_apiserver::pkg::apis::apiextensions::v1beta1 as apiextensions;
#[cfg(feature = "v1_9")] use ::k8s_openapi::v1_9::apimachinery::pkg::apis::meta::v1 as meta;

#[cfg(feature = "v1_10")] use ::k8s_openapi::v1_10::apiextensions_apiserver::pkg::apis::apiextensions::v1beta1 as apiextensions;
#[cfg(feature = "v1_10")] use ::k8s_openapi::v1_10::apimachinery::pkg::apis::meta::v1 as meta;

let client = ::Client::new().expect("couldn't create client");

let custom_resource_definition = apiextensions::CustomResourceDefinition {
metadata: Some(meta::ObjectMeta {
name: Some("foobars.k8s-openapi-tests-custom-resource-definition.com".to_string()),
..Default::default()
}),
spec: Some(apiextensions::CustomResourceDefinitionSpec {
group: "k8s-openapi-tests-custom-resource-definition.com".to_string(),
names: apiextensions::CustomResourceDefinitionNames {
kind: "FooBar".to_string(),
plural: "foobars".to_string(),
short_names: Some(vec!["fb".to_string()]),
singular: Some("foobar".to_string()),
..Default::default()
},
scope: "Namespaced".to_string(),
version: "v1".to_string(),
..Default::default()
}),
..Default::default()
};

let custom_resource_definition = apiextensions::CustomResourceDefinition::create_apiextensions_v1beta1_custom_resource_definition(
&client,
&custom_resource_definition,
None).expect("couldn't create custom resource definition");;
let custom_resource_definition: apiextensions::CustomResourceDefinition = match custom_resource_definition {
#[cfg(feature = "v1_8")] apiextensions::CreateApiextensionsV1beta1CustomResourceDefinitionResponse::Other(::http::StatusCode::CREATED, mut response) =>
response.json().expect("couldn't create custom resource definition"),
#[cfg(not(feature = "v1_8"))] apiextensions::CreateApiextensionsV1beta1CustomResourceDefinitionResponse::Created(custom_resource_definition) =>
custom_resource_definition,
other => panic!("couldn't create custom resource definition: {:?}", other),
};

let custom_resource_definition_self_link = {
let metadata = custom_resource_definition.metadata.expect("couldn't get custom resource definition metadata");
metadata.self_link.expect("couldn't get custom resource definition self link")
};

client.delete(&custom_resource_definition_self_link).expect("couldn't delete custom resource definition");
}
5 changes: 5 additions & 0 deletions k8s-openapi-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ struct KubeConfigUser {
client_key: std::path::PathBuf,
}

mod api_versions;

#[cfg(not(feature = "v1_7"))] // CRDs not supported in v1.7
mod custom_resource_definition;

mod deployment;

mod job;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct PodDisruptionBudgetStatus {
pub desired_healthy: i32,

/// DisruptedPods contains information about pods whose eviction was processed by the API server eviction subresource handler but has not yet been observed by the PodDisruptionBudget controller. A pod will be in this map from the time when the API server processed the eviction request to the time when the pod is seen by PDB controller as having been marked for deletion (or after a timeout). The key in the map is the name of the pod and the value is the time when the API server processed the eviction request. If the deletion didn't occur and a pod is still there it will be removed from the list automatically by PodDisruptionBudget controller after some time. If everything goes smooth this map should be empty for the most of the time. Large number of entries in the map may indicate problems with pod deletions.
pub disrupted_pods: ::std::collections::BTreeMap<String, ::v1_10::apimachinery::pkg::apis::meta::v1::Time>,
pub disrupted_pods: Option<::std::collections::BTreeMap<String, ::v1_10::apimachinery::pkg::apis::meta::v1::Time>>,

/// Number of pod disruptions that are currently allowed.
pub disruptions_allowed: i32,
Expand Down Expand Up @@ -84,7 +84,7 @@ impl<'de> ::serde::Deserialize<'de> for PodDisruptionBudgetStatus {
match key {
Field::Key_current_healthy => value_current_healthy = Some(::serde::de::MapAccess::next_value(&mut map)?),
Field::Key_desired_healthy => value_desired_healthy = Some(::serde::de::MapAccess::next_value(&mut map)?),
Field::Key_disrupted_pods => value_disrupted_pods = Some(::serde::de::MapAccess::next_value(&mut map)?),
Field::Key_disrupted_pods => value_disrupted_pods = ::serde::de::MapAccess::next_value(&mut map)?,
Field::Key_disruptions_allowed => value_disruptions_allowed = Some(::serde::de::MapAccess::next_value(&mut map)?),
Field::Key_expected_pods => value_expected_pods = Some(::serde::de::MapAccess::next_value(&mut map)?),
Field::Key_observed_generation => value_observed_generation = ::serde::de::MapAccess::next_value(&mut map)?,
Expand All @@ -95,7 +95,7 @@ impl<'de> ::serde::Deserialize<'de> for PodDisruptionBudgetStatus {
Ok(PodDisruptionBudgetStatus {
current_healthy: value_current_healthy.ok_or_else(|| ::serde::de::Error::missing_field("currentHealthy"))?,
desired_healthy: value_desired_healthy.ok_or_else(|| ::serde::de::Error::missing_field("desiredHealthy"))?,
disrupted_pods: value_disrupted_pods.ok_or_else(|| ::serde::de::Error::missing_field("disruptedPods"))?,
disrupted_pods: value_disrupted_pods,
disruptions_allowed: value_disruptions_allowed.ok_or_else(|| ::serde::de::Error::missing_field("disruptionsAllowed"))?,
expected_pods: value_expected_pods.ok_or_else(|| ::serde::de::Error::missing_field("expectedPods"))?,
observed_generation: value_observed_generation,
Expand Down Expand Up @@ -125,14 +125,16 @@ impl ::serde::Serialize for PodDisruptionBudgetStatus {
0 +
1 +
1 +
1 +
self.disrupted_pods.as_ref().map_or(0, |_| 1) +
1 +
1 +
self.observed_generation.as_ref().map_or(0, |_| 1),
)?;
::serde::ser::SerializeStruct::serialize_field(&mut state, "currentHealthy", &self.current_healthy)?;
::serde::ser::SerializeStruct::serialize_field(&mut state, "desiredHealthy", &self.desired_healthy)?;
::serde::ser::SerializeStruct::serialize_field(&mut state, "disruptedPods", &self.disrupted_pods)?;
if let Some(value) = &self.disrupted_pods {
::serde::ser::SerializeStruct::serialize_field(&mut state, "disruptedPods", value)?;
}
::serde::ser::SerializeStruct::serialize_field(&mut state, "disruptionsAllowed", &self.disruptions_allowed)?;
::serde::ser::SerializeStruct::serialize_field(&mut state, "expectedPods", &self.expected_pods)?;
if let Some(value) = &self.observed_generation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct CustomResourceDefinitionStatus {
pub accepted_names: ::v1_10::apiextensions_apiserver::pkg::apis::apiextensions::v1beta1::CustomResourceDefinitionNames,

/// Conditions indicate state for particular aspects of a CustomResourceDefinition
pub conditions: Vec<::v1_10::apiextensions_apiserver::pkg::apis::apiextensions::v1beta1::CustomResourceDefinitionCondition>,
pub conditions: Option<Vec<::v1_10::apiextensions_apiserver::pkg::apis::apiextensions::v1beta1::CustomResourceDefinitionCondition>>,
}

impl<'de> ::serde::Deserialize<'de> for CustomResourceDefinitionStatus {
Expand Down Expand Up @@ -59,14 +59,14 @@ impl<'de> ::serde::Deserialize<'de> for CustomResourceDefinitionStatus {
while let Some(key) = ::serde::de::MapAccess::next_key::<Field>(&mut map)? {
match key {
Field::Key_accepted_names => value_accepted_names = Some(::serde::de::MapAccess::next_value(&mut map)?),
Field::Key_conditions => value_conditions = Some(::serde::de::MapAccess::next_value(&mut map)?),
Field::Key_conditions => value_conditions = ::serde::de::MapAccess::next_value(&mut map)?,
Field::Other => { let _: ::serde::de::IgnoredAny = ::serde::de::MapAccess::next_value(&mut map)?; },
}
}

Ok(CustomResourceDefinitionStatus {
accepted_names: value_accepted_names.ok_or_else(|| ::serde::de::Error::missing_field("acceptedNames"))?,
conditions: value_conditions.ok_or_else(|| ::serde::de::Error::missing_field("conditions"))?,
conditions: value_conditions,
})
}
}
Expand All @@ -88,10 +88,12 @@ impl ::serde::Serialize for CustomResourceDefinitionStatus {
"CustomResourceDefinitionStatus",
0 +
1 +
1,
self.conditions.as_ref().map_or(0, |_| 1),
)?;
::serde::ser::SerializeStruct::serialize_field(&mut state, "acceptedNames", &self.accepted_names)?;
::serde::ser::SerializeStruct::serialize_field(&mut state, "conditions", &self.conditions)?;
if let Some(value) = &self.conditions {
::serde::ser::SerializeStruct::serialize_field(&mut state, "conditions", value)?;
}
::serde::ser::SerializeStruct::end(state)
}
}
12 changes: 7 additions & 5 deletions k8s-openapi/src/v1_10/apimachinery/pkg/apis/meta/v1/api_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct APIGroup {
pub preferred_version: Option<::v1_10::apimachinery::pkg::apis::meta::v1::GroupVersionForDiscovery>,

/// a map of client CIDR to server address that is serving this group. This is to help clients reach servers in the most network-efficient way possible. Clients can use the appropriate server address as per the CIDR that they match. In case of multiple matches, clients should use the longest matching CIDR. The server returns only those CIDRs that it thinks that the client can match. For example: the master will return an internal IP CIDR only, if the client reaches the server using an internal IP. Server looks at X-Forwarded-For header or X-Real-Ip header or request.RemoteAddr (in that order) to get the client IP.
pub server_address_by_client_cidrs: Vec<::v1_10::apimachinery::pkg::apis::meta::v1::ServerAddressByClientCIDR>,
pub server_address_by_client_cidrs: Option<Vec<::v1_10::apimachinery::pkg::apis::meta::v1::ServerAddressByClientCIDR>>,

/// versions are the versions supported in this group.
pub versions: Vec<::v1_10::apimachinery::pkg::apis::meta::v1::GroupVersionForDiscovery>,
Expand Down Expand Up @@ -86,7 +86,7 @@ impl<'de> ::serde::Deserialize<'de> for APIGroup {
Field::Key_kind => value_kind = ::serde::de::MapAccess::next_value(&mut map)?,
Field::Key_name => value_name = Some(::serde::de::MapAccess::next_value(&mut map)?),
Field::Key_preferred_version => value_preferred_version = ::serde::de::MapAccess::next_value(&mut map)?,
Field::Key_server_address_by_client_cidrs => value_server_address_by_client_cidrs = Some(::serde::de::MapAccess::next_value(&mut map)?),
Field::Key_server_address_by_client_cidrs => value_server_address_by_client_cidrs = ::serde::de::MapAccess::next_value(&mut map)?,
Field::Key_versions => value_versions = Some(::serde::de::MapAccess::next_value(&mut map)?),
Field::Other => { let _: ::serde::de::IgnoredAny = ::serde::de::MapAccess::next_value(&mut map)?; },
}
Expand All @@ -97,7 +97,7 @@ impl<'de> ::serde::Deserialize<'de> for APIGroup {
kind: value_kind,
name: value_name.ok_or_else(|| ::serde::de::Error::missing_field("name"))?,
preferred_version: value_preferred_version,
server_address_by_client_cidrs: value_server_address_by_client_cidrs.ok_or_else(|| ::serde::de::Error::missing_field("serverAddressByClientCIDRs"))?,
server_address_by_client_cidrs: value_server_address_by_client_cidrs,
versions: value_versions.ok_or_else(|| ::serde::de::Error::missing_field("versions"))?,
})
}
Expand Down Expand Up @@ -127,7 +127,7 @@ impl ::serde::Serialize for APIGroup {
self.kind.as_ref().map_or(0, |_| 1) +
1 +
self.preferred_version.as_ref().map_or(0, |_| 1) +
1 +
self.server_address_by_client_cidrs.as_ref().map_or(0, |_| 1) +
1,
)?;
if let Some(value) = &self.api_version {
Expand All @@ -140,7 +140,9 @@ impl ::serde::Serialize for APIGroup {
if let Some(value) = &self.preferred_version {
::serde::ser::SerializeStruct::serialize_field(&mut state, "preferredVersion", value)?;
}
::serde::ser::SerializeStruct::serialize_field(&mut state, "serverAddressByClientCIDRs", &self.server_address_by_client_cidrs)?;
if let Some(value) = &self.server_address_by_client_cidrs {
::serde::ser::SerializeStruct::serialize_field(&mut state, "serverAddressByClientCIDRs", value)?;
}
::serde::ser::SerializeStruct::serialize_field(&mut state, "versions", &self.versions)?;
::serde::ser::SerializeStruct::end(state)
}
Expand Down
12 changes: 7 additions & 5 deletions k8s-openapi/src/v1_7/apimachinery/pkg/apis/meta/v1/api_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct APIGroup {
pub preferred_version: Option<::v1_7::apimachinery::pkg::apis::meta::v1::GroupVersionForDiscovery>,

/// a map of client CIDR to server address that is serving this group. This is to help clients reach servers in the most network-efficient way possible. Clients can use the appropriate server address as per the CIDR that they match. In case of multiple matches, clients should use the longest matching CIDR. The server returns only those CIDRs that it thinks that the client can match. For example: the master will return an internal IP CIDR only, if the client reaches the server using an internal IP. Server looks at X-Forwarded-For header or X-Real-Ip header or request.RemoteAddr (in that order) to get the client IP.
pub server_address_by_client_cidrs: Vec<::v1_7::apimachinery::pkg::apis::meta::v1::ServerAddressByClientCIDR>,
pub server_address_by_client_cidrs: Option<Vec<::v1_7::apimachinery::pkg::apis::meta::v1::ServerAddressByClientCIDR>>,

/// versions are the versions supported in this group.
pub versions: Vec<::v1_7::apimachinery::pkg::apis::meta::v1::GroupVersionForDiscovery>,
Expand Down Expand Up @@ -86,7 +86,7 @@ impl<'de> ::serde::Deserialize<'de> for APIGroup {
Field::Key_kind => value_kind = ::serde::de::MapAccess::next_value(&mut map)?,
Field::Key_name => value_name = Some(::serde::de::MapAccess::next_value(&mut map)?),
Field::Key_preferred_version => value_preferred_version = ::serde::de::MapAccess::next_value(&mut map)?,
Field::Key_server_address_by_client_cidrs => value_server_address_by_client_cidrs = Some(::serde::de::MapAccess::next_value(&mut map)?),
Field::Key_server_address_by_client_cidrs => value_server_address_by_client_cidrs = ::serde::de::MapAccess::next_value(&mut map)?,
Field::Key_versions => value_versions = Some(::serde::de::MapAccess::next_value(&mut map)?),
Field::Other => { let _: ::serde::de::IgnoredAny = ::serde::de::MapAccess::next_value(&mut map)?; },
}
Expand All @@ -97,7 +97,7 @@ impl<'de> ::serde::Deserialize<'de> for APIGroup {
kind: value_kind,
name: value_name.ok_or_else(|| ::serde::de::Error::missing_field("name"))?,
preferred_version: value_preferred_version,
server_address_by_client_cidrs: value_server_address_by_client_cidrs.ok_or_else(|| ::serde::de::Error::missing_field("serverAddressByClientCIDRs"))?,
server_address_by_client_cidrs: value_server_address_by_client_cidrs,
versions: value_versions.ok_or_else(|| ::serde::de::Error::missing_field("versions"))?,
})
}
Expand Down Expand Up @@ -127,7 +127,7 @@ impl ::serde::Serialize for APIGroup {
self.kind.as_ref().map_or(0, |_| 1) +
1 +
self.preferred_version.as_ref().map_or(0, |_| 1) +
1 +
self.server_address_by_client_cidrs.as_ref().map_or(0, |_| 1) +
1,
)?;
if let Some(value) = &self.api_version {
Expand All @@ -140,7 +140,9 @@ impl ::serde::Serialize for APIGroup {
if let Some(value) = &self.preferred_version {
::serde::ser::SerializeStruct::serialize_field(&mut state, "preferredVersion", value)?;
}
::serde::ser::SerializeStruct::serialize_field(&mut state, "serverAddressByClientCIDRs", &self.server_address_by_client_cidrs)?;
if let Some(value) = &self.server_address_by_client_cidrs {
::serde::ser::SerializeStruct::serialize_field(&mut state, "serverAddressByClientCIDRs", value)?;
}
::serde::ser::SerializeStruct::serialize_field(&mut state, "versions", &self.versions)?;
::serde::ser::SerializeStruct::end(state)
}
Expand Down
Loading

0 comments on commit 059fed3

Please sign in to comment.