Skip to content

Commit

Permalink
Make api::core::v1::ContainerImage::names optional.
Browse files Browse the repository at this point in the history
Fixes #93
  • Loading branch information
Arnavion committed May 13, 2021
1 parent 8bf402c commit 0a9d7e4
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 50 deletions.
19 changes: 19 additions & 0 deletions k8s-openapi-codegen/src/fixups/upstream_bugs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ pub(crate) fn deployment_rollback_create_response_type(spec: &mut crate::swagger
//
// Override it to be optional to achieve the same effect.
pub(crate) mod optional_properties {
// `ContainerImage::names`
//
// Ref: https://github.com/kubernetes/kubernetes/issues/93606
pub(crate) fn containerimage(spec: &mut crate::swagger20::Spec) -> Result<(), crate::Error> {
let definition_path = crate::swagger20::DefinitionPath("io.k8s.api.core.v1.ContainerImage".to_owned());
if let Some(definition) = spec.definitions.get_mut(&definition_path) {
if let crate::swagger20::SchemaKind::Properties(properties) = &mut definition.kind {
if let Some(property) = properties.get_mut(&crate::swagger20::PropertyName("names".to_string())) {
if property.1 {
property.1 = false;
return Ok(());
}
}
}
}

Err("never applied ContainerImage optional properties override".into())
}

// `CustomResourceDefinitionStatus::conditions`
//
// Ref: https://github.com/kubernetes/kubernetes/pull/64996
Expand Down
10 changes: 10 additions & 0 deletions k8s-openapi-codegen/src/supported_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl SupportedVersion {
let upstream_bugs_fixups: &[fn(&mut crate::swagger20::Spec) -> Result<(), crate::Error>] = match self {
SupportedVersion::V1_11 => &[
crate::fixups::upstream_bugs::deployment_rollback_create_response_type,
crate::fixups::upstream_bugs::optional_properties::containerimage,
crate::fixups::upstream_bugs::optional_properties::crdstatus,
crate::fixups::upstream_bugs::optional_properties::poddisruptionbudgetstatus,
crate::fixups::upstream_bugs::raw_extension_ty,
Expand All @@ -84,48 +85,57 @@ impl SupportedVersion {

SupportedVersion::V1_12 => &[
crate::fixups::upstream_bugs::connect_options_gvk,
crate::fixups::upstream_bugs::optional_properties::containerimage,
crate::fixups::upstream_bugs::optional_properties::crdstatus,
crate::fixups::upstream_bugs::raw_extension_ty,
crate::fixups::upstream_bugs::remove_compat_refs,
],

SupportedVersion::V1_13 => &[
crate::fixups::upstream_bugs::connect_options_gvk,
crate::fixups::upstream_bugs::optional_properties::containerimage,
crate::fixups::upstream_bugs::optional_properties::crdstatus,
crate::fixups::upstream_bugs::raw_extension_ty,
crate::fixups::upstream_bugs::remove_compat_refs,
],

SupportedVersion::V1_14 => &[
crate::fixups::upstream_bugs::connect_options_gvk,
crate::fixups::upstream_bugs::optional_properties::containerimage,
crate::fixups::upstream_bugs::optional_properties::crdstatus,
crate::fixups::upstream_bugs::raw_extension_ty,
],

SupportedVersion::V1_15 => &[
crate::fixups::upstream_bugs::connect_options_gvk,
crate::fixups::upstream_bugs::optional_properties::containerimage,
crate::fixups::upstream_bugs::optional_properties::crdstatus,
crate::fixups::upstream_bugs::raw_extension_ty,
],

SupportedVersion::V1_16 => &[
crate::fixups::upstream_bugs::connect_options_gvk,
crate::fixups::upstream_bugs::optional_properties::containerimage,
],

SupportedVersion::V1_17 => &[
crate::fixups::upstream_bugs::connect_options_gvk,
crate::fixups::upstream_bugs::optional_properties::containerimage,
],

SupportedVersion::V1_18 => &[
crate::fixups::upstream_bugs::connect_options_gvk,
crate::fixups::upstream_bugs::optional_properties::containerimage,
],

SupportedVersion::V1_19 => &[
crate::fixups::upstream_bugs::connect_options_gvk,
crate::fixups::upstream_bugs::optional_properties::containerimage,
],

SupportedVersion::V1_20 => &[
crate::fixups::upstream_bugs::connect_options_gvk,
crate::fixups::upstream_bugs::optional_properties::containerimage,
],
};

Expand Down
12 changes: 7 additions & 5 deletions src/v1_11/api/core/v1/container_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ContainerImage {
/// Names by which this image is known. e.g. \["k8s.gcr.io/hyperkube:v1.0.7", "dockerhub.io/google_containers/hyperkube:v1.0.7"\]
pub names: Vec<String>,
pub names: Option<Vec<String>>,

/// The size of the image in bytes.
pub size_bytes: Option<i64>,
Expand Down Expand Up @@ -58,14 +58,14 @@ impl<'de> crate::serde::Deserialize<'de> for ContainerImage {

while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
match key {
Field::Key_names => value_names = Some(crate::serde::de::MapAccess::next_value(&mut map)?),
Field::Key_names => value_names = crate::serde::de::MapAccess::next_value(&mut map)?,
Field::Key_size_bytes => value_size_bytes = crate::serde::de::MapAccess::next_value(&mut map)?,
Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
}
}

Ok(ContainerImage {
names: value_names.ok_or_else(|| crate::serde::de::Error::missing_field("names"))?,
names: value_names,
size_bytes: value_size_bytes,
})
}
Expand All @@ -86,10 +86,12 @@ impl crate::serde::Serialize for ContainerImage {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
let mut state = serializer.serialize_struct(
"ContainerImage",
1 +
self.names.as_ref().map_or(0, |_| 1) +
self.size_bytes.as_ref().map_or(0, |_| 1),
)?;
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "names", &self.names)?;
if let Some(value) = &self.names {
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "names", value)?;
}
if let Some(value) = &self.size_bytes {
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "sizeBytes", value)?;
}
Expand Down
12 changes: 7 additions & 5 deletions src/v1_12/api/core/v1/container_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ContainerImage {
/// Names by which this image is known. e.g. \["k8s.gcr.io/hyperkube:v1.0.7", "dockerhub.io/google_containers/hyperkube:v1.0.7"\]
pub names: Vec<String>,
pub names: Option<Vec<String>>,

/// The size of the image in bytes.
pub size_bytes: Option<i64>,
Expand Down Expand Up @@ -58,14 +58,14 @@ impl<'de> crate::serde::Deserialize<'de> for ContainerImage {

while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
match key {
Field::Key_names => value_names = Some(crate::serde::de::MapAccess::next_value(&mut map)?),
Field::Key_names => value_names = crate::serde::de::MapAccess::next_value(&mut map)?,
Field::Key_size_bytes => value_size_bytes = crate::serde::de::MapAccess::next_value(&mut map)?,
Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
}
}

Ok(ContainerImage {
names: value_names.ok_or_else(|| crate::serde::de::Error::missing_field("names"))?,
names: value_names,
size_bytes: value_size_bytes,
})
}
Expand All @@ -86,10 +86,12 @@ impl crate::serde::Serialize for ContainerImage {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
let mut state = serializer.serialize_struct(
"ContainerImage",
1 +
self.names.as_ref().map_or(0, |_| 1) +
self.size_bytes.as_ref().map_or(0, |_| 1),
)?;
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "names", &self.names)?;
if let Some(value) = &self.names {
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "names", value)?;
}
if let Some(value) = &self.size_bytes {
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "sizeBytes", value)?;
}
Expand Down
12 changes: 7 additions & 5 deletions src/v1_13/api/core/v1/container_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ContainerImage {
/// Names by which this image is known. e.g. \["k8s.gcr.io/hyperkube:v1.0.7", "dockerhub.io/google_containers/hyperkube:v1.0.7"\]
pub names: Vec<String>,
pub names: Option<Vec<String>>,

/// The size of the image in bytes.
pub size_bytes: Option<i64>,
Expand Down Expand Up @@ -58,14 +58,14 @@ impl<'de> crate::serde::Deserialize<'de> for ContainerImage {

while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
match key {
Field::Key_names => value_names = Some(crate::serde::de::MapAccess::next_value(&mut map)?),
Field::Key_names => value_names = crate::serde::de::MapAccess::next_value(&mut map)?,
Field::Key_size_bytes => value_size_bytes = crate::serde::de::MapAccess::next_value(&mut map)?,
Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
}
}

Ok(ContainerImage {
names: value_names.ok_or_else(|| crate::serde::de::Error::missing_field("names"))?,
names: value_names,
size_bytes: value_size_bytes,
})
}
Expand All @@ -86,10 +86,12 @@ impl crate::serde::Serialize for ContainerImage {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
let mut state = serializer.serialize_struct(
"ContainerImage",
1 +
self.names.as_ref().map_or(0, |_| 1) +
self.size_bytes.as_ref().map_or(0, |_| 1),
)?;
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "names", &self.names)?;
if let Some(value) = &self.names {
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "names", value)?;
}
if let Some(value) = &self.size_bytes {
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "sizeBytes", value)?;
}
Expand Down
12 changes: 7 additions & 5 deletions src/v1_14/api/core/v1/container_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ContainerImage {
/// Names by which this image is known. e.g. \["k8s.gcr.io/hyperkube:v1.0.7", "dockerhub.io/google_containers/hyperkube:v1.0.7"\]
pub names: Vec<String>,
pub names: Option<Vec<String>>,

/// The size of the image in bytes.
pub size_bytes: Option<i64>,
Expand Down Expand Up @@ -58,14 +58,14 @@ impl<'de> crate::serde::Deserialize<'de> for ContainerImage {

while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
match key {
Field::Key_names => value_names = Some(crate::serde::de::MapAccess::next_value(&mut map)?),
Field::Key_names => value_names = crate::serde::de::MapAccess::next_value(&mut map)?,
Field::Key_size_bytes => value_size_bytes = crate::serde::de::MapAccess::next_value(&mut map)?,
Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
}
}

Ok(ContainerImage {
names: value_names.ok_or_else(|| crate::serde::de::Error::missing_field("names"))?,
names: value_names,
size_bytes: value_size_bytes,
})
}
Expand All @@ -86,10 +86,12 @@ impl crate::serde::Serialize for ContainerImage {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
let mut state = serializer.serialize_struct(
"ContainerImage",
1 +
self.names.as_ref().map_or(0, |_| 1) +
self.size_bytes.as_ref().map_or(0, |_| 1),
)?;
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "names", &self.names)?;
if let Some(value) = &self.names {
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "names", value)?;
}
if let Some(value) = &self.size_bytes {
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "sizeBytes", value)?;
}
Expand Down
12 changes: 7 additions & 5 deletions src/v1_15/api/core/v1/container_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ContainerImage {
/// Names by which this image is known. e.g. \["k8s.gcr.io/hyperkube:v1.0.7", "dockerhub.io/google_containers/hyperkube:v1.0.7"\]
pub names: Vec<String>,
pub names: Option<Vec<String>>,

/// The size of the image in bytes.
pub size_bytes: Option<i64>,
Expand Down Expand Up @@ -58,14 +58,14 @@ impl<'de> crate::serde::Deserialize<'de> for ContainerImage {

while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
match key {
Field::Key_names => value_names = Some(crate::serde::de::MapAccess::next_value(&mut map)?),
Field::Key_names => value_names = crate::serde::de::MapAccess::next_value(&mut map)?,
Field::Key_size_bytes => value_size_bytes = crate::serde::de::MapAccess::next_value(&mut map)?,
Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
}
}

Ok(ContainerImage {
names: value_names.ok_or_else(|| crate::serde::de::Error::missing_field("names"))?,
names: value_names,
size_bytes: value_size_bytes,
})
}
Expand All @@ -86,10 +86,12 @@ impl crate::serde::Serialize for ContainerImage {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
let mut state = serializer.serialize_struct(
"ContainerImage",
1 +
self.names.as_ref().map_or(0, |_| 1) +
self.size_bytes.as_ref().map_or(0, |_| 1),
)?;
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "names", &self.names)?;
if let Some(value) = &self.names {
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "names", value)?;
}
if let Some(value) = &self.size_bytes {
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "sizeBytes", value)?;
}
Expand Down
12 changes: 7 additions & 5 deletions src/v1_16/api/core/v1/container_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ContainerImage {
/// Names by which this image is known. e.g. \["k8s.gcr.io/hyperkube:v1.0.7", "dockerhub.io/google_containers/hyperkube:v1.0.7"\]
pub names: Vec<String>,
pub names: Option<Vec<String>>,

/// The size of the image in bytes.
pub size_bytes: Option<i64>,
Expand Down Expand Up @@ -58,14 +58,14 @@ impl<'de> crate::serde::Deserialize<'de> for ContainerImage {

while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
match key {
Field::Key_names => value_names = Some(crate::serde::de::MapAccess::next_value(&mut map)?),
Field::Key_names => value_names = crate::serde::de::MapAccess::next_value(&mut map)?,
Field::Key_size_bytes => value_size_bytes = crate::serde::de::MapAccess::next_value(&mut map)?,
Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
}
}

Ok(ContainerImage {
names: value_names.ok_or_else(|| crate::serde::de::Error::missing_field("names"))?,
names: value_names,
size_bytes: value_size_bytes,
})
}
Expand All @@ -86,10 +86,12 @@ impl crate::serde::Serialize for ContainerImage {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
let mut state = serializer.serialize_struct(
"ContainerImage",
1 +
self.names.as_ref().map_or(0, |_| 1) +
self.size_bytes.as_ref().map_or(0, |_| 1),
)?;
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "names", &self.names)?;
if let Some(value) = &self.names {
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "names", value)?;
}
if let Some(value) = &self.size_bytes {
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "sizeBytes", value)?;
}
Expand Down
12 changes: 7 additions & 5 deletions src/v1_17/api/core/v1/container_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ContainerImage {
/// Names by which this image is known. e.g. \["k8s.gcr.io/hyperkube:v1.0.7", "dockerhub.io/google_containers/hyperkube:v1.0.7"\]
pub names: Vec<String>,
pub names: Option<Vec<String>>,

/// The size of the image in bytes.
pub size_bytes: Option<i64>,
Expand Down Expand Up @@ -58,14 +58,14 @@ impl<'de> crate::serde::Deserialize<'de> for ContainerImage {

while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
match key {
Field::Key_names => value_names = Some(crate::serde::de::MapAccess::next_value(&mut map)?),
Field::Key_names => value_names = crate::serde::de::MapAccess::next_value(&mut map)?,
Field::Key_size_bytes => value_size_bytes = crate::serde::de::MapAccess::next_value(&mut map)?,
Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
}
}

Ok(ContainerImage {
names: value_names.ok_or_else(|| crate::serde::de::Error::missing_field("names"))?,
names: value_names,
size_bytes: value_size_bytes,
})
}
Expand All @@ -86,10 +86,12 @@ impl crate::serde::Serialize for ContainerImage {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
let mut state = serializer.serialize_struct(
"ContainerImage",
1 +
self.names.as_ref().map_or(0, |_| 1) +
self.size_bytes.as_ref().map_or(0, |_| 1),
)?;
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "names", &self.names)?;
if let Some(value) = &self.names {
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "names", value)?;
}
if let Some(value) = &self.size_bytes {
crate::serde::ser::SerializeStruct::serialize_field(&mut state, "sizeBytes", value)?;
}
Expand Down
Loading

0 comments on commit 0a9d7e4

Please sign in to comment.