Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
35 changes: 17 additions & 18 deletions rust/stackable-cockpit/src/platform/operator/listener_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ use stackable_operator::{
use tokio::sync::OnceCell;
use tracing::{debug, info, instrument};

pub static LISTENER_OPERATOR_PRESET: OnceCell<ListenerOperatorPreset> = OnceCell::const_new();
pub static LISTENER_CLASS_PRESET: OnceCell<ListenerClassPreset> = OnceCell::const_new();

/// Represents the `preset` value in the Listener Operator Helm Chart
#[derive(Copy, Clone, Debug, ValueEnum)]
Comment thread
sbernauer marked this conversation as resolved.
pub enum ListenerOperatorPreset {
pub enum ListenerClassPreset {
None,
StableNodes,
EphemeralNodes,
}

impl ListenerOperatorPreset {
impl ListenerClassPreset {
pub fn as_helm_values(&self) -> String {
let preset_value = match self {
Self::None => "none",
Expand All @@ -28,40 +29,38 @@ impl ListenerOperatorPreset {
}

#[instrument]
pub async fn determine_and_store_listener_operator_preset(
from_cli: Option<&ListenerOperatorPreset>,
) {
pub async fn determine_and_store_listener_class_preset(from_cli: Option<&ListenerClassPreset>) {
if let Some(from_cli) = from_cli {
LISTENER_OPERATOR_PRESET
LISTENER_CLASS_PRESET
.set(*from_cli)
.expect("We are the only function setting LISTENER_OPERATOR_PRESET");
.expect("LISTENER_CLASS_PRESET should be unset");
return;
}

let kubernetes_environment = guess_kubernetes_environment().await.unwrap_or_else(|err| {
info!("failed to determine Kubernetes environment, using defaults: {err:#?}");
KubernetesEnvironment::Unknown
});
let listener_operator_preset = match kubernetes_environment {
let listener_class_preset = match kubernetes_environment {
// Kind does not support LoadBalancers out of the box, so avoid that
KubernetesEnvironment::Kind => ListenerOperatorPreset::StableNodes,
KubernetesEnvironment::Kind => ListenerClassPreset::StableNodes,
// LoadBalancer support in k3s is optional, so let's be better safe than sorry and not use
// them
KubernetesEnvironment::K3s => ListenerOperatorPreset::StableNodes,
KubernetesEnvironment::K3s => ListenerClassPreset::StableNodes,
// Weekly node rotations and LoadBalancer support
KubernetesEnvironment::Ionos => ListenerOperatorPreset::EphemeralNodes,
KubernetesEnvironment::Ionos => ListenerClassPreset::EphemeralNodes,
// Don't pin nodes and assume we have LoadBalancer support
KubernetesEnvironment::Unknown => ListenerOperatorPreset::EphemeralNodes,
KubernetesEnvironment::Unknown => ListenerClassPreset::EphemeralNodes,
};
debug!(
preset = ?listener_operator_preset,
preset = ?listener_class_preset,
kubernetes.environment = ?kubernetes_environment,
"Using listener-operator preset"
"Using ListenerClass preset"
);

LISTENER_OPERATOR_PRESET
.set(listener_operator_preset)
.expect("We are the only function setting LISTENER_OPERATOR_PRESET");
LISTENER_CLASS_PRESET
.set(listener_class_preset)
.expect("LISTENER_CLASS_PRESET should be unset");
}

#[derive(Debug)]
Expand Down
4 changes: 2 additions & 2 deletions rust/stackable-cockpit/src/platform/operator/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{fmt::Display, str::FromStr};

use listener_operator::LISTENER_OPERATOR_PRESET;
use listener_operator::LISTENER_CLASS_PRESET;
use semver::Version;
use serde::Serialize;
use snafu::{ResultExt, Snafu, ensure};
Expand Down Expand Up @@ -213,7 +213,7 @@ impl OperatorSpec {
let mut helm_values = None;
if self.name == "listener" {
helm_values = Some(
LISTENER_OPERATOR_PRESET.get()
LISTENER_CLASS_PRESET.get()
.expect("At this point LISTENER_OPERATOR_PRESET must be set by determine_and_store_listener_operator_preset")
Comment thread
sbernauer marked this conversation as resolved.
Outdated
.as_helm_values()
);
Expand Down
4 changes: 2 additions & 2 deletions rust/stackablectl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ All notable changes to this project will be documented in this file.
### Added

- Automatically detect Kubernetes environment (e.g. kind, k3s or IONOS) and choose a sensible [listener-operator preset] by default ([#414]).
Comment thread
sbernauer marked this conversation as resolved.
Outdated
- Support configuring the [listener-operator preset] using `--listener-class-presets` ([#414]).
- Support configuring the [ListenerClass preset] using `--listener-class-preset` ([#414]).

[#414]: https://github.com/stackabletech/stackable-cockpit/pull/414
[listener-operator preset]: https://docs.stackable.tech/home/nightly/listener-operator/listenerclass/#presets
[ListenerClass preset]: https://docs.stackable.tech/home/nightly/listener-operator/listenerclass/#presets

## [1.1.0] - 2025-07-16

Expand Down
11 changes: 4 additions & 7 deletions rust/stackablectl/src/args/operator_configs.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use clap::Args;
use stackable_cockpit::platform::operator::listener_operator::ListenerOperatorPreset;
use stackable_cockpit::platform::operator::listener_operator::ListenerClassPreset;

#[derive(Debug, Args)]
#[command(next_help_heading = "Operator specific configurations")]
pub struct CommonOperatorConfigsArgs {
/// Choose the ListenerClass presets (`none`, `ephemeral-nodes` or `stable-nodes`).
/// Choose the ListenerClass preset (`none`, `ephemeral-nodes` or `stable-nodes`).
///
/// This maps to the listener-operator preset, see
/// This maps to the listener-operator Helm Chart preset value, see
/// [the listener-operator documentation](https://docs.stackable.tech/home/nightly/listener-operator/listenerclass/#presets)
/// for details.
///
/// This argument is likely temporary until we support setting arbitrary helm values for the
/// operators!
#[arg(long, global = true)]
pub listener_class_presets: Option<ListenerOperatorPreset>,
pub listener_class_preset: Option<ListenerClassPreset>,
}
6 changes: 3 additions & 3 deletions rust/stackablectl/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use stackable_cockpit::{
constants::{HELM_REPO_NAME_DEV, HELM_REPO_NAME_STABLE, HELM_REPO_NAME_TEST},
helm,
platform::operator::{
ChartSourceType, listener_operator::determine_and_store_listener_operator_preset,
ChartSourceType, listener_operator::determine_and_store_listener_class_preset,
},
utils::path::{
IntoPathOrUrl, IntoPathsOrUrls, ParsePathsOrUrls, PathOrUrl, PathOrUrlParseError,
Expand Down Expand Up @@ -191,8 +191,8 @@ impl Cli {
// TODO (Techassi): Do we still want to auto purge when running cache commands?
cache.auto_purge().await.unwrap();

determine_and_store_listener_operator_preset(
self.operator_configs.listener_class_presets.as_ref(),
determine_and_store_listener_class_preset(
self.operator_configs.listener_class_preset.as_ref(),
)
.await;

Expand Down
Loading