Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement dynamic watcher for Clusters and Namespaces #194

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
470 changes: 229 additions & 241 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ actix-web = "4.9.0"
futures = "0.3.28"
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
k8s-openapi = { version = "0.24", features = ["latest", "schemars"] }
kube = { version = "0.98", features = [
kube = { version = "0.98.0", features = [
"runtime",
"client",
"derive",
Expand All @@ -60,7 +60,10 @@ anyhow = "1.0.96"
base64 = "0.22.1"
clap = { version = "4.5.31", features = ["derive"] }
cluster-api-rs = "1.9.5"
fleet-api-rs = "0.11.4"
fleet-api-rs = "0.11.5"
async-broadcast = "0.7.2"
pin-project = "1.1.10"
async-stream = "0.3.6"

[dev-dependencies]
assert-json-diff = "2.0.2"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ Refer to the book [configuration](./docs/book/03_tutorials/02_configuration) sec

## Demo

<script src="https://asciinema.org/a/659626.js" id="asciicast-659626" async="true"></script>
[![asciicast](https://asciinema.org/a/659626.svg)](https://asciinema.org/a/659626)

## Calico CNI installation demo

<script src="https://asciinema.org/a/700924.js" id="asciicast-700924" async="true"></script>
[![asciicast](https://asciinema.org/a/700924.svg)](https://asciinema.org/a/700924)

## Get in contact

Expand Down
4 changes: 2 additions & 2 deletions docs/src/02_getting_started/02_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
server:
inferLocal: true # Uses default `kuberenetes` endpoint and secret for APIServerURL configuration
install:
version: v0.12.0-alpha.14 # We will install alpha for helmapp support
version: v0.12.0-beta.1 # We will install alpha for helmapp support
```

### Fleet Public URL and Certificate setup
Expand All @@ -52,7 +52,7 @@ spec:
server:
inferLocal: true # Uses default `kuberenetes` endpoint and secret for APIServerURL configuration
install:
version: v0.12.0-alpha.14 # We will install alpha for helmapp support
version: v0.12.0-beta.1 # We will install alpha for helmapp support
```

This scenario works well in a test setup, while using CAPI docker provider and docker clusters.
Expand Down
4 changes: 2 additions & 2 deletions docs/src/03_tutorials/01_prerequisites.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ kubectl config view -o json --raw | jq -r '.clusters[] | select(.name=="kind-dev
# Set the API server URL
API_SERVER_URL=`kubectl config view -o json --raw | jq -r '.clusters[] | select(.name=="kind-dev").cluster["server"]'`
# And proceed with the installation via helm
helm -n cattle-fleet-system install --version v0.12.0-alpha.14 --create-namespace --wait fleet-crd fleet/fleet-crd
helm install --create-namespace --version v0.12.0-alpha.14 -n cattle-fleet-system --set apiServerURL=$API_SERVER_URL --set-file apiServerCA=_out/ca.pem fleet fleet/fleet --wait
helm -n cattle-fleet-system install --version v0.12.0-beta.1 --create-namespace --wait fleet-crd fleet/fleet-crd
helm install --create-namespace --version v0.12.0-beta.1 -n cattle-fleet-system --set apiServerURL=$API_SERVER_URL --set-file apiServerCA=_out/ca.pem fleet fleet/fleet --wait
```
4. Install CAPI with the required experimental features enabled and initialized the Docker provider for testing.
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/03_tutorials/03_installing_calico.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="warning">

Note: For this setup to work, you need to install Fleet and Fleet CRDs charts via
`FleetAddonConfig` resource. Both need to have version >= v0.12.0-alpha.14,
`FleetAddonConfig` resource. Both need to have version >= v0.12.0-beta.1,
which provides support for `HelmApp` resource.

</div>
Expand Down
2 changes: 0 additions & 2 deletions docs/src/04_reference/01_import-strategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ Fleet mainly relies on `Cluster` labels, `Cluster` names and `ClusterGroups` whe

`FleetAddonConfig` provides several configuration options to define clusters to import.

**Note: Please be aware that chaning selection configuration requires restart of the `CAAPF` instance, as these selection options directly translate into watch configurations for controllers established on the `API` server.**

### Namespace Label Selection

This section defines how to select namespaces based on specific labels. The `namespaceSelector` field ensures that the import strategy applies only to namespaces that have the label `import: "true"`. This is useful for scoping automatic import to specific namespaces rather than applying it cluster-wide.
Expand Down
11 changes: 5 additions & 6 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ compile features="": _create-out-dir

[private]
_build features="":
just compile {{features}}
docker buildx build -t {{ORG}}/{{NAME}}:{{TAG}} .

# docker build base
Expand All @@ -77,6 +76,10 @@ docker-build:
docker-push:
docker push {{ORG}}/{{NAME}}:{{TAG}}

build-and-load:
docker build . -t {{ORG}}/{{NAME}}:{{TAG}}
kind load docker-image {{ORG}}/{{NAME}}:{{TAG}} --name dev

load-base features="":
just _build {{features}}
kind load docker-image {{ORG}}/{{NAME}}:{{TAG}} --name dev
Expand Down Expand Up @@ -131,11 +134,7 @@ deploy-child-cluster-class:

# Add and update helm repos used
update-helm-repos:
#helm repo add gitea-charts https://dl.gitea.com/charts/
helm repo add fleet https://rancher.github.io/fleet-helm-charts/
#helm repo add jetstack https://charts.jetstack.io
#helm repo add traefik https://traefik.github.io/charts
#helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update

# Install fleet into the k8s cluster
Expand All @@ -152,7 +151,7 @@ install-capi: _download-clusterctl
# Deploy will deploy the operator
deploy features="": _download-kustomize
just generate {{features}}
just load-base {{features}}
just build-and-load
kustomize build config/default | kubectl apply -f -
kubectl --context kind-dev apply -f testdata/config.yaml
kubectl wait fleetaddonconfigs fleet-addon-config --for=jsonpath='{.status.installedVersion}' --timeout=150s
Expand Down
5 changes: 4 additions & 1 deletion src/api/capi_cluster.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use cluster_api_rs::capi_cluster::{ClusterSpec, ClusterStatus};
use kube::{api::{ObjectMeta, TypeMeta}, Resource};
use kube::{
api::{ObjectMeta, TypeMeta},
Resource,
};
use serde::{Deserialize, Serialize};

#[derive(Resource, Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
Expand Down
5 changes: 4 additions & 1 deletion src/api/capi_clusterclass.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use cluster_api_rs::capi_clusterclass::{ClusterClassSpec, ClusterClassStatus};
use kube::{api::{ObjectMeta, TypeMeta}, Resource};
use kube::{
api::{ObjectMeta, TypeMeta},
Resource,
};
use serde::{Deserialize, Serialize};

#[derive(Resource, Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
Expand Down
2 changes: 0 additions & 2 deletions src/api/fleet_addon_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,9 @@ impl NamingStrategy {
#[serde(rename_all = "camelCase")]
pub struct Selectors {
/// Namespace label selector. If set, only clusters in the namespace matching label selector will be imported.
/// WARN: this field controls the state of opened watches to the cluster. If changed, requires controller to be reloaded.
pub namespace_selector: LabelSelector,

/// Cluster label selector. If set, only clusters matching label selector will be imported.
/// WARN: this field controls the state of opened watches to the cluster. If changed, requires controller to be reloaded.
pub selector: LabelSelector,
}

Expand Down
7 changes: 5 additions & 2 deletions src/api/fleet_cluster.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use serde::{Deserialize, Serialize};
use fleet_api_rs::fleet_cluster::{ClusterSpec, ClusterStatus};
use kube::{api::{ObjectMeta, TypeMeta}, Resource};
use kube::{
api::{ObjectMeta, TypeMeta},
Resource,
};
use serde::{Deserialize, Serialize};

#[derive(Resource, Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[resource(inherit = fleet_api_rs::fleet_cluster::Cluster)]
Expand Down
7 changes: 5 additions & 2 deletions src/api/fleet_cluster_registration_token.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use serde::{Deserialize, Serialize};
use fleet_api_rs::fleet_cluster_registration_token::{
ClusterRegistrationTokenSpec, ClusterRegistrationTokenStatus,
};
use kube::{api::{ObjectMeta, TypeMeta}, Resource};
use kube::{
api::{ObjectMeta, TypeMeta},
Resource,
};
use serde::{Deserialize, Serialize};

#[derive(Resource, Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[resource(inherit = fleet_api_rs::fleet_cluster_registration_token::ClusterRegistrationToken)]
Expand Down
7 changes: 5 additions & 2 deletions src/api/fleet_clustergroup.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use serde::{Deserialize, Serialize};
use fleet_api_rs::fleet_clustergroup::{ClusterGroupSpec, ClusterGroupStatus};
use kube::{api::{ObjectMeta, TypeMeta}, Resource};
use kube::{
api::{ObjectMeta, TypeMeta},
Resource,
};
use serde::{Deserialize, Serialize};

#[derive(Resource, Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[resource(inherit = fleet_api_rs::fleet_clustergroup::ClusterGroup)]
Expand Down
Loading
Loading