k8s v0.5.0-rc.2 K8s.Operation
Encapsulates Kubernetes REST API operations.
Link to this section Summary
Types
K8s.Operation
name. May be an atom, string, or tuple of {resource, subresource}
.
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 URL
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.
Converts a K8s.Operation
into a URL path.
Link to this section Types
K8s.Operation
name. May be an atom, string, or tuple of {resource, subresource}
.
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 URL
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"]
}
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
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)
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
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"
}
to_path(operation)
to_path(K8s.Operation.t()) :: {:ok, String.t()} | {:error, :missing_required_param, [atom()]}
Converts a K8s.Operation
into a URL path.