-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3acd0d
commit cf565ae
Showing
6 changed files
with
93 additions
and
200 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,215 +1,57 @@ | ||
defmodule Kube.Client do | ||
use Kube.Client.Base | ||
alias Kube | ||
alias Kazan.Models.Apimachinery.Meta.V1.{ObjectMeta} | ||
|
||
def list_dashboards(ns) do | ||
%Kazan.Request{ | ||
method: "get", | ||
path: "/apis/platform.plural.sh/v1alpha1/namespaces/#{Console.namespace(ns)}/dashboards", | ||
query_params: %{}, | ||
response_model: Kube.DashboardList | ||
} | ||
|> Kazan.run() | ||
end | ||
|
||
def list_log_filters(ns) do | ||
%Kazan.Request{ | ||
method: "get", | ||
path: "/apis/platform.plural.sh/v1alpha1/namespaces/#{Console.namespace(ns)}/logfilters", | ||
query_params: %{}, | ||
response_model: Kube.LogFilterList | ||
} | ||
|> Kazan.run() | ||
end | ||
list_request :list_dashboards, Kube.DashboardList, "platform.plural.sh", "v1alpha1", "dashboards" | ||
list_request :list_log_filters, Kube.LogFilterList, "platform.plural.sh", "v1alpha1", "logfilters" | ||
list_request :list_configuration_overlays, Kube.ConfigurationOverlayList, "platform.plural.sh", "v1alpha1", "configurationoverlays" | ||
list_request :list_runbooks, Kube.RunbookList, "platform.plural.sh", "v1alpha1", "runbooks" | ||
list_request :list_vertical_pod_autoscalers, Kube.VerticalPodAutoscalerList, "autoscaling.k8s.io", "v1", "verticalpodautoscalers" | ||
|
||
def list_configuration_overlays(ns) do | ||
%Kazan.Request{ | ||
method: "get", | ||
path: "/apis/platform.plural.sh/v1alpha1/namespaces/#{Console.namespace(ns)}/configurationoverlays", | ||
query_params: %{}, | ||
response_model: Kube.ConfigurationOverlayList | ||
} | ||
|> Kazan.run() | ||
end | ||
|
||
def get_dashboard(ns, name) do | ||
%Kazan.Request{ | ||
method: "get", | ||
path: "/apis/platform.plural.sh/v1alpha1/namespaces/#{Console.namespace(ns)}/dashboards/#{name}", | ||
query_params: %{}, | ||
response_model: Kube.Dashboard | ||
} | ||
|> Kazan.run() | ||
end | ||
get_request :get_dashboard, Kube.Dashboard, "platform.plural.sh", "v1alpha1", "dashboards" | ||
get_request :get_slashcommand, Kube.SlashCommand, "platform.plural.sh", "v1alpha1", "slashcommands" | ||
get_request :get_application, Kube.Application, "app.k8s.io", "v1", "applications" | ||
get_request :get_certificate, Kube.Certificate, "cert-manager.io", "v1", "certificates" | ||
get_request :get_runbook, Kube.Runbook, "platform.plural.sh", "v1alpha1", "runbooks" | ||
get_request :get_statefulset_resize, Kube.StatefulSetResize, "platform.plural.sh", "v1alpha1", "statefulsetresizes" | ||
get_request :get_vertical_pod_autoscaler, Kube.VerticalPodAutoscaler, "autoscaling.k8s.io", "v1", "verticalpodautoscalers" | ||
|
||
def get_slashcommand(ns, name) do | ||
%Kazan.Request{ | ||
method: "get", | ||
path: "/apis/platform.plural.sh/v1alpha1/namespaces/#{Console.namespace(ns)}/slashcommands/#{name}", | ||
query_params: %{}, | ||
response_model: Kube.SlashCommand | ||
} | ||
|> Kazan.run() | ||
end | ||
def get_application(name), do: get_application(name, name) | ||
|
||
def list_slashcommands() do | ||
%Kazan.Request{ | ||
method: "get", | ||
path: "/apis/platform.plural.sh/v1alpha1/slashcommands", | ||
query_params: %{}, | ||
response_model: Kube.SlashCommandList | ||
} | ||
|> Kazan.run() | ||
make_request("/apis/platform.plural.sh/v1alpha1/slashcommands", "get", Kube.SlashCommandList) | ||
end | ||
|
||
def list_licenses() do | ||
%Kazan.Request{ | ||
method: "get", | ||
path: "/apis/platform.plural.sh/v1alpha1/licenses", | ||
query_params: %{}, | ||
response_model: Kube.LicenseList | ||
} | ||
|> Kazan.run() | ||
end | ||
|
||
def get_application(name) do | ||
%Kazan.Request{ | ||
method: "get", | ||
path: "/apis/app.k8s.io/v1beta1/namespaces/#{Console.namespace(name)}/applications/#{name}", | ||
query_params: %{}, | ||
response_model: Kube.Application | ||
} | ||
|> Kazan.run() | ||
end | ||
|
||
def get_certificate(ns, name) do | ||
%Kazan.Request{ | ||
method: "get", | ||
path: "/apis/cert-manager.io/v1/namespaces/#{ns}/certificates/#{name}", | ||
query_params: %{}, | ||
response_model: Kube.Certificate | ||
} | ||
|> Kazan.run() | ||
make_request("/apis/platform.plural.sh/v1alpha1/licenses", "get", Kube.LicenseList) | ||
end | ||
|
||
def list_applications() do | ||
%Kazan.Request{ | ||
method: "get", | ||
path: "/apis/app.k8s.io/v1beta1/applications", | ||
query_params: %{}, | ||
response_model: Kube.ApplicationList | ||
} | ||
|> Kazan.run() | ||
end | ||
|
||
def get_application(name) do | ||
ns = Console.namespace(name) | ||
%Kazan.Request{ | ||
method: "get", | ||
path: "/apis/app.k8s.io/v1beta1/namespaces/#{ns}/applications/#{name}", | ||
query_params: %{}, | ||
response_model: Kube.Application | ||
} | ||
|> Kazan.run() | ||
make_request("/apis/app.k8s.io/v1/applications", "get", Kube.ApplicationList) | ||
end | ||
|
||
def list_metrics() do | ||
%Kazan.Request{ | ||
method: "get", | ||
path: "/apis/metrics.k8s.io/v1beta1/nodes", | ||
query_params: %{}, | ||
response_model: Kube.NodeMetricList | ||
} | ||
|> Kazan.run() | ||
make_request("/apis/metrics.k8s.io/v1beta1/nodes", "get", Kube.NodeMetricList) | ||
end | ||
|
||
def get_metrics(node) do | ||
%Kazan.Request{ | ||
method: "get", | ||
path: "/apis/metrics.k8s.io/v1beta1/nodes/#{node}", | ||
query_params: %{}, | ||
response_model: Kube.NodeMetric | ||
} | ||
|> Kazan.run() | ||
end | ||
|
||
def list_runbooks(ns, params \\ %{}) do | ||
%Kazan.Request{ | ||
method: "get", | ||
path: "/apis/platform.plural.sh/v1alpha1/namespaces/#{Console.namespace(ns)}/runbooks", | ||
query_params: params, | ||
response_model: Kube.RunbookList | ||
} | ||
|> Kazan.run() | ||
end | ||
|
||
def get_runbook(ns, name) do | ||
%Kazan.Request{ | ||
method: "get", | ||
path: "/apis/platform.plural.sh/v1alpha1/namespaces/#{Console.namespace(ns)}/runbooks/#{name}", | ||
query_params: %{}, | ||
response_model: Kube.Runbook | ||
} | ||
|> Kazan.run() | ||
make_request("/apis/metrics.k8s.io/v1beta1/nodes/#{node}", "get", Kube.NodeMetric) | ||
end | ||
|
||
def create_statefulset_resize(namespace, name, %Kube.StatefulSetResize{} = resize) do | ||
resize = %{resize | metadata: %ObjectMeta{name: name, namespace: namespace}} | ||
{:ok, encoded} = Kube.StatefulSetResize.encode(resize) | ||
|
||
%Kazan.Request{ | ||
method: "post", | ||
path: "/apis/platform.plural.sh/v1alpha1/namespaces/#{namespace}/statefulsetresizes/#{name}", | ||
query_params: %{}, | ||
body: Jason.encode!(encoded), | ||
content_type: "application/json", | ||
response_model: Kube.StatefulSetResize | ||
} | ||
|> Kazan.run() | ||
end | ||
|
||
def get_statefulset_resize(namespace, name) do | ||
%Kazan.Request{ | ||
method: "get", | ||
path: "/apis/platform.plural.sh/v1alpha1/namespaces/#{namespace}/statefulsetresizes/#{name}", | ||
query_params: %{}, | ||
response_model: Kube.StatefulSetResize | ||
} | ||
|> Kazan.run() | ||
end | ||
|
||
def get_vertical_pod_autoscaler(namespace, name) do | ||
%Kazan.Request{ | ||
method: "get", | ||
path: "/apis/autoscaling.k8s.io/v1/namespaces/#{Console.namespace(namespace)}/verticalpodautoscalers/#{name}", | ||
query_params: %{}, | ||
response_model: Kube.VerticalPodAutoscaler | ||
} | ||
|> Kazan.run() | ||
end | ||
|
||
def list_vertical_pod_autoscalers(namespace) do | ||
%Kazan.Request{ | ||
method: "get", | ||
path: "/apis/autoscaling.k8s.io/v1/namespaces/#{Console.namespace(namespace)}/verticalpodautoscalers", | ||
query_params: %{}, | ||
response_model: Kube.VerticalPodAutoscaler | ||
} | ||
|> Kazan.run() | ||
path_builder("platform.plural.sh", "v1alpha1", "statefulsetresizes", namespace, name) | ||
|> make_request("post", Kube.StatefulSetResize, Jason.encode!(encoded)) | ||
end | ||
|
||
def create_vertical_pod_autoscaler(namespace, name, %Kube.VerticalPodAutoscaler{} = vpa) do | ||
resize = %{vpa | metadata: %ObjectMeta{name: name, namespace: namespace}} | ||
{:ok, encoded} = Kube.VerticalPodAutoscaler.encode(resize) | ||
|
||
%Kazan.Request{ | ||
method: "post", | ||
path: "/apis/autoscaling.k8s.io/v1/namespaces/#{namespace}/verticalpodautoscalers/#{name}", | ||
query_params: %{}, | ||
body: Jason.encode!(encoded), | ||
content_type: "application/json", | ||
response_model: Kube.VerticalPodAutoscaler | ||
} | ||
|> Kazan.run() | ||
path_builder("autoscaling.k8s.io", "v1", "verticalpodautoscalers", namespace, name) | ||
|> make_request("post", Kube.VerticalPodAutoscaler, Jason.encode!(encoded)) | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
defmodule Kube.Client.Base do | ||
defmacro __using__(_) do | ||
quote do | ||
import Kube.Client.Base | ||
end | ||
end | ||
|
||
def make_request(path, verb, model, body \\ "", params \\ %{}) do | ||
%Kazan.Request{ | ||
method: verb, | ||
path: path, | ||
query_params: params, | ||
body: body, | ||
content_type: "application/json", | ||
response_model: model | ||
} | ||
|> Kazan.run() | ||
end | ||
|
||
def path_builder(g, v, k, namespace), do: "/apis/#{g}/#{v}/namespaces/#{Console.namespace(namespace)}/#{k}" | ||
def path_builder(g, v, k, namespace, name), do: "#{path_builder(g, v, k, namespace)}/#{name}" | ||
|
||
defmacro get_request(name, model, g, v, k) do | ||
quote do | ||
def unquote(name)(namespace, name, params \\ %{}) do | ||
%Kazan.Request{ | ||
method: "get", | ||
path: path_builder(unquote(g), unquote(v), unquote(k), namespace, name), | ||
query_params: params, | ||
response_model: unquote(model) | ||
} | ||
|> Kazan.run() | ||
end | ||
end | ||
end | ||
|
||
defmacro list_request(name, model, g, v, k) do | ||
quote do | ||
def unquote(name)(namespace, params \\ %{}) do | ||
%Kazan.Request{ | ||
method: "get", | ||
path: path_builder(unquote(g), unquote(v), unquote(k), namespace), | ||
query_params: params, | ||
response_model: unquote(model) | ||
} | ||
|> Kazan.run() | ||
end | ||
end | ||
end | ||
end |