View Source FLAMEK8sBackend.RunnerPodTemplate (flame_k8s_backend v0.3.3)

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 Case - Passing a Callback Function

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 pass a callback via runner_pod_tpl option to the FLAMEK8sBackend.

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 and Kind of the resource (set to v1/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 to Never)
  • The container image (set to the image of the parent pod's app container)

Options

  • :omit_owner_reference - Omit generating and appending the parent pod as ownerReference 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
}

Functions

Link to this function

manifest(parent_pod_manifest, template_args_or_callback, encoded_parent, opts \\ [])

View Source

Generates the POD manifest using information from the parent pod and the runner_pod_tpl option.