Skip to content

Commit

Permalink
Allow empty CAPI variable value to be deserialized without errors
Browse files Browse the repository at this point in the history
Signed-off-by: Danil Grigorev <[email protected]>
  • Loading branch information
Danil-Grigorev committed Apr 25, 2024
1 parent 3e04c2f commit 8422679
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 36 deletions.
12 changes: 7 additions & 5 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ TAG := "dev"
HOME_DIR := env_var('HOME')
YQ_VERSION := "v4.43.1"
YQ_BIN := "_out/yq"
OUT_DIR := "_out"
KOPIUM_BIN := "_out/bin/kopium"
KUSTOMIZE_VERSION := "v5.4.1"
KUSTOMIZE_BIN := "_out/kustomize"
ARCH := if arch() == "aarch64" { "arm64"} else { "amd64" }
Expand All @@ -21,10 +23,10 @@ generate:

# generates files for CRDS
generate-crds: _create-out-dir _install-kopium _download-yq
just _generate-kopium-url {{home_directory()}}/.cargo/bin/kopium "https://raw.githubusercontent.com/kubernetes-sigs/cluster-api/main/config/crd/bases/cluster.x-k8s.io_clusters.yaml" "src/api/capi_cluster.rs" ""
just _generate-kopium-url {{home_directory()}}/.cargo/bin/kopium "https://raw.githubusercontent.com/kubernetes-sigs/cluster-api/main/config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml" "src/api/capi_clusterclass.rs" ""
just _generate-kopium-url {{home_directory()}}/.cargo/bin/kopium "https://raw.githubusercontent.com/rancher/fleet/main/charts/fleet-crd/templates/crds.yaml" "src/api/fleet_cluster.rs" "select(.spec.names.singular==\"cluster\")" "--no-condition"
just _generate-kopium-url {{home_directory()}}/.cargo/bin/kopium "https://raw.githubusercontent.com/rancher/fleet/main/charts/fleet-crd/templates/crds.yaml" "src/api/fleet_clustergroup.rs" "select(.spec.names.singular==\"clustergroup\")" "--no-condition"
just _generate-kopium-url {{KOPIUM_BIN}} "https://raw.githubusercontent.com/kubernetes-sigs/cluster-api/main/config/crd/bases/cluster.x-k8s.io_clusters.yaml" "src/api/capi_cluster.rs" ""
just _generate-kopium-url {{KOPIUM_BIN}} "https://raw.githubusercontent.com/kubernetes-sigs/cluster-api/main/config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml" "src/api/capi_clusterclass.rs" ""
just _generate-kopium-url {{KOPIUM_BIN}} "https://raw.githubusercontent.com/rancher/fleet/main/charts/fleet-crd/templates/crds.yaml" "src/api/fleet_cluster.rs" "select(.spec.names.singular==\"cluster\")" "--no-condition"
just _generate-kopium-url {{KOPIUM_BIN}} "https://raw.githubusercontent.com/rancher/fleet/main/charts/fleet-crd/templates/crds.yaml" "src/api/fleet_clustergroup.rs" "select(.spec.names.singular==\"clustergroup\")" "--no-condition"

[private]
_generate-kopium-url kpath="" source="" dest="" yqexp="." condition="":
Expand Down Expand Up @@ -139,7 +141,7 @@ test-import: start-dev deploy deploy-child-cluster deploy-crs
# Install kopium
[private]
_install-kopium:
cargo install kopium
cargo install --git https://github.com/kube-rs/kopium.git --branch main --root {{OUT_DIR}}

# Download kustomize
[private]
Expand Down
20 changes: 12 additions & 8 deletions src/api/capi_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
// kopium command: kopium -D Default -f -
// kopium version: 0.18.0

use kube::CustomResource;
use serde::{Serialize, Deserialize};
use std::collections::BTreeMap;
use k8s_openapi::apimachinery::pkg::util::intstr::IntOrString;
use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition;
#[allow(unused_imports)]
mod prelude {
pub use kube::CustomResource;
pub use serde::{Serialize, Deserialize};
pub use std::collections::BTreeMap;
pub use k8s_openapi::apimachinery::pkg::util::intstr::IntOrString;
pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition;
}
use self::prelude::*;

#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, Default)]
#[kube(group = "cluster.x-k8s.io", version = "v1beta1", kind = "Cluster", plural = "clusters")]
Expand Down Expand Up @@ -179,7 +183,7 @@ pub struct ClusterTopologyVariables {
#[serde(default, skip_serializing_if = "Option::is_none", rename = "definitionFrom")]
pub definition_from: Option<String>,
pub name: String,
pub value: BTreeMap<String, serde_json::Value>,
pub value: serde_json::Value,
}

#[derive(Serialize, Deserialize, Clone, Debug, Default)]
Expand Down Expand Up @@ -308,7 +312,7 @@ pub struct ClusterTopologyWorkersMachineDeploymentsVariablesOverrides {
#[serde(default, skip_serializing_if = "Option::is_none", rename = "definitionFrom")]
pub definition_from: Option<String>,
pub name: String,
pub value: BTreeMap<String, serde_json::Value>,
pub value: serde_json::Value,
}

#[derive(Serialize, Deserialize, Clone, Debug, Default)]
Expand Down Expand Up @@ -352,7 +356,7 @@ pub struct ClusterTopologyWorkersMachinePoolsVariablesOverrides {
#[serde(default, skip_serializing_if = "Option::is_none", rename = "definitionFrom")]
pub definition_from: Option<String>,
pub name: String,
pub value: BTreeMap<String, serde_json::Value>,
pub value: serde_json::Value,
}

#[derive(Serialize, Deserialize, Clone, Debug, Default)]
Expand Down
36 changes: 20 additions & 16 deletions src/api/capi_clusterclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
// kopium command: kopium -D Default -f -
// kopium version: 0.18.0

