Skip to content

Commit

Permalink
set namespace and generateName if not set
Browse files Browse the repository at this point in the history
  • Loading branch information
mruoss committed Aug 27, 2024
1 parent b76c506 commit 018888c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

<!--------------------- Don't add new entries after this line --------------------->

### Added

- `FLAMEK8sBackend.RunnerPodTemplate`: Set `.metadata.namespace` and `.metadata.generateName` on runner pod if not set ([#43](https://github.com/mruoss/flame_k8s_backend/pull/43))

## [0.4.3] - 2024-08-22

### Fixed
Expand Down
10 changes: 8 additions & 2 deletions lib/flame_k8s_backend/runner_pod_template.ex
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ defmodule FLAMEK8sBackend.RunnerPodTemplate do
opts
) do
parent_pod_manifest_name = parent_pod_manifest["metadata"]["name"]
parent_pod_manifest_namespace = parent_pod_manifest["metadata"]["namespace"]

object_references =
if opts[:omit_owner_reference],
Expand All @@ -263,8 +264,13 @@ defmodule FLAMEK8sBackend.RunnerPodTemplate do

runner_pod_template
|> Map.merge(%{"apiVersion" => "v1", "kind" => "Pod"})
|> put_in(~w(metadata generateName), parent_pod_manifest_name <> "-")
|> put_in(~w(metadata ownerReferences), object_references)
|> update_in([Access.key("metadata", %{})], fn metadata ->
metadata
|> Map.delete("name")
|> Map.put_new("generateName", parent_pod_manifest_name <> "-")
|> Map.put_new("namespace", parent_pod_manifest_namespace)
|> Map.put("ownerReferences", object_references)
end)
|> put_in(~w(spec restartPolicy), "Never")
|> put_in(~w(spec serviceAccount), parent_pod_manifest["spec"]["serviceAccount"])
|> update_in(["spec", "containers", Access.at(0)], fn container ->
Expand Down

0 comments on commit 018888c

Please sign in to comment.