View Source K8sWebhoox.AdmissionControl.AdmissionReview (k8s_webhoox v0.1.0)
This module defines a struct which is used as token in the Pluggable
pipeline handling an admission request. See K8sWebhoox.Plug
for more
information on how to set up the request handler pipeline.
This module also defines a set of useful helpers when processing an admission request.
Link to this section Summary
Functions
Adds a warning to the admission review's response.
Responds by allowing the operation
Checks the given field's value - if defined - against a list of allowed values. If the field is not defined, the request is considered valid and no error is returned. Use the CRD to define required fields.
Defines a field as being immutable. Denies the request if the field was mutated.
Responds by denying the operation
Responds by denying the operation, returning response code and message
Link to this section Functions
@spec add_warning(K8sWebhoox.Conn.t(), binary()) :: K8sWebhoox.Conn.t()
Adds a warning to the admission review's response.
examples
Examples
iex> conn = %K8sWebhoox.Conn{request: %{}, response: %{}, api_version: "", kind: ""}
...> K8sWebhoox.AdmissionControl.AdmissionReview.add_warning(conn, "warning")
%K8sWebhoox.Conn{request: %{}, response: %{"warnings" => ["warning"]}, api_version: "", kind: ""}
iex> conn = %K8sWebhoox.Conn{request: %{}, response: %{"warnings" => ["existing_warning"]}, api_version: "", kind: ""}
...> K8sWebhoox.AdmissionControl.AdmissionReview.add_warning(conn, "new_warning")
%K8sWebhoox.Conn{request: %{}, response: %{"warnings" => ["new_warning", "existing_warning"]}, api_version: "", kind: ""}
@spec allow(K8sWebhoox.Conn.t()) :: K8sWebhoox.Conn.t()
Responds by allowing the operation
examples
Examples
iex> conn = %K8sWebhoox.Conn{request: %{}, response: %{}, api_version: "", kind: ""}
...> K8sWebhoox.AdmissionControl.AdmissionReview.allow(conn)
%K8sWebhoox.Conn{request: %{}, response: %{"allowed" => true}, api_version: "", kind: ""}
@spec check_allowed_values(K8sWebhoox.Conn.t(), list(), list()) :: K8sWebhoox.Conn.t()
Checks the given field's value - if defined - against a list of allowed values. If the field is not defined, the request is considered valid and no error is returned. Use the CRD to define required fields.
examples
Examples
iex> conn = %K8sWebhoox.Conn{request: %{"object" => %{"metadata" => %{"annotations" => %{"some/annotation" => "bar"}}, "spec" => %{}}, "oldObject" => %{"spec" => %{}}}, response: %{}, api_version: "", kind: ""}
...> K8sWebhoox.AdmissionControl.AdmissionReview.check_allowed_values(conn, ~w(metadata annotations some/annotation), ["foo", "bar"])
%K8sWebhoox.Conn{request: %{"object" => %{"metadata" => %{"annotations" => %{"some/annotation" => "bar"}}, "spec" => %{}}, "oldObject" => %{"spec" => %{}}}, response: %{}, api_version: "", kind: ""}
iex> conn = %K8sWebhoox.Conn{request: %{"object" => %{"metadata" => %{}, "spec" => %{}}, "oldObject" => %{"spec" => %{}}}, response: %{}, api_version: "", kind: ""}
...> K8sWebhoox.AdmissionControl.AdmissionReview.check_allowed_values(conn, ~w(metadata annotations some/annotation), ["foo", "bar"])
%K8sWebhoox.Conn{request: %{"object" => %{"metadata" => %{}, "spec" => %{}}, "oldObject" => %{"spec" => %{}}}, response: %{}, api_version: "", kind: ""}
iex> conn = %K8sWebhoox.Conn{request: %{"object" => %{"metadata" => %{"annotations" => %{"some/annotation" => "other"}}, "spec" => %{}}, "oldObject" => %{"spec" => %{}}}, response: %{}, api_version: "", kind: ""}
...> K8sWebhoox.AdmissionControl.AdmissionReview.check_allowed_values(conn, ~w(metadata annotations some/annotation), ["foo", "bar"])
%K8sWebhoox.Conn{request: %{"object" => %{"metadata" => %{"annotations" => %{"some/annotation" => "other"}}, "spec" => %{}}, "oldObject" => %{"spec" => %{}}}, response: %{"allowed" => false, "status" => %{"code" => 400, "message" => ~S(The field .metadata.annotations.some/annotation must contain one of the values in ["foo", "bar"] but it's currently set to "other".)}}, api_version: "", kind: ""}
@spec check_immutable(K8sWebhoox.Conn.t(), list()) :: K8sWebhoox.Conn.t()
Defines a field as being immutable. Denies the request if the field was mutated.
examples
Examples
iex> conn = %K8sWebhoox.Conn{request: %{"object" => %{"spec" => %{"immutable" => "value"}}, "oldObject" => %{"spec" => %{"immutable" => "value"}}}, response: %{}, api_version: "", kind: ""}
...> K8sWebhoox.AdmissionControl.AdmissionReview.check_immutable(conn, ["spec", "immutable"])
%K8sWebhoox.Conn{request: %{"object" => %{"spec" => %{"immutable" => "value"}}, "oldObject" => %{"spec" => %{"immutable" => "value"}}}, response: %{}, api_version: "", kind: ""}
iex> conn = %K8sWebhoox.Conn{request: %{"object" => %{"spec" => %{"immutable" => "new_value"}}, "oldObject" => %{"spec" => %{"immutable" => "value"}}}, response: %{}, api_version: "", kind: ""}
...> K8sWebhoox.AdmissionControl.AdmissionReview.check_immutable(conn, ["spec", "immutable"])
%K8sWebhoox.Conn{request: %{"object" => %{"spec" => %{"immutable" => "new_value"}}, "oldObject" => %{"spec" => %{"immutable" => "value"}}}, response: %{"allowed" => false, "status" => %{"code" => 400, "message" => "The field .spec.immutable is immutable."}}, api_version: "", kind: ""}
@spec deny(K8sWebhoox.Conn.t()) :: K8sWebhoox.Conn.t()
Responds by denying the operation
examples
Examples
iex> conn = %K8sWebhoox.Conn{request: %{}, response: %{}, api_version: "", kind: ""}
...> K8sWebhoox.AdmissionControl.AdmissionReview.deny(conn)
%K8sWebhoox.Conn{request: %{}, response: %{"allowed" => false}, api_version: "", kind: ""}
@spec deny(K8sWebhoox.Conn.t(), integer(), binary()) :: K8sWebhoox.Conn.t()
Responds by denying the operation, returning response code and message
examples
Examples
iex> conn = %K8sWebhoox.Conn{request: %{}, response: %{}, api_version: "", kind: ""}
...> K8sWebhoox.AdmissionControl.AdmissionReview.deny(conn, 403, "foo")
%K8sWebhoox.Conn{request: %{}, response: %{"allowed" => false, "status" => %{"code" => 403, "message" => "foo"}}, api_version: "", kind: ""}
iex> K8sWebhoox.AdmissionControl.AdmissionReview.deny(%K8sWebhoox.Conn{request: %{}, response: %{}, api_version: "", kind: ""}, "foo")
%K8sWebhoox.Conn{request: %{}, response: %{"allowed" => false, "status" => %{"code" => 400, "message" => "foo"}}, api_version: "", kind: ""}