Class: CDK8sPlus25::K8S::ValidatingWebhook

Inherits:
Jsii::Struct
  • Object
show all
Defined in:
k8_s/validating_webhook.rb

Overview

ValidatingWebhook describes an admission webhook and the resources and operations it applies to.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(admission_review_versions:, client_config:, name:, side_effects:, failure_policy: nil, match_policy: nil, namespace_selector: nil, object_selector: nil, rules: nil, timeout_seconds: nil) ⇒ ValidatingWebhook

Returns a new instance of ValidatingWebhook.

Parameters:

  • admission_review_versions (Array<String>)

    AdmissionReviewVersions is an ordered list of preferred AdmissionReview versions the Webhook expects.

  • client_config (CDK8sPlus25::K8S::WebhookClientConfig)

    ClientConfig defines how to communicate with the hook.

  • name (String)

    The name of the admission webhook.

  • side_effects (String)

    SideEffects states whether this webhook has side effects.

  • failure_policy (String, nil) (defaults to: nil)

    FailurePolicy defines how unrecognized errors from the admission endpoint are handled - allowed values are Ignore or Fail.

  • match_policy (String, nil) (defaults to: nil)

    matchPolicy defines how the "rules" list is used to match incoming requests. Allowed values are "Exact" or "Equivalent".

  • namespace_selector (CDK8sPlus25::K8S::LabelSelector, nil) (defaults to: nil)

    NamespaceSelector decides whether to run the webhook on an object based on whether the namespace for that object matches the selector.

  • object_selector (CDK8sPlus25::K8S::LabelSelector, nil) (defaults to: nil)

    ObjectSelector decides whether to run the webhook based on if the object has matching labels.

  • rules (Array<CDK8sPlus25::K8S::RuleWithOperations>, nil) (defaults to: nil)

    Rules describes what operations on what resources/subresources the webhook cares about.

  • timeout_seconds (Numeric, nil) (defaults to: nil)

    TimeoutSeconds specifies the timeout for this webhook.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'k8_s/validating_webhook.rb', line 17

def initialize(admission_review_versions:, client_config:, name:, side_effects:, failure_policy: nil, match_policy: nil, namespace_selector: nil, object_selector: nil, rules: nil, timeout_seconds: nil)
  @admission_review_versions = admission_review_versions
  Jsii::Type.check_type(@admission_review_versions, "eyJjb2xsZWN0aW9uIjp7ImVsZW1lbnR0eXBlIjp7InByaW1pdGl2ZSI6InN0cmluZyJ9LCJraW5kIjoiYXJyYXkifX0=", "admissionReviewVersions")
  @client_config = client_config.is_a?(Hash) ? ::CDK8sPlus25::K8S::WebhookClientConfig.new(**client_config.transform_keys(&:to_sym)) : client_config
  Jsii::Type.check_type(@client_config, "eyJmcW4iOiJjZGs4cy1wbHVzLTI1Lms4cy5XZWJob29rQ2xpZW50Q29uZmlnIn0=", "clientConfig")
  @name = name
  Jsii::Type.check_type(@name, "eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==", "name")
  @side_effects = side_effects
  Jsii::Type.check_type(@side_effects, "eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==", "sideEffects")
  @failure_policy = failure_policy
  Jsii::Type.check_type(@failure_policy, "eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==", "failurePolicy") unless @failure_policy.nil?
  @match_policy = match_policy
  Jsii::Type.check_type(@match_policy, "eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==", "matchPolicy") unless @match_policy.nil?
  @namespace_selector = namespace_selector.is_a?(Hash) ? ::CDK8sPlus25::K8S::LabelSelector.new(**namespace_selector.transform_keys(&:to_sym)) : namespace_selector
  Jsii::Type.check_type(@namespace_selector, "eyJmcW4iOiJjZGs4cy1wbHVzLTI1Lms4cy5MYWJlbFNlbGVjdG9yIn0=", "namespaceSelector") unless @namespace_selector.nil?
  @object_selector = object_selector.is_a?(Hash) ? ::CDK8sPlus25::K8S::LabelSelector.new(**object_selector.transform_keys(&:to_sym)) : object_selector
  Jsii::Type.check_type(@object_selector, "eyJmcW4iOiJjZGs4cy1wbHVzLTI1Lms4cy5MYWJlbFNlbGVjdG9yIn0=", "objectSelector") unless @object_selector.nil?
  @rules = rules.is_a?(Array) ? rules.map { |jsii_v0| jsii_v0.is_a?(Hash) ? ::CDK8sPlus25::K8S::RuleWithOperations.new(**jsii_v0.transform_keys(&:to_sym)) : jsii_v0 } : rules
  Jsii::Type.check_type(@rules, "eyJjb2xsZWN0aW9uIjp7ImVsZW1lbnR0eXBlIjp7ImZxbiI6ImNkazhzLXBsdXMtMjUuazhzLlJ1bGVXaXRoT3BlcmF0aW9ucyJ9LCJraW5kIjoiYXJyYXkifX0=", "rules") unless @rules.nil?
  @timeout_seconds = timeout_seconds
  Jsii::Type.check_type(@timeout_seconds, "eyJwcmltaXRpdmUiOiJudW1iZXIifQ==", "timeoutSeconds") unless @timeout_seconds.nil?
