Skip to content

Commit 64b5b4e

Browse files
committed
Ensure proper pod name for Run command
From k8s: ``` must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*' ```
1 parent 8f11d2f commit 64b5b4e

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/cmd.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,15 @@ fn shorten_to(s: String, max_len: usize) -> String {
324324
}
325325
}
326326

327+
/// Replace all characters that are not allowed as part of a pod name
328+
fn ensure_pod_name(s: String) -> String {
329+
let pod_name_regex = Regex::new(r"[^a-z0-9\.-]").unwrap();
330+
shorten_to(
331+
pod_name_regex.replace_all(&s.to_ascii_lowercase().to_string(), "-").to_string(),
332+
63
333+
)
334+
}
335+
327336
/// Print out the specified list of pods in a pretty format
328337
fn print_podlist(
329338
podlist: PodList,
@@ -1275,7 +1284,7 @@ command!(
12751284
clickwrite!(writer, "Couldon't get container image\n");
12761285
return;
12771286
};
1278-
let pod_name = format!("one-off-shell-{}", container_image.as_str());
1287+
let pod_name = format!("run-{}", ensure_pod_name(container_image.to_string()));
12791288

12801289
if matches.is_present("terminal") {
12811290
let terminal = if let Some(t) = matches.value_of("terminal") {

0 commit comments

Comments
 (0)