added steps to support bootstrapping by loading filepath to CA
@@ -10,11 +10,11 @@ use rcgen::{
Certificate, CertificateParams, DistinguishedName, DnType, KeyPair, SanType,
PKCS_ECDSA_P256_SHA256,
};
-use tokio::fs::{read, write, File};
+use tokio::fs::{read, read_to_string, write, File};
use tokio::io::AsyncWriteExt;
use tracing::{debug, info, instrument, trace};
-use crate::config::Config as KubeletConfig;
+use crate::config::{self, Config as KubeletConfig};
use crate::kubeconfig::exists as kubeconfig_exists;
use crate::kubeconfig::KUBECONFIG;
@@ -66,14 +66,23 @@ async fn bootstrap_auth<K: AsRef<Path>>(
})?;
let server = named_cluster.cluster.server;
trace!(%server, "Identified server information from bootstrap config");
- let ca_data = named_cluster
- .cluster
- .certificate_authority_data
- .ok_or_else(|| {
- anyhow::anyhow!(
+
+ let ca_data = match named_cluster.cluster.certificate_authority {
+ Some(certificate_authority) => {
+ read_to_string(certificate_authority).await.map_err(|e| {
+ anyhow::anyhow!(format!("Error loading certificate_authority file: {}", e))
+ })?
+ }
+ None => match named_cluster.cluster.certificate_authority_data {
+ Some(certificate_authority_data) => certificate_authority_data,
+ None => {
+ return Err(anyhow::anyhow!(
"Unable to find certificate authority information in bootstrap config"
- )
- })?;
+ ))
+ }
+ },
+ };
+
trace!(csr_name = %config.node_name, "Generating and sending CSR to Kubernetes API");
let csrs: Api<CertificateSigningRequest> = Api::all(client);
let csr_json = serde_json::json!({