end

Instance Attribute Details

#admission_review_versionsArray<String> (readonly)

AdmissionReviewVersions is an ordered list of preferred AdmissionReview versions the Webhook expects.

API server will try to use first version in the list which it supports. If none of the versions specified in this list supported by API server, validation will fail for this object. If a persisted webhook configuration specifies allowed versions and does not include any versions known to the API Server, calls to the webhook will fail and be subject to the failure policy.

Returns:

  • (Array<String>)


45
46
47
# File 'k8_s/validating_webhook.rb', line 45

def admission_review_versions
  @admission_review_versions
end

#client_configCDK8sPlus25::K8S::WebhookClientConfig (readonly)

ClientConfig defines how to communicate with the hook.

Required



51
52
53
# File 'k8_s/validating_webhook.rb', line 51

def client_config
  @client_config
end

#failure_policyString? (readonly)

Note:

Default: Fail.

FailurePolicy defines how unrecognized errors from the admission endpoint are handled - allowed values are Ignore or Fail.

Defaults to Fail.

Returns:

  • (String, nil)


70
71
72
# File 'k8_s/validating_webhook.rb', line 70

def failure_policy
  @failure_policy
end

#match_policyString? (readonly)

Note:

Default: Equivalent"

matchPolicy defines how the "rules" list is used to match incoming requests. Allowed values are "Exact" or "Equivalent".

  • Exact: match a request only if it exactly matches a specified rule. For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, but "rules" only included apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"], a request to apps/v1beta1 or extensions/v1beta1 would not be sent to the webhook.
  • Equivalent: match a request if modifies a resource listed in rules, even via another API group or version. For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, and "rules" only included apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"], a request to apps/v1beta1 or extensions/v1beta1 would be converted to apps/v1 and sent to the webhook.

Defaults to "Equivalent"

Returns:

  • (String, nil)


80
81
82
# File 'k8_s/validating_webhook.rb', line 80

def match_policy
  @match_policy
end

#nameString (readonly)

The name of the admission webhook.

Name should be fully qualified, e.g., imagepolicy.kubernetes.io, where "imagepolicy" is the name of the webhook, and kubernetes.io is the name of the organization. Required.

Returns:

  • (String)


57
58
59
# File 'k8_s/validating_webhook.rb', line 57

def name
  @name
end

#namespace_selectorCDK8sPlus25::K8S::LabelSelector? (readonly)

Note:

Default: the empty LabelSelector, which matches everything.

NamespaceSelector decides whether to run the webhook on an object based on whether the namespace for that object matches the selector.

If the object itself is a namespace, the matching is performed on object.metadata.labels. If the object is another cluster scoped resource, it never skips the webhook.

For example, to run the webhook on any objects whose namespace is not associated with "runlevel" of "0" or "1"; you will set the selector as follows: "namespaceSelector": { "matchExpressions": [ { "key": "runlevel", "operator": "NotIn", "values": [ "0", "1" ] } ] }