use kube::CustomResource;
use serde::{Serialize, Deserialize};
use std::collections::BTreeMap;
use k8s_openapi::apimachinery::pkg::util::intstr::IntOrString;
use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition;
#[allow(unused_imports)]
mod prelude {
pub use kube::CustomResource;
pub use serde::{Serialize, Deserialize};
pub use std::collections::BTreeMap;
pub use k8s_openapi::apimachinery::pkg::util::intstr::IntOrString;
pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition;
}
use self::prelude::*;

#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, Default)]
#[kube(group = "cluster.x-k8s.io", version = "v1beta1", kind = "ClusterClass", plural = "clusterclasses")]
Expand Down Expand Up @@ -191,7 +195,7 @@ pub struct ClusterClassPatchesDefinitionsJsonPatches {
pub op: String,
pub path: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub value: Option<BTreeMap<String, serde_json::Value>>,
pub value: Option<serde_json::Value>,
#[serde(default, skip_serializing_if = "Option::is_none", rename = "valueFrom")]
pub value_from: Option<ClusterClassPatchesDefinitionsJsonPatchesValueFrom>,
}
Expand Down Expand Up @@ -275,23 +279,23 @@ pub struct ClusterClassVariablesSchema {
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct ClusterClassVariablesSchemaOpenApiv3Schema {
#[serde(default, skip_serializing_if = "Option::is_none", rename = "additionalProperties")]
pub additional_properties: Option<BTreeMap<String, serde_json::Value>>,
pub additional_properties: Option<serde_json::Value>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub default: Option<BTreeMap<String, serde_json::Value>>,
pub default: Option<serde_json::Value>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none", rename = "enum")]
pub r#enum: Option<Vec<BTreeMap<String, serde_json::Value>>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub example: Option<BTreeMap<String, serde_json::Value>>,
pub example: Option<serde_json::Value>,
#[serde(default, skip_serializing_if = "Option::is_none", rename = "exclusiveMaximum")]
pub exclusive_maximum: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none", rename = "exclusiveMinimum")]
pub exclusive_minimum: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub format: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub items: Option<BTreeMap<String, serde_json::Value>>,
pub items: Option<serde_json::Value>,
#[serde(default, skip_serializing_if = "Option::is_none", rename = "maxItems")]
pub max_items: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none", rename = "maxLength")]
Expand All @@ -307,7 +311,7 @@ pub struct ClusterClassVariablesSchemaOpenApiv3Schema {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub pattern: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub properties: Option<BTreeMap<String, serde_json::Value>>,
pub properties: Option<serde_json::Value>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub required: Option<Vec<String>>,
#[serde(rename = "type")]
Expand Down Expand Up @@ -621,23 +625,23 @@ pub struct ClusterClassStatusVariablesDefinitionsSchema {
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct ClusterClassStatusVariablesDefinitionsSchemaOpenApiv3Schema {
#[serde(default, skip_serializing_if = "Option::is_none", rename = "additionalProperties")]
pub additional_properties: Option<BTreeMap<String, serde_json::Value>>,
pub additional_properties: Option<serde_json::Value>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub default: Option<BTreeMap<String, serde_json::Value>>,
pub default: Option<serde_json::Value>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none", rename = "enum")]
pub r#enum: Option<Vec<BTreeMap<String, serde_json::Value>>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub example: Option<BTreeMap<String, serde_json::Value>>,
pub example: Option<serde_json::Value>,
#[serde(default, skip_serializing_if = "Option::is_none", rename = "exclusiveMaximum")]
pub exclusive_maximum: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none", rename = "exclusiveMinimum")]
pub exclusive_minimum: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub format: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub items: Option<BTreeMap<String, serde_json::Value>>,
pub items: Option<serde_json::Value>,
#[serde(default, skip_serializing_if = "Option::is_none", rename = "maxItems")]
pub max_items: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none", rename = "maxLength")]
Expand All @@ -653,7 +657,7 @@ pub struct ClusterClassStatusVariablesDefinitionsSchemaOpenApiv3Schema {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub pattern: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub properties: Option<BTreeMap<String, serde_json::Value>>,
pub properties: Option<serde_json::Value>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub required: Option<Vec<String>>,
#[serde(rename = "type")]
Expand Down
12 changes: 8 additions & 4 deletions src/api/fleet_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
// kopium command: kopium -D Default --no-condition -f -
// kopium version: 0.18.0

use kube::CustomResource;
use serde::{Serialize, Deserialize};
use std::collections::BTreeMap;
use k8s_openapi::apimachinery::pkg::util::intstr::IntOrString;
#[allow(unused_imports)]
mod prelude {
pub use kube::CustomResource;
pub use serde::{Serialize, Deserialize};
pub use std::collections::BTreeMap;
pub use k8s_openapi::apimachinery::pkg::util::intstr::IntOrString;
}
use self::prelude::*;

#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, Default)]
#[kube(group = "fleet.cattle.io", version = "v1alpha1", kind = "Cluster", plural = "clusters")]
Expand Down
10 changes: 7 additions & 3 deletions src/api/fleet_clustergroup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
// kopium command: kopium -D Default --no-condition -f -
// kopium version: 0.18.0

use kube::CustomResource;
use serde::{Serialize, Deserialize};
use std::collections::BTreeMap;
#[allow(unused_imports)]
mod prelude {
pub use kube::CustomResource;
pub use serde::{Serialize, Deserialize};
pub use std::collections::BTreeMap;
}
use self::prelude::*;

#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, Default)]
#[kube(group = "fleet.cattle.io", version = "v1alpha1", kind = "ClusterGroup", plural = "clustergroups")]
Expand Down

0 comments on commit 8422679

Please sign in to comment.