Skip to content

Commit d298e57

Browse files
authored
Merge pull request #736 from molnett/mk/allow_custom_cluster_domain
allow for custom cluster domain for agent to api connection
2 parents 7bd7746 + a6d4c4b commit d298e57

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

apiserver/src/client/webclient.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
};
99
use async_trait::async_trait;
1010
use models::{
11-
constants::{APISERVER_SERVICE_NAME, CA_NAME, TLS_KEY_MOUNT_PATH},
11+
constants::{APISERVER_SERVICE_NAME, CA_NAME, KUBERNETES_SERVICE_CLUSTER_DOMAIN, TLS_KEY_MOUNT_PATH},
1212
node::{BottlerocketShadow, BottlerocketShadowSelector, BottlerocketShadowStatus},
1313
};
1414
use snafu::ResultExt;
@@ -65,6 +65,7 @@ pub struct K8SAPIServerClient {
6565
k8s_projected_token_path: String,
6666
service_port: u16,
6767
namespace: String,
68+
cluster_domain_suffix: String,
6869
}
6970

7071
impl K8SAPIServerClient {
@@ -77,10 +78,16 @@ impl K8SAPIServerClient {
7778
.context(error::CreateK8sClientSnafu)?;
7879
event!(Level::INFO, %service_port, "Created K8s API Server client using service port");
7980

81+
// Get cluster domain suffix from env var or use default
82+
let cluster_domain_suffix = env::var("KUBERNETES_SERVICE_CLUSTER_DOMAIN")
83+
.unwrap_or_else(|_| KUBERNETES_SERVICE_CLUSTER_DOMAIN.to_string());
84+
event!(Level::INFO, %cluster_domain_suffix, "Using cluster domain suffix");
85+
8086
Ok(Self {
8187
k8s_projected_token_path,
8288
service_port: service_port as u16,
8389
namespace: namespace.to_string(),
90+
cluster_domain_suffix,
8491
})
8592
}
8693

@@ -99,8 +106,8 @@ impl K8SAPIServerClient {
99106
/// Returns the domain on which the server can be reached.
100107
pub fn server_domain(&self) -> String {
101108
format!(
102-
"{}.{}.svc.cluster.local:{}",
103-
APISERVER_SERVICE_NAME, self.namespace, self.service_port
109+
"{}.{}.{}:{}",
110+
APISERVER_SERVICE_NAME, self.namespace, self.cluster_domain_suffix, self.service_port
104111
)
105112
}
106113

models/src/constants.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub const APISERVER_MAX_UNAVAILABLE: &str = "33%"; // The maximum number of unav
5858
pub const APISERVER_HEALTH_CHECK_ROUTE: &str = "/ping"; // Route used for apiserver k8s liveness and readiness checks.
5959
pub const APISERVER_CRD_CONVERT_ENDPOINT: &str = "/crdconvert"; // Custom Resource convert endpoint
6060
pub const APISERVER_SERVICE_NAME: &str = "brupop-apiserver"; // The name for the `svc` fronting the apiserver.
61+
pub const KUBERNETES_SERVICE_CLUSTER_DOMAIN: &str = "svc.cluster.local"; // The default cluster domain suffix used for internal service communication.
6162

6263
// agent constants
6364
pub const AGENT: &str = "agent";

0 commit comments

Comments
 (0)