Skip to content

Commit

Permalink
Merge pull request #22 from Danil-Grigorev/apiextensions-json-fix
Browse files Browse the repository at this point in the history
Allow empty CAPI variable value to be deserialized without errors
  • Loading branch information
richardcase authored Apr 25, 2024
2 parents 3e04c2f + 46d47eb commit f351d5b
Show file tree
Hide file tree
Showing 7 changed files with 444 additions and 39 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ jobs:
- uses: actions/checkout@v4
- name: Test
run: just test-unit
test-e2e:
runs-on: ubuntu-latest
steps:
- name: Install just
uses: extractions/setup-just@v2
- name: Install kind
uses: helm/kind-action@v1
with:
install_only: true
- uses: actions/checkout@v4
- name: Test
run: just test-cluster-class-import
42 changes: 34 additions & 8 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ ORG := "ghcr.io/rancher-sandbox"
TAG := "dev"
HOME_DIR := env_var('HOME')
YQ_VERSION := "v4.43.1"
CLUSTERCTL_VERSION := "v1.7.1"
YQ_BIN := "_out/yq"
OUT_DIR := "_out"
KOPIUM_BIN := "_out/bin/kopium"
KUSTOMIZE_VERSION := "v5.4.1"
KUSTOMIZE_BIN := "_out/kustomize"
CLUSTERCTL_BIN := "_out/clusterctl"
ARCH := if arch() == "aarch64" { "arm64"} else { "amd64" }
DIST := os()

Expand All @@ -21,10 +25,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 @@ -95,10 +99,14 @@ stop-dev:
deploy-crs:
kubectl --context kind-dev apply -f testdata/crs.yaml

# Deploy child cluster using docker & kubead,
# Deploy child cluster using docker & kubeadm
deploy-child-cluster:
kubectl --context kind-dev apply -f testdata/cluster_docker_kcp.yaml

# Deploy child cluster-call based cluster using docker & kubeadm
deploy-child-cluster-class:
kubectl --context kind-dev apply -f testdata/capi-quickstart.yaml

# Add and update helm repos used
update-helm-repos:
#helm repo add gitea-charts https://dl.gitea.com/charts/
Expand All @@ -118,8 +126,8 @@ install-fleet: _create-out-dir
helm install --create-namespace -n cattle-fleet-system --set apiServerURL=$API_SERVER_URL --set-file apiServerCA=_out/ca.pem fleet fleet/fleet --wait
# Install cluster api and any providers
install-capi:
EXP_CLUSTER_RESOURCE_SET=true CLUSTER_TOPOLOGY=true clusterctl init -i docker
install-capi: _download-clusterctl
EXP_CLUSTER_RESOURCE_SET=true CLUSTER_TOPOLOGY=true {{CLUSTERCTL_BIN}} init -i docker

# Deploy will deploy the operator
deploy: _download-kustomize load-base
Expand All @@ -136,10 +144,16 @@ test-import: start-dev deploy deploy-child-cluster deploy-crs
kubectl wait pods --for=condition=Ready --timeout=300s --all --all-namespaces
kubectl wait clusters.fleet.cattle.io --timeout=300s --for=condition=Imported docker-demo

# Full e2e test of importing cluster in fleet
test-cluster-class-import: start-dev deploy deploy-child-cluster-class deploy-crs
kubectl wait pods --for=condition=Ready --timeout=300s --all --all-namespaces
kubectl wait clustergroups.fleet.cattle.io --timeout=300s --for=jsonpath='{.status.clusterCount}=1' quick-start
kubectl wait clusters.fleet.cattle.io --timeout=300s --for=condition=Imported capi-quickstart

# 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 All @@ -150,6 +164,18 @@ _download-kustomize:
tar -xzf {{KUSTOMIZE_BIN}}.tar.gz -C _out
chmod +x {{KUSTOMIZE_BIN}}

[private]
[linux]
_download-clusterctl:
curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/{{CLUSTERCTL_VERSION}}/clusterctl-linux-amd64 -o {{CLUSTERCTL_BIN}}
chmod +x {{CLUSTERCTL_BIN}}

[private]
[macos]
_download-clusterctl:
curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/{{CLUSTERCTL_VERSION}}/clusterctl-darwin-amd64 -o {{CLUSTERCTL_BIN}}
chmod +x {{CLUSTERCTL_BIN}}

# Download yq
[private]
[linux]
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
Loading

0 comments on commit f351d5b

Please sign in to comment.