-
-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Support configuring ListenerClass preset (with sensible defaults) #414
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
dd593a8
feat: Support configuring listner-operator preset (with sensible defa…
sbernauer 49039e3
Update rustdoc
sbernauer 2d96b64
changelog
sbernauer a8db362
--listener-operator-preset -> --listener-class-presets
sbernauer ca2895b
Update rust/stackable-cockpit/src/platform/operator/listener_operator.rs
sbernauer 263b9cd
Apply suggestions from code review
sbernauer 3e69cd9
Fix compilation
sbernauer be8fade
Make CLI flag --listener-class-preset singular
sbernauer 3281de1
Update CLI docs
sbernauer 3ff1776
change link title in changelog
sbernauer fd044d2
Update rust/stackablectl/src/args/operator_configs.rs
sbernauer 3019ae3
Remove docs on temporary
sbernauer 8d838f0
Update rust/stackable-cockpit/src/platform/operator/mod.rs
sbernauer bfa6b25
Update rust/stackablectl/CHANGELOG.md
sbernauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
rust/stackable-cockpit/src/platform/operator/listener_operator.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| use clap::ValueEnum; | ||
| use snafu::ResultExt; | ||
| use stackable_operator::{ | ||
| k8s_openapi::api::core::v1::Node, | ||
| kube::{Api, Client, api::ListParams}, | ||
| }; | ||
| use tokio::sync::OnceCell; | ||
| use tracing::{debug, info, instrument}; | ||
|
|
||
| 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)] | ||
| pub enum ListenerClassPreset { | ||
| None, | ||
| StableNodes, | ||
| EphemeralNodes, | ||
| } | ||
|
|
||
| impl ListenerClassPreset { | ||
| pub fn as_helm_values(&self) -> String { | ||
| let preset_value = match self { | ||
| Self::None => "none", | ||
| Self::StableNodes => "stable-nodes", | ||
| Self::EphemeralNodes => "ephemeral-nodes", | ||
| }; | ||
| format!("preset: {preset_value}") | ||
| } | ||
| } | ||
|
|
||
| #[instrument] | ||
| pub async fn determine_and_store_listener_class_preset(from_cli: Option<&ListenerClassPreset>) { | ||
| if let Some(from_cli) = from_cli { | ||
| LISTENER_CLASS_PRESET | ||
| .set(*from_cli) | ||
| .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_class_preset = match kubernetes_environment { | ||
| // Kind does not support LoadBalancers out of the box, so avoid that | ||
| KubernetesEnvironment::Kind => ListenerClassPreset::StableNodes, | ||
| // LoadBalancer support in k3s is optional, so let's be better safe than sorry and not use | ||
| // them | ||
| KubernetesEnvironment::K3s => ListenerClassPreset::StableNodes, | ||
| // Weekly node rotations and LoadBalancer support | ||
| KubernetesEnvironment::Ionos => ListenerClassPreset::EphemeralNodes, | ||
| // Don't pin nodes and assume we have LoadBalancer support | ||
| KubernetesEnvironment::Unknown => ListenerClassPreset::EphemeralNodes, | ||
| }; | ||
| debug!( | ||
| preset = ?listener_class_preset, | ||
| kubernetes.environment = ?kubernetes_environment, | ||
| "Using ListenerClass preset" | ||
| ); | ||
|
|
||
| LISTENER_CLASS_PRESET | ||
| .set(listener_class_preset) | ||
| .expect("LISTENER_CLASS_PRESET should be unset"); | ||
| } | ||
|
|
||
| #[derive(Debug)] | ||
| enum KubernetesEnvironment { | ||
| Kind, | ||
| K3s, | ||
| Ionos, | ||
| Unknown, | ||
| } | ||
|
|
||
| /// Tries to guess what Kubernetes environment stackablectl is connecting to. | ||
| /// | ||
| /// Returns an error in case anything goes wrong. This could e.g. be the case in case no | ||
| /// Kubernetes context is configured, stackablectl is missing RBAC permission to retrieve nodes or | ||
| /// simply a network error. | ||
| #[instrument] | ||
| async fn guess_kubernetes_environment() -> Result<KubernetesEnvironment, snafu::Whatever> { | ||
| let client = Client::try_default() | ||
| .await | ||
| .whatever_context("failed to construct Kubernetes client")?; | ||
| let node_api: Api<Node> = Api::all(client); | ||
| let nodes = node_api | ||
| .list(&ListParams::default()) | ||
| .await | ||
| .whatever_context("failed to list Kubernetes nodes")?; | ||
|
|
||
| for node in nodes { | ||
| if let Some(spec) = node.spec { | ||
| if let Some(provider_id) = spec.provider_id { | ||
| if provider_id.starts_with("kind://") { | ||
| return Ok(KubernetesEnvironment::Kind); | ||
| } else if provider_id.starts_with("k3s://") { | ||
| return Ok(KubernetesEnvironment::K3s); | ||
| } else if provider_id.starts_with("ionos://") { | ||
| return Ok(KubernetesEnvironment::Ionos); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Ok(KubernetesEnvironment::Unknown) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| mod cluster; | ||
| mod file; | ||
| mod namespace; | ||
| mod operator_configs; | ||
| mod repo; | ||
|
|
||
| pub use cluster::*; | ||
| pub use file::*; | ||
| pub use namespace::*; | ||
| pub use operator_configs::*; | ||
| pub use repo::*; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| use clap::Args; | ||
| use stackable_cockpit::platform::operator::listener_operator::ListenerClassPreset; | ||
|
|
||
| #[derive(Debug, Args)] | ||
| #[command(next_help_heading = "Operator specific configurations")] | ||
| pub struct CommonOperatorConfigsArgs { | ||
| /// Choose the ListenerClass preset (`none`, `ephemeral-nodes` or `stable-nodes`). | ||
| /// | ||
| /// 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. | ||
| #[arg(long, global = true)] | ||
| pub listener_class_preset: Option<ListenerClassPreset>, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.