If instead you want to only run the webhook on any objects whose namespace is associated with the "environment" of "prod" or "staging"; you will set the selector as follows: "namespaceSelector": { "matchExpressions": [ { "key": "environment", "operator": "In", "values": [ "prod", "staging" ] } ] }

See https://kubernetes.io/docs/concepts/overview/working-with-objects/labels for more examples of label selectors.

Default to the empty LabelSelector, which matches everything.



117
118
119
# File 'k8_s/validating_webhook.rb', line 117

def namespace_selector
  @namespace_selector
end

#object_selectorCDK8sPlus25::K8S::LabelSelector? (readonly)

Note:

Default: the empty LabelSelector, which matches everything.

ObjectSelector decides whether to run the webhook based on if the object has matching labels.

objectSelector is evaluated against both the oldObject and newObject that would be sent to the webhook, and is considered to match if either object matches the selector. A null object (oldObject in the case of create, or newObject in the case of delete) or an object that cannot have labels (like a DeploymentRollback or a PodProxyOptions object) is not considered to match. Use the object selector only if the webhook is opt-in, because end users may skip the admission webhook by setting the labels. Default to the empty LabelSelector, which matches everything.



124
125
126
# File 'k8_s/validating_webhook.rb', line 124

def object_selector
  @object_selector
end

#rulesArray<CDK8sPlus25::K8S::RuleWithOperations>? (readonly)

Rules describes what operations on what resources/subresources the webhook cares about.

The webhook cares about an operation if it matches any Rule. However, in order to prevent ValidatingAdmissionWebhooks and MutatingAdmissionWebhooks from putting the cluster in a state which cannot be recovered from without completely disabling the plugin, ValidatingAdmissionWebhooks and MutatingAdmissionWebhooks are never called on admission requests for ValidatingWebhookConfiguration and MutatingWebhookConfiguration objects.

Returns:



130
131
132
# File 'k8_s/validating_webhook.rb', line 130

def rules
  @rules
end

#side_effectsString (readonly)

SideEffects states whether this webhook has side effects.

Acceptable values are: None, NoneOnDryRun (webhooks created via v1beta1 may also specify Some or Unknown). Webhooks with side effects MUST implement a reconciliation system, since a request may be rejected by a future step in the admission chain and the side effects therefore need to be undone. Requests with the dryRun attribute will be auto-rejected if they match a webhook with sideEffects == Unknown or Some.

Returns:

  • (String)


63
64
65
# File 'k8_s/validating_webhook.rb', line 63

def side_effects
  @side_effects
end

#timeout_secondsNumeric? (readonly)

Note:

Default: 10 seconds.

TimeoutSeconds specifies the timeout for this webhook.

After the timeout passes, the webhook call will be ignored or the API call will fail based on the failure policy. The timeout value must be between 1 and 30 seconds. Default to 10 seconds.

Returns:

  • (Numeric, nil)


137
138
139
# File 'k8_s/validating_webhook.rb', line 137

def timeout_seconds
  @timeout_seconds
end

Class Method Details

.jsii_propertiesObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'k8_s/validating_webhook.rb', line 139

def self.jsii_properties
  {
    :admission_review_versions => "admissionReviewVersions",
    :client_config => "clientConfig",
    :name => "name",
    :side_effects => "sideEffects",
    :failure_policy => "failurePolicy",
    :match_policy => "matchPolicy",
    :namespace_selector => "namespaceSelector",
    :object_selector => "objectSelector",
    :rules => "rules",
    :timeout_seconds => "timeoutSeconds",
  }
end

Instance Method Details

#to_jsiiObject



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'k8_s/validating_webhook.rb', line 154

def to_jsii
  result = {}
  result.merge!({
    "admissionReviewVersions" => @admission_review_versions,
    "clientConfig" => @client_config,
    "name" => @name,
    "sideEffects" => @side_effects,
    "failurePolicy" => @failure_policy,
    "matchPolicy" => @match_policy,
    "namespaceSelector" => @namespace_selector,
    "objectSelector" => @object_selector,
    "rules" => @rules,
    "timeoutSeconds" => @timeout_seconds,
  })
  result.compact
end