Skip to content

Commit

Permalink
Add option for using agent initiated setup
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>
  • Loading branch information
Danil-Grigorev committed May 21, 2024
1 parent 2c429b4 commit aa5858c
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 52 deletions.
1 change: 1 addition & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ rules:
resources:
- clusters
- clustergroups
- clusterregistrationtokens
verbs:
- create
- get
Expand Down
27 changes: 18 additions & 9 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ default:
@just --list --unsorted --color=always

# Generates stuff
generate:
just generate-addon-crds
generate features="":
just generate-addon-crds {{features}}
just generate-crds

# generates files for CRDS
Expand All @@ -29,13 +29,14 @@ generate-crds: _create-out-dir _install-kopium _download-yq
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"
just _generate-kopium-url {{KOPIUM_BIN}} "https://raw.githubusercontent.com/rancher/fleet/main/charts/fleet-crd/templates/crds.yaml" "src/api/fleet_cluster_registration_token.rs" "select(.spec.names.singular==\"clusterregistrationtoken\")" ""

[private]
_generate-kopium-url kpath="" source="" dest="" yqexp="." condition="":
curl -sSL {{source}} | {{YQ_BIN}} '{{yqexp}}' | {{kpath}} -D Default {{condition}} -f - > {{dest}}

generate-addon-crds:
cargo run --bin crdgen > config/crds/fleet-addon-config.yaml
generate-addon-crds features="":
cargo run --features={{features}} --bin crdgen > config/crds/fleet-addon-config.yaml

# run with opentelemetry
run-telemetry:
Expand Down Expand Up @@ -70,15 +71,18 @@ _build features="":
docker build -t {{ORG}}/{{NAME}}:{{TAG}} .

# docker build base
build-base: (_build "")
build-base features="":
just _build {{features}}

# docker build with telemetry
build-otel: (_build "telemetry")

# Push the docker images
docker-push:
docker push {{ORG}}/{{NAME}}:{{TAG}}

load-base: build-base
load-base features="":
just build-base {{features}}
kind load docker-image {{ORG}}/{{NAME}}:{{TAG}} --name dev

# Start local dev environment
Expand Down Expand Up @@ -131,7 +135,9 @@ 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
deploy features="": _download-kustomize
just generate {{features}}
just load-base {{features}}
{{KUSTOMIZE_BIN}} build config/default | kubectl apply -f -

undeploy: _download-kustomize
Expand All @@ -146,7 +152,10 @@ test-import: start-dev deploy deploy-child-cluster deploy-crs
kubectl wait clusters.fleet.cattle.io --timeout=300s --for=condition=Ready docker-demo

# Full e2e test of importing cluster in fleet
test-cluster-class-import: start-dev deploy deploy-child-cluster-class deploy-crs
test-cluster-class-import: start-dev
just deploy "agent-initiated"
just deploy-child-cluster-class
just 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 clustergroups.fleet.cattle.io --timeout=300s --for=condition=Ready quick-start
Expand All @@ -155,7 +164,7 @@ test-cluster-class-import: start-dev deploy deploy-child-cluster-class deploy-cr
# Install kopium
[private]
_install-kopium:
cargo install --git https://github.com/kube-rs/kopium.git --branch main --root {{OUT_DIR}}
cargo install --git https://github.com/kube-rs/kopium.git --tag 0.19.0 --root {{OUT_DIR}}

# Download kustomize
[private]
Expand Down
3 changes: 2 additions & 1 deletion src/api/capi_cluster.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// WARNING: generated by kopium - manual changes will be overwritten
// kopium command: kopium -D Default -f -
// kopium version: 0.18.0
// kopium version: 0.19.0

