Add function to handle Rundeck environment variables and options for execution in pod #161
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I like to improve the script and command execution in pods in the way, that the environment variables set by Rundeck like the possible options of a job, are propagated to the pod. And create with this a behavior like running jobs on the local machine. For this, I wrote two functions.
common.handle_rundeck_environment_variables
: This function is called inpods-run-script.py
andpods-node-executor.py
. In the function all environment variables of the current Rundeck process are filtered for just variables where the key starts withRD_
. Also the function looks for variables that starts withRD_FILE_
that are uploaded files. This files are needed to uploaded to the pod too. The default directory is/tmp
or what inRD_NODE_FILE_COPY_DESTINATION_DIR
is defined.The function returns two arrays. The first array including all environment variables and can be added in front of the execution command. The first element is the command
env
and the following elements in the array are strings in the format'key=value'
. The second array contains all paths of uploaded files. This array can be used for my second function.common.clean_up_temporary_files
: This function is called in the end ofpods-run-script.py
andpods-node-executor.py
. Like the name says the function delete uploaded files from the pod.In the pods-run-script function the temporary created script is added to the list of to deleting files.
My Background:
I like to use Rundeck in a kind “as a service” for multiple departments in my organization. To separate the environment of every department I like to use pods in my k8s. With this separation the departments can’t break or delete setups from other departments. But to use pods like running jobs on the local Rundeck machine it is needed to also have all Rundeck environment variables and uploaded files inside the pod.