View Source Kubereq (kubereq v0.2.1)
Kubereq defines a set of Request Steps for Req. All steps combined turn
a Kubernetes configuration in the form of a %Kubereq.Kubeconfig{} struct into a
%Req.Request{} struct containing all headers and options required to
connect to the cluster and perform the given operations.
In order to build %Kubereq.Kubeconfig{} struct you can either use the steps defined
in the Kubeconf library or create your own Kubernetes configuration loader
module combining those steps.
Instead of using this module directly, consider using
Kubegen to generate your API clients.
Examples
The following is a simple but incomplete example for a Client dealing
with ConfigMaps. This code is an extraction of what is generated by
Kubegen when generating a client for
ConfigMaps.
defmodule MyApp.K8sClient.Core.V1.ConfigMap do
@resource_path "api/v1/namespaces/:namespace/configmaps/:name"
defp req() do
kubeconfig = Kubereq.Kubeconfig.load(Kubereq.Kubeconfig.Default)
Kubereq.new(kubeconfig, @resource_path)
end
def get(namespace, name) do
Kubereq.get(req(), namespace, name)
end
def list(namespace, opts \\ []) do
Kubereq.list(req(), namespace, opts)
end
end
Summary
Functions
Applies the given resource using a Server-Side-Apply Patch.
The req struct should have been created using Kubereq.new/2.
Create the resource object.
The req struct should have been created using Kubereq.new/2.
Deletes a resource.
The req struct should have been created using Kubereq.new/2.
Deletes all resources in the given namespace.
The req struct should have been created using Kubereq.new/2.
Get the resource name in namespace.
The req struct should have been created using Kubereq.new/2.
Patches the resource namein namespace using the given json_patch.
The req struct should have been created using Kubereq.new/2.
Get a resource list.
The req struct should have been created using Kubereq.new/2.
Patches the resource namein namespace using the given merge_patch.
The req struct should have been created using Kubereq.new/2.
Prepares a Req.Request struct for making HTTP requests to a Kubernetes
cluster. The kubeconfig is the Kubernetes configuration in the form of a
%Kubereq.Kubeconfig{} struct and should contain all informations required to connect
to the Kubernetes cluster.
Prepares a Req.Request struct for a specific resource on a specific
Kubernetes cluster. The kubeconfig is the Kubernetes configuration in the
form of a %Kubereq.Kubeconfig{} struct and should contain all informations required to
connect to the Kubernetes cluster.
Updates the given resource.
The req struct should have been created using Kubereq.new/2.
GET a resource and wait until the given callback returns true or the given
timeout (ms) has expired.
The req struct should have been created using Kubereq.new/2.
Watch events of all resources in namespace.
The req struct should have been created using Kubereq.new/2.
Watch events of a single resources namein namespace.
The req struct should have been created using Kubereq.new/2.
Types
@type namespace() :: String.t() | nil
@type response() :: {:ok, Req.Response.t()} | {:error, Exception.t()}
@type wait_until_response() :: :ok | {:error, :watch_timeout}
@type watch_response() :: {:ok, Enumerable.t(map())} | {:ok, Task.t()} | {:error, Exception.t()}
Functions
@spec apply( Req.Request.t(), resource :: map(), field_manager :: binary(), force :: boolean() ) :: response()
Applies the given resource using a Server-Side-Apply Patch.
The req struct should have been created using Kubereq.new/2.
See the documentation
for a documentation on field_manager and force arguments.
Examples
iex> Kubereq.apply(req, %{...})
{:ok, %Req.Response{...}
@spec create(Req.Request.t(), resource :: map()) :: response()
Create the resource object.
The req struct should have been created using Kubereq.new/2.
Example
iex> Kubereq.create(req, resource)
{:ok, %Req.Response{status: 201, body: %{...}}}
@spec delete(Req.Request.t(), namespace :: namespace(), name :: String.t()) :: response()
Deletes a resource.
The req struct should have been created using Kubereq.new/2.
Examples
iex> Kubereq.delete(req, "default", "foo")
{:ok, %Req.Response{status: 200, body: %{...}}}
@spec delete_all(Req.Request.t(), namespace :: namespace(), opts :: keyword()) :: response()
Deletes all resources in the given namespace.
The req struct should have been created using Kubereq.new/2.
Examples
iex> Kubereq.delete_all(req, "default", "foo")
{:ok, %Req.Response{...}Options
:field_selectors- A list of field selectors. SeeKubereq.Step.FieldSelectorfor more infos.:label_selectors- A list of field selectors. SeeKubereq.Step.LabelSelectorfor more infos.
@spec get(Req.Request.t(), namespace :: namespace(), name :: String.t()) :: response()
Get the resource name in namespace.
The req struct should have been created using Kubereq.new/2.
Example
iex> Kubereq.get(req, "default", "foo")
{:ok, %Req.Response{status: 200, body: %{...}}}
@spec json_patch( Req.Request.t(), json_patch :: map(), namespace :: namespace(), name :: String.t() ) :: response()
Patches the resource namein namespace using the given json_patch.
The req struct should have been created using Kubereq.new/2.
Examples
iex> Kubereq.json_patch(req, %{...}, "default", "foo")
{:ok, %Req.Response{...}
@spec list(Req.Request.t(), namespace :: namespace(), opts :: keyword()) :: response()
Get a resource list.
The req struct should have been created using Kubereq.new/2.
Examples
iex> Kubereq.list(req, "api/v1/namespaces/:namespace/configmaps", "default", [])
{:ok, %Req.Response{status: 200, body: %{...}}}Options
:field_selectors- A list of field selectors. SeeKubereq.Step.FieldSelectorfor more infos.:label_selectors- A list of field selectors. SeeKubereq.Step.LabelSelectorfor more infos.
@spec merge_patch( Req.Request.t(), merge_patch :: String.t(), namespace :: namespace(), name :: String.t() ) :: response()
Patches the resource namein namespace using the given merge_patch.
The req struct should have been created using Kubereq.new/2.
Examples
iex> Kubereq.merge_patch(req, %{...}, "default", "foo")
{:ok, %Req.Response{...}
@spec new(kubeconfig :: Kubereq.Kubeconfig.t()) :: Req.Request.t()
Prepares a Req.Request struct for making HTTP requests to a Kubernetes
cluster. The kubeconfig is the Kubernetes configuration in the form of a
%Kubereq.Kubeconfig{} struct and should contain all informations required to connect
to the Kubernetes cluster.
Examples
iex> kubeconfig = Kubereq.Kubeconfig.load(Kubereq.Kubeconfig.Default)
...> Kubereq.new(kubeconfig)
%Request.Req{...}
@spec new(kubeconfig :: Kubereq.Kubeconfig.t(), resource_path :: binary()) :: Req.Request.t()
Prepares a Req.Request struct for a specific resource on a specific
Kubernetes cluster. The kubeconfig is the Kubernetes configuration in the
form of a %Kubereq.Kubeconfig{} struct and should contain all informations required to
connect to the Kubernetes cluster.
The parameter resource_path should be the path on which the Kubernetes API
Server listens for requests for the targeted resource kind. It should
contain placeholders for :namespace and :name.
The :namespace and :name are provided through the :path_params option
built into Req when making the request.
Examples
Prepare a Req.Request for ConfigMaps:
iex> kubeconfig = Kubereq.Kubeconfig.load(Kubereq.Kubeconfig.Default)
...> Kubereq.new(kubeconfig, "api/v1/namespaces/:namespace/configmaps/:name")
%Request.Req{...}
@spec update(Req.Request.t(), resource :: map()) :: response()
Updates the given resource.
The req struct should have been created using Kubereq.new/2.
Examples
iex> Kubereq.update(req, %{...})
{:ok, %Req.Response{...}
@spec wait_until( Req.Request.t(), namespace :: namespace(), name :: String.t(), callback :: wait_until_callback(), timeout :: non_neg_integer() ) :: wait_until_response()
GET a resource and wait until the given callback returns true or the given
timeout (ms) has expired.
The req struct should have been created using Kubereq.new/2.
Options
timeout- Timeout in ms after function terminates with{:error, :timeout}
@spec watch( Req.Request.t(), namespace :: namespace(), opts :: keyword() ) :: watch_response()
Watch events of all resources in namespace.
The req struct should have been created using Kubereq.new/2.
Examples
iex> Kubereq.watch(req, "default", [])
{:ok, #Function<60.48886818/2 in Stream.transform/3>}In order to watch events in all namespaces, pass nil as namespace:
iex> Kubereq.watch(req, nil, [])
{:ok, #Function<60.48886818/2 in Stream.transform/3>}Options
:resource_version- If given, starts to stream from the givenresourceVersionof the resource list. Otherwise starts streaming from HEAD.:stream_to- If set to apid, streams events to the given pid. If set to{pid, ref}, the messages are in the form{ref, event}.:field_selectors- A list of field selectors. SeeKubereq.Step.FieldSelectorfor more infos.:label_selectors- A list of field selectors. SeeKubereq.Step.LabelSelectorfor more infos.
@spec watch_single( Req.Request.t(), namespace :: namespace(), name :: String.t(), opts :: keyword() ) :: watch_response()
Watch events of a single resources namein namespace.
The req struct should have been created using Kubereq.new/2.
Examples
iex> Kubereq.watch_single(req, "default", [])
{:ok, #Function<60.48886818/2 in Stream.transform/3>}In order to watch events in all namespaces, pass nil as namespace:
iex> Kubereq.watch_single(req, nil, [])
{:ok, #Function<60.48886818/2 in Stream.transform/3>}Options
:stream_to- If set to apid, streams events to the given pid. If set to{pid, ref}, the messages are in the form{ref, event}