View Source FLAMEK8sBackend.RunnerPodTemplate (flame_k8s_backend v0.5.6)
This module is responsible for generating the manifest for the runner pods.
The manifest can be overridden using the runner_pod_tpl
option on
FLAMEK8sBackend
.
Simple Use Case
By default, resources
and env
variables are copied from the parent pod.
Using the runner_pod_tpl
option on the FLAMEK8sBackend
, you can add
additional environment variables or set different resources
. You would do
this by setting the runner_pod_tpl
to a struct of type
FLAMEK8sBackend.RunnerPodTemplate.t/0
as follows:
# application.ex
alias FLAMEK8sBackend.RunnerPodTemplate
children = [
{FLAME.Pool,
name: MyApp.SamplePool,
backend: {FLAMEK8sBackend,
runner_pod_tpl: %RunnerPodTemplate{
env: [%{"name" => "FOO", "value" => "bar"}],
resources: %{
requests: %{"memory" => "256Mi", "cpu" => "100m"},
limimts: %{"memory" => "256Mi", "cpu" => "400m"}
}
}
},
# other opts
}
]
# ...
Advanced Use Cases
In some cases you might need advanced control over the runner pod manifest.
Maybe you want to set node affinity because you need your runners to run on
nodes with GPUs or you need additional volumes etc. In this case, you can set
runner_pod_tpl
to either a map representing the Pod manifest or a callback
function as described below.
Using a Manifest Map
You can set runner_pod_tpl
to a map representing the manifest of the runner
Pod:
# application.ex
alias FLAMEK8sBackend.RunnerPodTemplate
import YamlElixir.Sigil
pod_template = ~y"""
apiVersion: v1
kind: Pod
metadata:
# your metadata
spec:
# Pod spec
"""
children = [
{FLAME.Pool,
name: MyApp.SamplePool,
backend: {FLAMEK8sBackend, runner_pod_tpl: pod_template},
# other opts
}
]
# ...
Using a Callback Function
The callback has to be of type
FLAMEK8sBackend.RunnerPodTemplate.callback/0
. The callback will be called
with the manifest of the parent pod which can be used to extract information.
It should return a pod template as a map
Define a callback, e.g. in a separate module:
defmodule MyApp.FLAMERunnerPodTemplate do
def runner_pod_manifest(parent_pod_manifest) do
%{
"metadata" => %{
# namespace, labels, ownerReferences,...
},
"spec" => %{
"containers" => [
%{
# container definition
}
]
}
}
end
end
Register the backend:
# application.ex
# ...
children = [
{FLAME.Pool,
name: MyApp.SamplePool,
backend: {FLAMEK8sBackend, runner_pod_tpl: &MyApp.FLAMERunnerPodTemplate.runner_pod_manifest/1},
# other opts
}
]
# ...
Predefined Values
Note that the following values are controlled by the backend and, if set by your callback function, are going to be overwritten:
apiVersion
andKind
of the resource (set tov1/Pod
)- The pod's and container's names (set to a combination of the parent pod's name and a random id)
- The
restartPolicy
(set toNever
)- The container
image
(set to the image of the parent pod's app container)
Automatically Defined Environment Variables
Some environment variables are defined automatically on the runner pod:
POD_IP
is set to the runner Pod's IP address (.status.podIP
) - (not overridable)POD_NAME
is set to the runner Pod's name (.metadata.name
) - (not overridable)POD_NAMESPACE
is set to the runner Pod's namespace (.metadata.namespace
) - (not overridable)PHX_SERVER
is set tofalse
(overridable)FLAME_PARENT
used internally by FLAME - (not overridable)
Options
:omit_owner_reference
- Omit generating and appending the parent pod asownerReference
to the runner pod's metadata:app_container_name
- name of the container running this application. By default, the first container in the list of containers is used.
Summary
Functions
Generates the POD manifest using information from the parent pod
and the runner_pod_tpl
option.
Types
@type callback() :: (parent_pod_manifest() -> runner_pod_template :: map())
@type parent_pod_manifest() :: map()
@type t() :: %FLAMEK8sBackend.RunnerPodTemplate{ add_parent_env: boolean(), env: map() | nil, resources: map() | nil }
Describing the Runner Pod Template struct
Fields
env
- a map describing a Pod environment variable declaration%{"name" => "MY_ENV_VAR", "value" => "my_env_var_value"}
resources
- Pod resource requests and limits.add_parent_env
- If true, all env vars of the main container includingenvFrom
are copied to the runner pod. default:true
Functions
manifest(parent_pod_manifest, template_args_or_callback, parent_ref, opts \\ [])
View SourceGenerates the POD manifest using information from the parent pod
and the runner_pod_tpl
option.