Skip to content
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ anyhow = "1.0.96"
base64 = "0.22.1"
clap = { version = "4.5.32", features = ["derive"] }
cluster-api-rs = "1.9.6"
fleet-api-rs = "0.12.0-rc.1"
fleet-api-rs = "0.12.0"
async-broadcast = "0.7.2"
pin-project = "1.1.10"
async-stream = "0.3.6"
Expand Down
8 changes: 7 additions & 1 deletion config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,10 @@ rules:
- list
- patch
- update
- watch
- watch
- apiGroups:
- fleet.cattle.io
resources:
- bundlenamespacemappings
verbs:
- delete
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-rc.1 # We will install alpha for helmapp support
followLatest: true
```

### 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-rc.1 # We will install alpha for helmapp support
followLatest: true
```

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-rc.1 --create-namespace --wait fleet-crd fleet/fleet-crd
helm install --create-namespace --version v0.12.0-rc.1 -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 --create-namespace --wait fleet-crd fleet/fleet-crd
helm install --create-namespace --version v0.12.0 -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-rc.1,
`FleetAddonConfig` resource. Both need to have version >= v0.12.0,
which provides support for `HelmApp` resource.

</div>
Expand Down
10 changes: 2 additions & 8 deletions docs/src/03_tutorials/04_installing_calico_via_gitrepo.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 have Fleet and Fleet CRDs charts installed
with version >= `v0.12.0-rc.1`.
with version >= `v0.12.0`.

</div>

Expand Down Expand Up @@ -54,13 +54,7 @@ We also need to [resolve conflicts][], which happen due to in-place modification
[previous]: ./03_installing_calico.md
[resolve conflicts]: https://fleet.rancher.io/bundle-diffs

Then we are specifying `targets.yaml` file, which will declare selection rules for this `fleet.yaml` configuration. In our case, we will match on clusters labeled with `cni: calico` label:

```yaml
{{#include ../../../fleet/applications/calico/targets.yaml}}
```

Once everything is ready, we need to apply our `GitRepo` in the `default` namespace:
Once everything is ready, we need to apply our `GitRepo` in the `default` namespace. In our case, we will match on clusters labeled with `cni: calico` label:

```yaml
{{#include ../../../testdata/gitrepo-calico.yaml}}
Expand Down
1 change: 1 addition & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ _test-import-all:
[private]
_test-delete-all:
# Verify that deleting everything causes full re-import
kubectl delete clustergroups.fleet.cattle.io quick-start.clusterclass --wait
kubectl delete clustergroups.fleet.cattle.io -n clusterclass quick-start --wait
kubectl delete bundlenamespacemappings.fleet.cattle.io -n clusterclass default --wait
kubectl delete clusters.fleet.cattle.io capi-quickstart --wait
Expand Down
86 changes: 3 additions & 83 deletions src/api/bundle_namespace_mapping.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::collections::BTreeMap;

use fleet_api_rs::fleet_bundle_namespace_mapping::{
BundleNamespaceMappingBundleSelector, BundleNamespaceMappingNamespaceSelector,
};
use kube::{
api::{ObjectMeta, TypeMeta},
Resource,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

mod mapping {
Expand Down Expand Up @@ -32,83 +32,3 @@ pub struct BundleNamespaceMapping {
pub bundle_selector: BundleNamespaceMappingBundleSelector,
pub namespace_selector: BundleNamespaceMappingNamespaceSelector,
}

/// A label selector is a label query over a set of resources. The result of matchLabels and
/// matchExpressions are ANDed. An empty label selector matches all objects. A null
/// label selector matches no objects.
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, JsonSchema)]
pub struct BundleNamespaceMappingBundleSelector {
/// matchExpressions is a list of label selector requirements. The requirements are ANDed.
#[serde(
default,
skip_serializing_if = "Option::is_none",
rename = "matchExpressions"
)]
pub match_expressions: Option<Vec<BundleNamespaceMappingBundleSelectorMatchExpressions>>,
/// matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
/// map is equivalent to an element of matchExpressions, whose key field is "key", the
/// operator is "In", and the values array contains only "value". The requirements are ANDed.
#[serde(
default,
skip_serializing_if = "Option::is_none",
rename = "matchLabels"
)]
pub match_labels: Option<BTreeMap<String, String>>,
}

/// A label selector requirement is a selector that contains values, a key, and an operator that
/// relates the key and values.
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, JsonSchema)]
pub struct BundleNamespaceMappingBundleSelectorMatchExpressions {
/// key is the label key that the selector applies to.
pub key: String,
/// operator represents a key's relationship to a set of values.
/// Valid operators are In, NotIn, Exists and DoesNotExist.
pub operator: String,
/// values is an array of string values. If the operator is In or NotIn,
/// the values array must be non-empty. If the operator is Exists or DoesNotExist,
/// the values array must be empty. This array is replaced during a strategic
/// merge patch.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub values: Option<Vec<String>>,
}

/// A label selector is a label query over a set of resources. The result of matchLabels and
/// matchExpressions are ANDed. An empty label selector matches all objects. A null
/// label selector matches no objects.
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, JsonSchema)]
pub struct BundleNamespaceMappingNamespaceSelector {
/// matchExpressions is a list of label selector requirements. The requirements are ANDed.
#[serde(
default,
skip_serializing_if = "Option::is_none",
rename = "matchExpressions"
)]
pub match_expressions: Option<Vec<BundleNamespaceMappingNamespaceSelectorMatchExpressions>>,
/// matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
/// map is equivalent to an element of matchExpressions, whose key field is "key", the
/// operator is "In", and the values array contains only "value". The requirements are ANDed.
#[serde(
default,
skip_serializing_if = "Option::is_none",
rename = "matchLabels"
)]
pub match_labels: Option<BTreeMap<String, String>>,
}

/// A label selector requirement is a selector that contains values, a key, and an operator that
/// relates the key and values.
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, JsonSchema)]
pub struct BundleNamespaceMappingNamespaceSelectorMatchExpressions {
/// key is the label key that the selector applies to.
pub key: String,
/// operator represents a key's relationship to a set of values.
/// Valid operators are In, NotIn, Exists and DoesNotExist.
pub operator: String,
/// values is an array of string values. If the operator is In or NotIn,
/// the values array must be non-empty. If the operator is Exists or DoesNotExist,
/// the values array must be empty. This array is replaced during a strategic
/// merge patch.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub values: Option<Vec<String>>,
}
4 changes: 2 additions & 2 deletions src/api/capi_cluster.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::BTreeMap;

use cluster_api_rs::capi_cluster::{ClusterSpec, ClusterStatus};
use fleet_api_rs::fleet_clustergroup::{ClusterGroupSelector, ClusterGroupSpec};
use fleet_api_rs::{fleet_bundle_namespace_mapping::BundleNamespaceMappingNamespaceSelector, fleet_clustergroup::{ClusterGroupSelector, ClusterGroupSpec}};
use kube::{
api::{ObjectMeta, TypeMeta},
Resource, ResourceExt as _,
Expand All @@ -11,7 +11,7 @@ use rand::distr::{Alphanumeric, SampleString as _};
use serde::{Deserialize, Serialize};

use super::{
bundle_namespace_mapping::{BundleNamespaceMapping, BundleNamespaceMappingNamespaceSelector},
bundle_namespace_mapping::BundleNamespaceMapping,
fleet_addon_config::ClusterConfig,
fleet_cluster,
fleet_clustergroup::{ClusterGroup, CLUSTER_CLASS_LABEL, CLUSTER_CLASS_NAMESPACE_LABEL},
Expand Down
20 changes: 14 additions & 6 deletions src/controllers/addon_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,20 @@ impl FleetAddonConfig {
};
let message = format!("Updated chart flags to the expected state: {options}");
if let Some(ref mut status) = self.status {
if !status
.conditions
.iter()
.any(|c| c.type_ == "FlagsUpdate" && message == c.message)
{
options.patch_fleet()?.wait().await?;
if !status.conditions.iter().any(|c| {
c.type_ == "FlagsUpdate"
&& message == c.message
&& c.observed_generation == self.metadata.generation
}) {
let installed_meta = match FleetChart::get_metadata("fleet").await? {
Some(meta) => meta,
None => return Ok(None),
};

options
.patch_fleet(&installed_meta.app_version)?
.wait()
.await?;

status.conditions.push(Condition {
last_transition_time: Time(Local::now().to_utc()),
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/helm/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ impl FleetChart {
}

impl FleetOptions {
pub fn patch_fleet(&self) -> FleetPatchResult<Child> {
pub fn patch_fleet(&self, version: &str) -> FleetPatchResult<Child> {
let mut upgrade = Command::new("helm");

upgrade.args(["upgrade", "fleet", "fleet/fleet", "--reuse-values"]);
upgrade.args(["upgrade", "fleet", "fleet/fleet", "--reuse-values", "--version", version]);

if !self.namespace.is_empty() {
upgrade.args(["--namespace", &self.namespace]);
Expand Down
2 changes: 1 addition & 1 deletion testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ spec:
matchLabels:
import: ""
install:
version: v0.12.0-rc.1 # We will install alpha for helmapp support
followLatest: true # We will install alpha for helmapp support