Skip to content

Instantly share code, notes, and snippets.

Created March 28, 2023 18:56
What would you like to do?
Kubernetes for Oban Auto Scaling
defmodule Oban.Pro.Clouds.Kubernetes do
@moduledoc false
@behaviour Oban.Pro.Cloud
@enforce_keys [:api_server, :bearer_token, :deployment, :namespace]
defstruct @enforce_keys
@impl Oban.Pro.Cloud
def init(opts) do
struct!(__MODULE__, opts)
@impl Oban.Pro.Cloud
def scale(quantity, %__MODULE__{} = conf) do
api_server: api_server,
namespace: namespace,
deployment: deployment,
bearer_token: bearer_token
} = conf
url = "#{api_server}/apis/apps/v1/namespaces/#{namespace}/deployments/#{deployment}/scale"
headers = [
{"Content-Type", "application/strategic-merge-patch+json"},
{"Accept", "application/json"},
{"Authorization", "Bearer #{bearer_token}"}
Req.patch!(url, json: %{"spec" => %{"replicas" => quantity}}, headers: headers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment