Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ k8s-openapi ={ version = "0.20.0", features = ["v1_28"] }
kube = "0.87.2"
log = "0.4.21"
rand = "0.8.5"
rayon = "1.9.0"
reqwest = { version = "0.11.23", features = ["blocking", "brotli", "deflate", "gzip", "rustls-tls", "json"] }
rustls = { version = "0.21.11", default-features = false, features = ["quic"] }
solana-core = "1.18.8"
solana-ledger = "1.18.8"
solana-logger = "1.18.8"
solana-sdk = "1.18.8"
strum = "0.26.2"
Expand Down
35 changes: 16 additions & 19 deletions src/library.rs → src/cluster_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,33 @@ use {
// 3) RPC Node -> One image for each RPC node (not implemented yet)
// 4) Clients -> Each client has its own image (not implemented yet)

pub struct Library {
validators: Vec<Option<Validator>>,
_clients: Option<Vec<Validator>>,
#[derive(Default)]
pub struct ClusterImages {
bootstrap: Option<Validator>,
_validator: Option<Validator>,
_rpc: Option<Validator>,
_clients: Vec<Validator>,
}

impl Default for Library {
fn default() -> Self {
Self {
validators: vec![None; 1],
_clients: None,
}
}
}

impl Library {
impl ClusterImages {
pub fn set_item(&mut self, item: Validator, validator_type: ValidatorType) {
match validator_type {
ValidatorType::Bootstrap => self.validators[0] = Some(item),
ValidatorType::Bootstrap => self.bootstrap = Some(item),
_ => panic!("{validator_type} not implemented yet!"),
}
}

pub fn bootstrap(&mut self) -> Result<&mut Validator, Box<dyn Error>> {
self.validators
.get_mut(0)
.and_then(Option::as_mut)
.ok_or_else(|| "No Bootstrap validator found.".to_string().into())
self.bootstrap
.as_mut()
.ok_or_else(|| "Bootstrap validator is not available".into())
}

pub fn get_validators(&self) -> impl Iterator<Item = &Validator> {
self.validators.iter().filter_map(Option::as_ref)
self.bootstrap
.iter()
.chain(self._validator.iter())
.chain(self._rpc.iter())
.filter_map(Some)
}
}
47 changes: 22 additions & 25 deletions src/docker.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use {
crate::{
new_spinner_progress_bar, release::DeployMethod, startup_scripts::StartupScripts,
validator::Validator, DockerPushThreadError, ValidatorType, BUILD, ROCKET,
validator::Validator, ValidatorType, BUILD, ROCKET,
},
log::*,
rayon::prelude::*,
std::{
error::Error,
fmt::{self, Display, Formatter},
fs,
path::{Path, PathBuf},
process::{Command, Stdio},
process::{Child, Command, Stdio},
},
};

Expand Down Expand Up @@ -198,40 +197,38 @@ WORKDIR /home/solana
Ok(())
}

pub fn push_image(docker_image: &DockerImage) -> Result<(), Box<dyn Error + Send>> {
let progress_bar = new_spinner_progress_bar();
progress_bar.set_message(format!(
"{ROCKET}Pushing {docker_image} image to registry...",
));
pub fn push_image(docker_image: &DockerImage) -> Result<Child, Box<dyn Error>> {
let command = format!("docker push '{docker_image}'");
let output = Command::new("sh")
let child = Command::new("sh")
.arg("-c")
.arg(&command)
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.expect("Failed to execute command")
.wait_with_output()
.expect("Failed to push image");
.spawn()?;

if !output.status.success() {
return Err(Box::new(DockerPushThreadError::from(
output.status.to_string(),
)));
}
progress_bar.finish_and_clear();
Ok(())
Ok(child)
}

pub fn push_images<'a, I>(&self, validators: I) -> Result<(), Box<dyn Error + Send>>
pub fn push_images<'a, I>(&self, validators: I) -> Result<(), Box<dyn Error>>
where
I: IntoIterator<Item = &'a Validator>,
{
info!("Pushing images...");
validators
let children: Result<Vec<Child>, _> = validators
.into_iter()
.collect::<Vec<_>>() // Collect into Vec and thread push
.par_iter()
.try_for_each(|validator| Self::push_image(validator.image()))
.map(|validator| Self::push_image(validator.image()))
.collect();

let progress_bar = new_spinner_progress_bar();
progress_bar.set_message(format!("{ROCKET}Pushing images to registry..."));
for child in children? {
let output = child.wait_with_output()?;
if !output.status.success() {
return Err(output.status.to_string().into());
}
}
progress_bar.finish_and_clear();

Ok(())
}
}
104 changes: 87 additions & 17 deletions src/k8s_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
use {
k8s_openapi::{api::core::v1::Secret, ByteString},
kube::api::ObjectMeta,
std::{
collections::{BTreeMap, HashMap},
error::Error,
path::PathBuf,
crate::{docker::DockerImage, ValidatorType},
k8s_openapi::{
api::{
apps::v1::{ReplicaSet, ReplicaSetSpec},
core::v1::{
Container, EnvVar, PodSecurityContext, PodSpec, PodTemplateSpec, Probe,
ResourceRequirements, Secret, Volume, VolumeMount,
},
},
apimachinery::pkg::{api::resource::Quantity, apis::meta::v1::LabelSelector},
ByteString,
},
kube::api::ObjectMeta,
std::{collections::BTreeMap, error::Error, path::PathBuf},
};

pub enum SecretType {
Expand All @@ -26,21 +33,20 @@ fn build_secret(name: &str, data: BTreeMap<String, ByteString>) -> Secret {

pub fn create_secret(
secret_name: &str,
secrets: HashMap<String, SecretType>,
secrets: BTreeMap<String, SecretType>,
) -> Result<Secret, Box<dyn Error>> {
let mut data: BTreeMap<String, ByteString> = BTreeMap::new();
for (label, value) in secrets {
match value {
SecretType::Value { v } => {
data.insert(label, ByteString(v.into_bytes()));
}
let data = secrets
.into_iter()
.map(|(label, value)| match value {
SecretType::Value { v } => Ok((label, ByteString(v.into_bytes()))),
SecretType::File { path } => {
let file_content = std::fs::read(&path)
let content = std::fs::read(&path)
.map_err(|err| format!("Failed to read file '{:?}': {}", path, err))?;
data.insert(label, ByteString(file_content));
Ok((label, ByteString(content)))
}
}
}
})
.collect::<Result<BTreeMap<String, ByteString>, Box<dyn Error>>>()?;

Ok(build_secret(secret_name, data))
}

Expand All @@ -49,3 +55,67 @@ pub fn create_selector(key: &str, value: &str) -> BTreeMap<String, String> {
btree.insert(key.to_string(), value.to_string());
btree
}

#[allow(clippy::too_many_arguments)]
pub fn create_replica_set(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea if this works, so I'll assume it's all correct 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha it does. but i could change create_replica_set() to accept a struct instead of all the args.

name: ValidatorType,
namespace: String,
label_selector: BTreeMap<String, String>,
image_name: DockerImage,
environment_variables: Vec<EnvVar>,
command: Vec<String>,
volumes: Option<Vec<Volume>>,
volume_mounts: Option<Vec<VolumeMount>>,
pod_requests: BTreeMap<String, Quantity>,
readiness_probe: Option<Probe>,
) -> Result<ReplicaSet, Box<dyn Error>> {
let pod_spec = PodTemplateSpec {
metadata: Some(ObjectMeta {
labels: Some(label_selector.clone()),
..Default::default()
}),
spec: Some(PodSpec {
containers: vec![Container {
name: format!("{}-container", image_name.validator_type()),
image: Some(image_name.to_string()),
image_pull_policy: Some("Always".to_string()),
env: Some(environment_variables),
command: Some(command),
volume_mounts,
readiness_probe,
resources: Some(ResourceRequirements {
requests: Some(pod_requests),
..Default::default()
}),
..Default::default()
}],
volumes,
security_context: Some(PodSecurityContext {
run_as_user: Some(1000),
run_as_group: Some(1000),
..Default::default()
}),
..Default::default()
}),
};

let replicas_set_spec = ReplicaSetSpec {
replicas: Some(1),
selector: LabelSelector {
match_labels: Some(label_selector),
..Default::default()
},
template: Some(pod_spec),
..Default::default()
};

Ok(ReplicaSet {
metadata: ObjectMeta {
name: Some(format!("{name}-replicaset")),
namespace: Some(namespace),
..Default::default()
},
spec: Some(replicas_set_spec),
..Default::default()
})
}
Loading