Skip to content

Commit 10beef1

Browse files
authored
Merge pull request #14 from svend/optional-cluster-cert
Make cluster certificate authority optional
2 parents d2772e1 + 039fcf5 commit 10beef1

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/config/apis.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,15 @@ impl Config {
114114
}
115115

116116
impl Cluster {
117-
pub fn load_certificate_authority(&self) -> Result<Vec<u8>, Error> {
118-
utils::data_or_file_with_base64(
119-
&self.certificate_authority_data,
120-
&self.certificate_authority,
121-
)
117+
pub fn load_certificate_authority(&self) -> Option<Result<Vec<u8>, Error>> {
118+
if self.certificate_authority_data.is_some() || self.certificate_authority.is_some() {
119+
Some(utils::data_or_file_with_base64(
120+
&self.certificate_authority_data,
121+
&self.certificate_authority,
122+
))
123+
} else {
124+
None
125+
}
122126
}
123127
}
124128

src/config/kube_config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ impl KubeConfigLoader {
5555
.map_err(Error::from)
5656
}
5757

58-
pub fn ca(&self) -> Result<X509, Error> {
59-
let ca = &self.cluster.load_certificate_authority()?;
60-
X509::from_pem(&ca).map_err(Error::from)
58+
pub fn ca(&self) -> Option<Result<X509, Error>> {
59+
let ca = self.cluster.load_certificate_authority()?;
60+
Some(ca.and_then(|ca| X509::from_pem(&ca).map_err(Error::from)))
6161
}
6262
}

src/config/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ pub fn load_kube_config() -> Result<Configuration, Error> {
4141
let loader = KubeConfigLoader::load(kubeconfig)?;
4242
let mut client_builder = Client::builder();
4343

44-
let ca = loader.ca()?;
45-
let req_ca = Certificate::from_der(&ca.to_der()?)?;
46-
client_builder = client_builder.add_root_certificate(req_ca);
47-
44+
if let Some(ca) = loader.ca() {
45+
let req_ca = Certificate::from_der(&ca?.to_der()?)?;
46+
client_builder = client_builder.add_root_certificate(req_ca);
47+
}
4848
match loader.p12(" ") {
4949
Ok(p12) => {
5050
let req_p12 = Identity::from_pkcs12_der(&p12.to_der()?, " ")?;

0 commit comments

Comments
 (0)