View Source K8s.Operation (k8s v2.6.1)
Encapsulates Kubernetes REST API operations.
Summary
Types
K8s.Operation
name. May be an atom, string, or tuple of {resource, subresource}
.
Acceptable patch types
api_version
- APIgroupVersion
, AKAapiVersion
name
- The name of the REST operation (Kubernets kind/resource/subresource). This is not always the same as thekind
key in thedata
field. e.g:deployments
when POSTing, GETting a deployment.data
- HTTP request body to submit when applicable. (POST, PUT, PATCH, etc)method
- HTTP Methodverb
- Kubernetes REST API verb (deletecollection
,update
,create
,watch
, etc)path_params
- Parameters to interpolate into the Kubernetes REST URLquery_params
- Query parameters. Merged w/ params provided to anyK8s.Client.Runner
.K8s.Client.Runner
options win.header_params
- Header parameters.
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.
Get a query param of an operation
Gets a K8s.Selector
on the operation.
Set the connection object on the operation
Add a query param to an operation
Puts a K8s.Selector
on the operation.
Converts a K8s.Operation
into a URL path.
Types
K8s.Operation
name. May be an atom, string, or tuple of {resource, subresource}
.
@type patch_type() :: :strategic_merge | :merge | :json_merge | :apply
Acceptable patch types
@type t() :: %K8s.Operation{ api_version: binary(), conn: K8s.Conn.t() | nil, data: map() | nil, header_params: keyword(), method: atom(), name: name_t(), path_params: keyword(), query_params: keyword(), verb: atom() }
api_version
- APIgroupVersion
, AKAapiVersion
name
- The name of the REST operation (Kubernets kind/resource/subresource). This is not always the same as thekind
key in thedata
field. e.g:deployments
when POSTing, GETting a deployment.data
- HTTP request body to submit when applicable. (POST, PUT, PATCH, etc)method
- HTTP Methodverb
- Kubernetes REST API verb (deletecollection
,update
,create
,watch
, etc)path_params
- Parameters to interpolate into the Kubernetes REST URLquery_params
- Query parameters. Merged w/ params provided to anyK8s.Client.Runner
.K8s.Client.Runner
options win.header_params
- Header parameters.
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
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"],
header_params: ["Content-Type": "application/json"]
}
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"],
header_params: ["Content-Type": "application/json"]
}
Functions
Builds an Operation
given a verb and a k8s resource.
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"
}
build(verb, api_version, name_or_kind, path_params, data \\ nil, opts \\ [])
View SourceBuilds 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
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"
}
@spec get_label_selector(t()) :: K8s.Selector.t()
Get a query param of an operation
Examples
Using a keyword
list of params:
iex> operation = %K8s.Operation{query_params: [foo: "bar"]}
...> K8s.Operation.get_query_param(operation, :foo)
"bar"
@spec get_selector(t()) :: K8s.Selector.t()
Gets a K8s.Selector
on the operation.
Examples
iex> operation = %K8s.Operation{query_params: [labelSelector: K8s.Selector.label({"component", "redis"})]}
...> K8s.Operation.get_selector(operation)
%K8s.Selector{
match_expressions: [],
match_labels: %{"component" => {"=", "redis"}}
}
@spec put_conn(t(), K8s.Conn.t()) :: t()
Set the connection object on the operation
Examples
iex> operation = %K8s.Operation{query_params: [foo: "bar"]}
...> conn = %K8s.Conn{}
...> operation = K8s.Operation.put_conn(operation, conn)
...> match?(%K8s.Operation{conn: %K8s.Conn{}}, operation)
true
@spec put_label_selector(t(), K8s.Selector.t()) :: t()
@spec put_query_param(t(), list() | K8s.Selector.t()) :: t()
@spec put_query_param(t(), any(), String.t() | K8s.Selector.t()) :: t()
Add a query param to an operation
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"]}
@spec put_selector(t(), K8s.Selector.t()) :: t()
Puts a K8s.Selector
on the operation.
Examples
iex> operation = %K8s.Operation{}
...> selector = K8s.Selector.label({"component", "redis"})
...> K8s.Operation.put_selector(operation, selector)
%K8s.Operation{
query_params: [
labelSelector: %K8s.Selector{
match_expressions: [],
match_labels: %{"component" => {"=", "redis"}}
}
]
}
@spec to_path(t()) :: {:ok, String.t()} | {:error, K8s.Operation.Error.t()}
Converts a K8s.Operation
into a URL path.