Skip to content

Commit

Permalink
Merge pull request bottlerocket-os#2725 from ecpullen/testsys-userdata
Browse files Browse the repository at this point in the history
testsys: Accept custom userdata
  • Loading branch information
ecpullen authored Jan 13, 2023
2 parents 2cda97c + 32f7dc1 commit 65026b1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
3 changes: 3 additions & 0 deletions tools/testsys-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ pub struct GenericVariantConfig {
pub conformance_registry: Option<String>,
/// The endpoint IP to reserve for the vSphere control plane VMs when creating a K8s cluster
pub control_plane_endpoint: Option<String>,
/// The path to userdata that should be used for Bottlerocket launch
pub userdata: Option<String>,
}

impl GenericVariantConfig {
Expand All @@ -222,6 +224,7 @@ impl GenericVariantConfig {
conformance_image: self.conformance_image.or(other.conformance_image),
conformance_registry: self.conformance_registry.or(other.conformance_registry),
control_plane_endpoint: self.control_plane_endpoint.or(other.control_plane_endpoint),
userdata: self.userdata.or(other.userdata),
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion tools/testsys/src/aws_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::crds::BottlerocketInput;
use crate::error::{self, Result};
use aws_sdk_ec2::model::{Filter, Image};
use aws_sdk_ec2::Region;
use bottlerocket_types::agent_config::{ClusterType, Ec2Config};
use bottlerocket_types::agent_config::{ClusterType, CustomUserData, Ec2Config};
use maplit::btreemap;
use model::{DestructionPolicy, Resource};
use serde::Deserialize;
Expand Down Expand Up @@ -146,6 +146,12 @@ pub(crate) async fn ec2_crd<'a>(
.cloned()
.collect(),
)
.custom_user_data(
bottlerocket_input
.crd_input
.encoded_userdata()?
.map(|encoded_userdata| CustomUserData::Merge { encoded_userdata }),
)
.cluster_name_template(cluster_name, "clusterName")
.region_template(cluster_name, "region")
.instance_profile_arn_template(cluster_name, "iamInstanceProfileArn")
Expand Down
14 changes: 14 additions & 0 deletions tools/testsys/src/crds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ impl<'a> CrdInput<'a> {
.collect())
}

/// Use the provided userdata path to create the encoded userdata.
pub fn encoded_userdata(&self) -> Result<Option<String>> {
let userdata_path = match self.config.userdata.as_ref() {
Some(path) => path,
None => return Ok(None),
};

let userdata = std::fs::read_to_string(userdata_path).context(error::FileSnafu {
path: userdata_path,
})?;

Ok(Some(base64::encode(userdata)))
}

/// Fill in the templated cluster name with `arch` and `variant`.
fn rendered_cluster_name(&self, raw_cluster_name: String) -> Result<String> {
Ok(rendered_cluster_name(
Expand Down
5 changes: 5 additions & 0 deletions tools/testsys/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ struct CliConfig {
/// The endpoint IP to reserve for the vSphere control plane VMs when creating a K8s cluster
#[clap(long, env = "TESTSYS_CONTROL_PLANE_ENDPOINT")]
pub control_plane_endpoint: Option<String>,

/// Specify the path to the userdata that should be added for Bottlerocket launch
#[clap(long, env = "TESTSYS_USERDATA")]
pub userdata: Option<String>,
}

impl From<CliConfig> for GenericVariantConfig {
Expand All @@ -154,6 +158,7 @@ impl From<CliConfig> for GenericVariantConfig {
conformance_image: val.conformance_image,
conformance_registry: val.conformance_registry,
control_plane_endpoint: val.control_plane_endpoint,
userdata: val.userdata,
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion tools/testsys/src/vmware_k8s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::error::{self, Result};
use crate::migration::migration_crd;
use crate::sonobuoy::sonobuoy_crd;
use bottlerocket_types::agent_config::{
CreationPolicy, K8sVersion, VSphereK8sClusterConfig, VSphereK8sClusterInfo, VSphereVmConfig,
CreationPolicy, CustomUserData, K8sVersion, VSphereK8sClusterConfig, VSphereK8sClusterInfo,
VSphereVmConfig,
};
use maplit::btreemap;
use model::{Crd, DestructionPolicy, SecretName};
Expand Down Expand Up @@ -198,6 +199,12 @@ impl CrdCreator for VmwareK8sCreator {
control_plane_endpoint_ip: format!("${{{}.endpoint}}", cluster_name),
kubeconfig_base64: format!("${{{}.encodedKubeconfig}}", cluster_name),
})
.custom_user_data(
bottlerocket_input
.crd_input
.encoded_userdata()?
.map(|encoded_userdata| CustomUserData::Merge { encoded_userdata }),
)
.assume_role(bottlerocket_input.crd_input.config.agent_role.clone())
.set_labels(Some(labels))
.set_conflicts_with(Some(existing_clusters))
Expand Down

0 comments on commit 65026b1

Please sign in to comment.