@@ -8,7 +8,7 @@ use crate::{
88} ;
99use async_trait:: async_trait;
1010use 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} ;
1414use 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
7071impl 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
0 commit comments