View Source K8s.Operation (k8s v1.1.1)

Encapsulates Kubernetes REST API operations.

Link to this section Summary

Types

K8s.Operation name. May be an atom, string, or tuple of {resource, subresource}.

t()
  • api_version - API groupVersion, AKA apiVersion
  • name - The name of the REST operation (Kubernets kind/resource/subresource). This is not always the same as the kind key in the data field. e.g: deployments when POSTing, GETting a deployment.
  • data - HTTP request body to submit when applicable. (POST, PUT, PATCH, etc)
  • method - HTTP Method
  • verb - Kubernetes REST API verb (deletecollection, update, create, watch, etc)
  • path_params - Parameters to interpolate into the Kubernetes REST URL
  • query_params - Query parameters. Merged w/ params provided to any K8s.Client.Runner. K8s.Client.Runner options win.

name would be deployments in the case of a deployment, but may be deployments/status or deployments/scale for Status and Scale subresources.

Functions

Builds an Operation given a verb and a k8s resource.

Builds an Operation given an verb and a k8s resource info.

Gets a K8s.Selector on the operation.

Get a query param of an operation

Add a query param to an operation

Converts a K8s.Operation into a URL path.

Link to this section Types

Specs

name_t() :: binary() | atom() | {binary(), binary()}

K8s.Operation name. May be an atom, string, or tuple of {resource, subresource}.

Specs

t() :: %K8s.Operation{
  api_version: binary(),
  data: map() | nil,
  method: atom(),
  name: name_t(),
  path_params: keyword(),
  query_params: keyword(),
  verb: atom()
}
  • api_version - API groupVersion, AKA apiVersion
  • name - The name of the REST operation (Kubernets kind/resource/subresource). This is not always the same as the kind key in the data field. e.g: deployments when POSTing, GETting a deployment.
  • data - HTTP request body to submit when applicable. (POST, PUT, PATCH, etc)
  • method - HTTP Method
  • verb - Kubernetes REST API verb (deletecollection, update, create, watch, etc)
  • path_params - Parameters to interpolate into the Kubernetes REST URL
  • query_params - Query parameters. Merged w/ params provided to any K8s.Client.Runner. K8s.Client.Runner options win.

name would be deployments in the case of a deployment, but may be deployments/status or deployments/scale for Status and Scale subresources.

name-and-data-field-examples

name and data field examples

The following example would update the nginx deployment's Scale. Note the deployments/scale operation will have a Scale data payload:

%K8s.Operation{
  method: :put,
  verb: :update,
  api_version: "v1", # api version of the "Scale" kind
  name: "deployments/scale",
  data: %{"apiVersion" => "v1", "kind" => "Scale"}, # `data` is of kind "Scale"
  path_params: [name: "nginx", namespace: "default"]
}

The following example would update the nginx deployment's Status. Note the deployments/status operation will have a Deployment data payload:

%K8s.Operation{
  method: :put,
  verb: :update,
  api_version: "apps/v1", # api version of the "Deployment" kind
  name: "deployments/status",
  data: %{"apiVersion" => "apps/v1", "kind" => "Deployment"}, # `data` is of kind "Deployment"
  path_params: [name: "nginx", namespace: "default"]
}

Link to this section Functions

Link to this function

build(verb, resource, opts \\ [])

View Source

Specs

build(atom(), map(), keyword()) :: t()

Builds an Operation given a verb and a k8s resource.

examples

Examples

iex> deploy = %{"apiVersion" => "apps/v1", "kind" => "Deployment", "metadata" => %{"namespace" => "default", "name" => "nginx"}}
...> K8s.Operation.build(:update, deploy)
%K8s.Operation{
  method: :put,
  verb: :update,
  data: %{"apiVersion" => "apps/v1", "kind" => "Deployment", "metadata" => %{"namespace" => "default", "name" => "nginx"}},
  path_params: [namespace: "default", name: "nginx"],
  api_version: "apps/v1",
  name: "Deployment"
}
Link to this function

build(verb, api_version, name_or_kind, path_params, data \\ nil, opts \\ [])

View Source

Specs

build(atom(), binary(), name_t(), keyword(), map() | nil, keyword()) :: t()

Builds an Operation given an verb and a k8s resource info.

Note: The name here may be a Kind and not a REST resource name in the event that the operation was built using a map. Use K8s.Discovery.ResourceFinder.resource_name_for_kind/3 to get the correct REST resource name, given a kind.

examples

Examples

Building a GET deployment operation:

iex> K8s.Operation.build(:get, "apps/v1", :deployment, [namespace: "default", name: "nginx"])
%K8s.Operation{
  method: :get,
  verb: :get,
  data: nil,
  path_params: [namespace: "default", name: "nginx"],
  api_version: "apps/v1",
  name: :deployment
}

Building a GET deployments/status operation:

iex> K8s.Operation.build(:get, "apps/v1", "deployments/status", [namespace: "default", name: "nginx"])
%K8s.Operation{
  method: :get,
  verb: :get,
  data: nil,
  path_params: [namespace: "default", name: "nginx"],
  api_version: "apps/v1",
  name: "deployments/status"
}
Link to this function

get_label_selector(operation)

View Source

Specs

get_label_selector(t()) :: K8s.Selector.t()

Gets a K8s.Selector on the operation.

examples

Examples

iex> operation = %K8s.Operation{query_params: [labelSelector: K8s.Selector.label({"component", "redis"})]}
...> K8s.Operation.get_label_selector(operation)
%K8s.Selector{
  match_expressions: [],
  match_labels: %{"component" => "redis"}
}
Link to this function

get_query_param(operation, key)

View Source

Specs

get_query_param(t(), atom()) :: any()

Get a query param of an operation

examples

Examples

Using a keyword list of params:

iex> operation = %K8s.Operation{query_params: [foo: "bar"]}
...> K8s.Operation.get_query_param(operation, :foo)
"bar"
Link to this function

put_label_selector(op, selector)

View Source

Specs

put_label_selector(t(), K8s.Selector.t()) :: t()

Puts a K8s.Selector on the operation.

examples

Examples

iex> operation = %K8s.Operation{}
...> selector = K8s.Selector.label({"component", "redis"})
...> K8s.Operation.put_label_selector(operation, selector)
%K8s.Operation{
  query_params: [
    labelSelector: %K8s.Selector{
      match_expressions: [],
      match_labels: %{"component" => "redis"}
    }
  ]
}
Link to this function

put_query_param(op, key, value)

View Source

Specs

put_query_param(t(), atom(), String.t() | K8s.Selector.t()) :: t()

Add a query param to an operation

examples

Examples

Using a keyword list of params:

iex> operation = %K8s.Operation{}
...> K8s.Operation.put_query_param(operation, :foo, "bar")
%K8s.Operation{query_params: [foo: "bar"]}

Specs

to_path(t()) :: {:ok, String.t()} | {:error, K8s.Operation.Error.t()}

Converts a K8s.Operation into a URL path.