#[allow(unused_imports)]
mod prelude {
Expand All @@ -17,6 +17,7 @@ use self::prelude::*;
#[kube(namespaced)]
#[kube(status = "ClusterStatus")]
#[kube(schema = "disabled")]
#[kube(derive="Default")]
pub struct ClusterSpec {
#[serde(default, skip_serializing_if = "Option::is_none", rename = "clusterNetwork")]
pub cluster_network: Option<ClusterClusterNetwork>,
Expand Down
3 changes: 2 additions & 1 deletion src/api/capi_clusterclass.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// WARNING: generated by kopium - manual changes will be overwritten
// kopium command: kopium -D Default -f -
// kopium version: 0.18.0
// kopium version: 0.19.0

#[allow(unused_imports)]
mod prelude {
Expand All @@ -17,6 +17,7 @@ use self::prelude::*;
#[kube(namespaced)]
#[kube(status = "ClusterClassStatus")]
#[kube(schema = "disabled")]
#[kube(derive="Default")]
pub struct ClusterClassSpec {
#[serde(default, skip_serializing_if = "Option::is_none", rename = "controlPlane")]
pub control_plane: Option<ClusterClassControlPlane>,
Expand Down
34 changes: 26 additions & 8 deletions src/api/fleet_addon_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,8 @@ impl Default for FleetAddonConfig {
metadata: Default::default(),
spec: FleetAddonConfigSpec {
patch_resource: Some(true),
cluster_class: Some(ClusterClassConfig {
set_owner_references: Some(true),
enabled: Some(true),
}),
cluster: Some(ClusterConfig {
set_owner_references: Some(true),
enabled: Some(true),
}),
cluster_class: Some(ClusterClassConfig::default()),
cluster: Some(ClusterConfig::default()),
},
}
}
Expand All @@ -48,6 +42,15 @@ pub struct ClusterClassConfig {
pub set_owner_references: Option<bool>,
}

impl Default for ClusterClassConfig {
fn default() -> Self {
Self {
set_owner_references: Some(true),
enabled: Some(true),
}
}
}

#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct ClusterConfig {
/// Enable Cluster config funtionality.
Expand All @@ -59,4 +62,19 @@ pub struct ClusterConfig {

/// Setting to disable setting owner references on the created resources
pub set_owner_references: Option<bool>,

#[cfg(feature = "agent-initiated")]
/// Prepare initial cluster for agent initiated connection
pub agent_initiated: Option<bool>,
}

impl Default for ClusterConfig {
fn default() -> Self {
Self {
set_owner_references: Some(true),
enabled: Some(true),
#[cfg(feature = "agent-initiated")]
agent_initiated: Some(true),
}
}
}
3 changes: 2 additions & 1 deletion src/api/fleet_cluster.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// WARNING: generated by kopium - manual changes will be overwritten
// kopium command: kopium -D Default --no-condition -f -
// kopium version: 0.18.0
// kopium version: 0.19.0

#[allow(unused_imports)]
mod prelude {
Expand All @@ -16,6 +16,7 @@ use self::prelude::*;
#[kube(namespaced)]
#[kube(status = "ClusterStatus")]
#[kube(schema = "disabled")]
#[kube(derive="Default")]
pub struct ClusterSpec {
#[serde(default, skip_serializing_if = "Option::is_none", rename = "agentAffinity")]
pub agent_affinity: Option<ClusterAgentAffinity>,
Expand Down
30 changes: 30 additions & 0 deletions src/api/fleet_cluster_registration_token.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// WARNING: generated by kopium - manual changes will be overwritten
// kopium command: kopium -D Default -f -
// kopium version: 0.19.0

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

#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, Default)]
#[kube(group = "fleet.cattle.io", version = "v1alpha1", kind = "ClusterRegistrationToken", plural = "clusterregistrationtokens")]
#[kube(namespaced)]
#[kube(status = "ClusterRegistrationTokenStatus")]
#[kube(schema = "disabled")]
#[kube(derive="Default")]
pub struct ClusterRegistrationTokenSpec {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub ttl: Option<String>,
}

#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct ClusterRegistrationTokenStatus {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub expires: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none", rename = "secretName")]
pub secret_name: Option<String>,
}

3 changes: 2 additions & 1 deletion src/api/fleet_clustergroup.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// WARNING: generated by kopium - manual changes will be overwritten
// kopium command: kopium -D Default --no-condition -f -
// kopium version: 0.18.0
// kopium version: 0.19.0

#[allow(unused_imports)]
mod prelude {
Expand All @@ -15,6 +15,7 @@ use self::prelude::*;
#[kube(namespaced)]
#[kube(status = "ClusterGroupStatus")]
#[kube(schema = "disabled")]
#[kube(derive="Default")]
pub struct ClusterGroupSpec {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub selector: Option<ClusterGroupSelector>,
Expand Down
2 changes: 2 additions & 0 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ pub mod capi_clusterclass;
pub mod fleet_cluster;
pub mod fleet_clustergroup;
pub mod fleet_addon_config;
#[cfg(feature = "agent-initiated")]
pub mod fleet_cluster_registration_token;
Loading

0 comments on commit aa5858c

Please sign in to comment.