-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add bootstrap kubernetes labels and validator management structs #9
Changes from all commits
f025ae7
9596709
8d5f9a3
d5a071a
68ac58f
565c8f0
146a546
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
use { | ||
k8s_openapi::{api::core::v1::Secret, ByteString}, | ||
kube::api::ObjectMeta, | ||
std::{collections::BTreeMap, error::Error, path::PathBuf}, | ||
std::{ | ||
collections::{BTreeMap, HashMap}, | ||
error::Error, | ||
path::PathBuf, | ||
}, | ||
}; | ||
|
||
fn create_secret(name: &str, data: BTreeMap<String, ByteString>) -> Secret { | ||
pub enum SecretType { | ||
Value { v: String }, | ||
File { path: PathBuf }, | ||
} | ||
|
||
fn build_secret(name: &str, data: BTreeMap<String, ByteString>) -> Secret { | ||
Secret { | ||
metadata: ObjectMeta { | ||
name: Some(name.to_string()), | ||
|
@@ -15,16 +24,28 @@ fn create_secret(name: &str, data: BTreeMap<String, ByteString>) -> Secret { | |
} | ||
} | ||
|
||
pub fn create_secret_from_files( | ||
pub fn create_secret( | ||
secret_name: &str, | ||
key_files: &[(PathBuf, &str)], //[pathbuf, key type] | ||
secrets: HashMap<String, SecretType>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Since |
||
) -> Result<Secret, Box<dyn Error>> { | ||
let mut data = BTreeMap::new(); | ||
for (file_path, key_type) in key_files { | ||
let file_content = std::fs::read(file_path) | ||
.map_err(|err| format!("Failed to read file '{:?}': {}", file_path, err))?; | ||
data.insert(format!("{}.json", key_type), ByteString(file_content)); | ||
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())); | ||
} | ||
SecretType::File { path } => { | ||
let file_content = std::fs::read(&path) | ||
.map_err(|err| format!("Failed to read file '{:?}': {}", path, err))?; | ||
data.insert(label, ByteString(file_content)); | ||
} | ||
} | ||
Comment on lines
+31
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: you might be able to do this in one statement by collecting into a
|
||
} | ||
Ok(build_secret(secret_name, data)) | ||
} | ||
|
||
Ok(create_secret(secret_name, data)) | ||
pub fn create_selector(key: &str, value: &str) -> BTreeMap<String, String> { | ||
let mut btree = BTreeMap::new(); | ||
btree.insert(key.to_string(), value.to_string()); | ||
btree | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
push_image
is usingCommand::spawn
internally, it creates a new process anyway, so thepar_iter
is a little overkill. You could havepush_image
return theprocess::Child
and then iterate through them here withwait_with_output
, and completely remove rayon