Skip to content
This repository was archived by the owner on Feb 16, 2024. It is now read-only.

Commit 05ad1fd

Browse files
committed
Detect IONOS managed Stackable clusters and skip installing releases
1 parent eb800e9 commit 05ad1fd

File tree

6 files changed

+50
-1
lines changed

6 files changed

+50
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Added
66

77
- Added Listener operator to supported operators ([#143](https://github.com/stackabletech/stackablectl/pull/143))
8+
- Detect IONOS managed Stackable clusters and skip installing releases ([#147](https://github.com/stackabletech/stackablectl/pull/147))
89

910
## [0.5.0] - 2022-09-14
1011

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ kube = "0.74" # Using openssl (and not native-tls) as kube-rs team tries to move
1919
lazy_static = "1.4"
2020
log = "0.4"
2121
openssl = { version = "0.10.36", features = ["vendored"] } # Must match version from kube
22+
regex = "1.6"
2223
which = "4.2"
2324
semver = "1.0"
2425
serde = { version = "1.0", features = ["derive"]}

src/ionos.rs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use std::error::Error;
2+
3+
use k8s_openapi::api::apps::v1::Deployment;
4+
use kube::{api::ListParams, Api, ResourceExt};
5+
use lazy_static::lazy_static;
6+
use regex::Regex;
7+
8+
/// We asked the IONOS guys and agreed an this way of identifying a managed stackable cluster
9+
/// One ideas was to give the Namespace `stackable-operators` as special label
10+
///
11+
/// The current solution lists the deployment in the `stackable-operators` namespace and searches for matching names
12+
/// This is far from the ideal solution and should be improved when there are better points of identifying a managed stackable cluster
13+
pub async fn detect_ionos_managed_stackable_operators() -> Result<Vec<String>, Box<dyn Error>> {
14+
lazy_static! {
15+
static ref OPERATOR_DEPLOYMENT_REGEX: Regex =
16+
Regex::new("dp-[0-9a-f]{20}-([a-z-]+)-operator-deployment").unwrap();
17+
}
18+
19+
let mut operators = Vec::new();
20+
21+
let client = crate::kube::get_client().await?;
22+
let deployments = Api::<Deployment>::namespaced(client, "stackable-operators")
23+
.list(&ListParams::default())
24+
.await?;
25+
for deployment in deployments {
26+
let deployment_name = deployment.name_unchecked();
27+
if let Some(operator_name) = OPERATOR_DEPLOYMENT_REGEX
28+
.captures(&deployment_name)
29+
.and_then(|cap| cap.get(1).map(|m| m.as_str()))
30+
{
31+
operators.push(operator_name.to_string());
32+
}
33+
}
34+
35+
Ok(operators)
36+
}

src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mod arguments;
99
mod demo;
1010
mod helm;
1111
mod helpers;
12+
mod ionos;
1213
mod kind;
1314
mod kube;
1415
mod operator;

src/release.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{arguments::OutputType, helpers, kind, operator, operator::Operator, CliArgs};
1+
use crate::{arguments::OutputType, helpers, ionos, kind, operator, operator::Operator, CliArgs};
22
use cached::proc_macro::cached;
33
use clap::{ArgGroup, Parser, ValueHint};
44
use indexmap::IndexMap;
@@ -201,6 +201,15 @@ pub async fn install_release(
201201
include_products: &[String],
202202
exclude_products: &[String],
203203
) -> Result<(), Box<dyn Error>> {
204+
let managed_stackable_operators = ionos::detect_ionos_managed_stackable_operators().await?;
205+
if !managed_stackable_operators.is_empty() {
206+
warn!("stackablectl detected that you are running on a managed Stackable cluster operated by IONOS. \
207+
As IONOS has installed the Stackable operators already, stackablectl is not going to install them a second time. \
208+
Please make sure that your managed Stackable cluster uses the same Stackable operator versions as the release {release_name}. \
209+
You can list the Stackable operator versions of the {release_name} release using `stackablectl release describe {release_name}`.");
210+
return Ok(());
211+
}
212+
204213
info!("Installing release {release_name}");
205214
let release = get_release(release_name).await;
206215

0 commit comments

Comments
 (0)