-
-
Save obmarg/c31d91b61a0ef8aff4f0428f7412d3a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias Kazan.Apis.Core.V1, as: Core | |
alias Kazan.Models.Apimachinery.Meta.V1, as: Meta | |
alias Kazan.Apis.Batch.V1, as: Batch | |
def deploy!(request, project, namespace, opts \\ []) do | |
server = server(opts) | |
Logger.debug("Creating job for request #{request.id}") | |
job = | |
request | |
|> build_job(project) | |
|> Batch.create_namespaced_job!(namespace) | |
|> Kazan.run!(server: server) | |
Logger.debug("Job created for request #{request.id}. Watching for updates") | |
namespace | |
|> Batch.watch_namespaced_job!(job.metadata.name) | |
|> Kazan.Watcher.start_link( | |
resource_version: job.metadata.resource_version, | |
send_to: self(), | |
server: server | |
) | |
|> await_done(job) | |
end | |
defp await_done({:ok, watcher}, job) do | |
receive do | |
%Meta.WatchEvent{object: %{status: status}, type: "MODIFIED"} -> | |
cond do | |
status.failed == 1 -> | |
Logger.warn("Job Failed") | |
Logger.warn(inspect(job)) | |
{:error, :job_failed} | |
status.succeeded == 1 -> | |
Logger.info("Job Succeeded") | |
:ok | |
status.active == 1 -> | |
Logger.debug("Job in progress") | |
await_done({:ok, watcher}, job) | |
:otherwise -> | |
Logger.debug( | |
"K8s deploy received unknown status: #{inspect(status)}" | |
) | |
await_done({:ok, watcher}, job) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment