-
Notifications
You must be signed in to change notification settings - Fork 84
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 one-off command #65
base: master
Are you sure you want to change the base?
Conversation
This command takes the image of the container of the current pod and runs the specified command in a one-off kubectl run command. If the pod has multiple containers and none is specified, it will fail asking for the specific container.
I might have done some things wrong, so I'm really happy to receive feedback on this! |
src/cmd.rs
Outdated
.arg("--context") | ||
.arg(&kluster.name) | ||
.arg("run") | ||
.arg("one-off-shell") |
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.
Could be named more specific eg. <pod_name>-one-off
src/cmd.rs
Outdated
@@ -1145,6 +1145,199 @@ command!( | |||
} | |||
); | |||
|
|||
command!( | |||
OneOff, |
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.
OneOff
should be probably Run
to mimic the kubectl
command.
Would be useful to have the env variables of the specified pod set as well. |
The challenge with the env variables is, that there might be some variables from secrets and |
This looks great! I'm just gonna test it out and then will leave comments and/or merge |
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.
looks pretty good, modulo needing to fix the name
src/cmd.rs
Outdated
clickwrite!(writer, "Couldon't get container image\n"); | ||
return; | ||
}; | ||
let pod_name = format!("one-off-shell-{}", container_image.as_str()); |
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.
this needs to truncate to 63 characters, and also needs to replace any invalid or uppercase characters. 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])?)*')
8782157
to
64b5b4e
Compare
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])?)*' ```
64b5b4e
to
7078ddb
Compare
@nicklan thanks for pointing that out. I added a method to sanitise the pod name. |
I realised that the current implementation only allows one run command of the same image at the same time. A random sequence could be added to the K8s name so it does not fail for more run commands for the same pod/image at the same time. |
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.
Thanks for the fixup, it works on some stuff now, but short pod names cause a panic.
let pod_name_regex = Regex::new(r"[^a-z0-9-]").unwrap(); | ||
let result = pod_name_regex.replace_all(&s.to_ascii_lowercase().to_string(), "-").to_string(); | ||
|
||
if &result[0..1] == "-" || &result[58..59] == "-" { |
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.
You can't hard-code up to 59 here since the pod name might be less than 59 characters which will cause a panic. You'll need to look at the string length and go off that.
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.
Oh no that's not good. I also realized that you can't run a command for the same pod twice. So while fixing this I would also introduce a random string to accommodate that use case.
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.
Yeah, that's true. The other option is that you can delete the pod when it's done. Maybe the right thing to do would be to default to adding a random string, but have an option like --name
that lets you set the name you want to use
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.
Good point!
This command takes the image of the container of the current pod
and runs the specified command in a one-off kubectl run command.
If the pod has multiple containers and none is specified, it will
fail asking for the specific container.