-
-
Save sorentwo/f5ba9048e1e91456d37a8c7d4b8e4d58 to your computer and use it in GitHub Desktop.
Kubernetes for Oban Auto Scaling
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
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) | |
end | |
@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) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment