Skip to content

Commit f6b4aef

Browse files
committed
don't fetch cluster domain from kubelet if the user has set it already
1 parent dd4b5d1 commit f6b4aef

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

crates/stackable-operator/CHANGELOG.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- The default Kubernetes cluster domain name is now fetched from the kubelet API unless explicitely configured ([#1068]).
10+
711
### Changed
812

913
- Update `kube` to `1.1.0` ([#1049]).
@@ -23,6 +27,7 @@ All notable changes to this project will be documented in this file.
2327
[#1058]: https://github.com/stackabletech/operator-rs/pull/1058
2428
[#1060]: https://github.com/stackabletech/operator-rs/pull/1060
2529
[#1064]: https://github.com/stackabletech/operator-rs/pull/1064
30+
[#1068]: https://github.com/stackabletech/operator-rs/pull/1068
2631

2732
## [0.93.2] - 2025-05-26
2833

@@ -148,7 +153,7 @@ All notable changes to this project will be documented in this file.
148153
### Added
149154

150155
- Add Deployments to `ClusterResource`s ([#992]).
151-
- Add `DeploymentConditionBuilder` ([#993]).
156+
- Add `DeploymentConditionBuilder` ([#993]).
152157

153158
### Changed
154159

@@ -369,7 +374,7 @@ All notable changes to this project will be documented in this file.
369374
### Fixed
370375

371376
- BREAKING: `KeyValuePairs::insert` (as well as `Labels::`/`Annotations::` via it) now overwrites
372-
the old value if the key already exists. Previously, `iter()` would return *both* values in
377+
the old value if the key already exists. Previously, `iter()` would return _both_ values in
373378
lexicographical order (causing further conversions like `Into<BTreeMap>` to prefer the maximum
374379
value) ([#888]).
375380

@@ -634,7 +639,7 @@ All notable changes to this project will be documented in this file.
634639

635640
### Changed
636641

637-
- Implement `PartialEq` for most *Snafu* Error enums ([#757]).
642+
- Implement `PartialEq` for most _Snafu_ Error enums ([#757]).
638643
- Update Rust to 1.77 ([#759])
639644

640645
### Fixed
@@ -1385,7 +1390,7 @@ This is a rerelease of 0.25.1 which some last-minute incompatible API changes to
13851390
### Changed
13861391

13871392
- Objects are now streamed rather than polled when waiting for them to be deleted ([#452]).
1388-
- serde\_yaml 0.8.26 -> 0.9.9 ([#450])
1393+
- serde_yaml 0.8.26 -> 0.9.9 ([#450])
13891394

13901395
[#450]: https://github.com/stackabletech/operator-rs/pull/450
13911396
[#452]: https://github.com/stackabletech/operator-rs/pull/452

crates/stackable-operator/src/client.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,10 +657,25 @@ pub async fn initialize_operator(
657657
.context(InferKubeConfigSnafu)?;
658658
let default_namespace = kubeconfig.default_namespace.clone();
659659
let client = kube::Client::try_from(kubeconfig).context(CreateKubeClientSnafu)?;
660-
let kubelet_config = kubelet::KubeletConfig::fetch(&client)
661-
.await
662-
.context(KubeletConfigSnafu)?;
663-
let cluster_info = KubernetesClusterInfo::new(&kubelet_config, cluster_info_opts);
660+
661+
let local_cluster_info_opts = match cluster_info_opts.kubernetes_cluster_domain {
662+
None => {
663+
trace!("Cluster domain not set, fetching kubelet config to determine cluster domain.");
664+
665+
let kubelet_config = kubelet::KubeletConfig::fetch(&client)
666+
.await
667+
.context(KubeletConfigSnafu)?;
668+
669+
KubernetesClusterInfoOpts {
670+
kubernetes_cluster_domain: Some(kubelet_config.cluster_domain),
671+
}
672+
}
673+
_ => KubernetesClusterInfoOpts {
674+
kubernetes_cluster_domain: cluster_info_opts.kubernetes_cluster_domain.clone(),
675+
},
676+
};
677+
678+
let cluster_info = KubernetesClusterInfo::new(&local_cluster_info_opts);
664679

665680
Ok(Client::new(
666681
client,

crates/stackable-operator/src/utils/cluster_info.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
use super::kubelet::KubeletConfig;
1+
use std::str::FromStr;
2+
23
use crate::commons::networking::DomainName;
34

5+
const KUBERNETES_CLUSTER_DOMAIN_DEFAULT: &str = "cluster.local";
6+
47
/// Some information that we know about the Kubernetes cluster.
58
#[derive(Debug, Clone)]
69
pub struct KubernetesClusterInfo {
@@ -18,19 +21,20 @@ pub struct KubernetesClusterInfoOpts {
1821
}
1922

2023
impl KubernetesClusterInfo {
21-
pub fn new(
22-
kubelet_config: &KubeletConfig,
23-
cluster_info_opts: &KubernetesClusterInfoOpts,
24-
) -> Self {
24+
pub fn new(cluster_info_opts: &KubernetesClusterInfoOpts) -> Self {
2525
let cluster_domain = match &cluster_info_opts.kubernetes_cluster_domain {
2626
Some(cluster_domain) => {
2727
tracing::info!(%cluster_domain, "Using configured Kubernetes cluster domain");
2828

2929
cluster_domain.clone()
3030
}
3131
None => {
32-
let cluster_domain = kubelet_config.cluster_domain.clone();
33-
tracing::info!(%cluster_domain, "Using kubelet config cluster domain");
32+
// TODO(sbernauer): Do some sort of advanced auto-detection, see https://github.com/stackabletech/issues/issues/436.
33+
// There have been attempts of parsing the `/etc/resolv.conf`, but they have been
34+
// reverted. Please read on the linked issue for details.
35+
let cluster_domain = DomainName::from_str(KUBERNETES_CLUSTER_DOMAIN_DEFAULT)
36+
.expect("KUBERNETES_CLUSTER_DOMAIN_DEFAULT constant must a valid domain");
37+
tracing::info!(%cluster_domain, "Defaulting Kubernetes cluster domain as it has not been configured");
3438

3539
cluster_domain
3640
}

crates/stackable-operator/src/utils/kubelet.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ pub struct KubeletConfig {
4343
}
4444

4545
impl KubeletConfig {
46-
4746
/// Fetches the kubelet configuration from the "first" node in the Kubernetes cluster.
4847
pub async fn fetch(client: &Client) -> Result<Self, Error> {
4948
let api: Api<Node> = Api::all(client.clone());

0 commit comments

Comments
 (0)