blob: 49d94ec0eb758d7fa23d3ef73f8ae2f13c656497 [file] [log] [blame]
sslobodrd046be82019-01-16 10:02:22 -05001/*
2Copyright 2017 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package v1beta1
18
19import (
20 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21)
22
23// Rule is a tuple of APIGroups, APIVersion, and Resources.It is recommended
24// to make sure that all the tuple expansions are valid.
25type Rule struct {
26 // APIGroups is the API groups the resources belong to. '*' is all groups.
27 // If '*' is present, the length of the slice must be one.
28 // Required.
29 APIGroups []string `json:"apiGroups,omitempty" protobuf:"bytes,1,rep,name=apiGroups"`
30
31 // APIVersions is the API versions the resources belong to. '*' is all versions.
32 // If '*' is present, the length of the slice must be one.
33 // Required.
34 APIVersions []string `json:"apiVersions,omitempty" protobuf:"bytes,2,rep,name=apiVersions"`
35
36 // Resources is a list of resources this rule applies to.
37 //
38 // For example:
39 // 'pods' means pods.
40 // 'pods/log' means the log subresource of pods.
41 // '*' means all resources, but not subresources.
42 // 'pods/*' means all subresources of pods.
43 // '*/scale' means all scale subresources.
44 // '*/*' means all resources and their subresources.
45 //
46 // If wildcard is present, the validation rule will ensure resources do not
47 // overlap with each other.
48 //
49 // Depending on the enclosing object, subresources might not be allowed.
50 // Required.
51 Resources []string `json:"resources,omitempty" protobuf:"bytes,3,rep,name=resources"`
52}
53
54type FailurePolicyType string
55
56const (
57 // Ignore means that an error calling the webhook is ignored.
58 Ignore FailurePolicyType = "Ignore"
59 // Fail means that an error calling the webhook causes the admission to fail.
60 Fail FailurePolicyType = "Fail"
61)
62
63type SideEffectClass string
64
65const (
66 // SideEffectClassUnknown means that no information is known about the side effects of calling the webhook.
67 // If a request with the dry-run attribute would trigger a call to this webhook, the request will instead fail.
68 SideEffectClassUnknown SideEffectClass = "Unknown"
69 // SideEffectClassNone means that calling the webhook will have no side effects.
70 SideEffectClassNone SideEffectClass = "None"
71 // SideEffectClassSome means that calling the webhook will possibly have side effects.
72 // If a request with the dry-run attribute would trigger a call to this webhook, the request will instead fail.
73 SideEffectClassSome SideEffectClass = "Some"
74 // SideEffectClassNoneOnDryRun means that calling the webhook will possibly have side effects, but if the
75 // request being reviewed has the dry-run attribute, the side effects will be suppressed.
76 SideEffectClassNoneOnDryRun SideEffectClass = "NoneOnDryRun"
77)
78
79// +genclient
80// +genclient:nonNamespaced
81// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
82
83// ValidatingWebhookConfiguration describes the configuration of and admission webhook that accept or reject and object without changing it.
84type ValidatingWebhookConfiguration struct {
85 metav1.TypeMeta `json:",inline"`
86 // Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata.
87 // +optional
88 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
89 // Webhooks is a list of webhooks and the affected resources and operations.
90 // +optional
91 // +patchMergeKey=name
92 // +patchStrategy=merge
93 Webhooks []Webhook `json:"webhooks,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,2,rep,name=Webhooks"`
94}
95
96// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
97
98// ValidatingWebhookConfigurationList is a list of ValidatingWebhookConfiguration.
99type ValidatingWebhookConfigurationList struct {
100 metav1.TypeMeta `json:",inline"`
101 // Standard list metadata.
102 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
103 // +optional
104 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
105 // List of ValidatingWebhookConfiguration.
106 Items []ValidatingWebhookConfiguration `json:"items" protobuf:"bytes,2,rep,name=items"`
107}
108
109// +genclient
110// +genclient:nonNamespaced
111// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
112
113// MutatingWebhookConfiguration describes the configuration of and admission webhook that accept or reject and may change the object.
114type MutatingWebhookConfiguration struct {
115 metav1.TypeMeta `json:",inline"`
116 // Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata.
117 // +optional
118 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
119 // Webhooks is a list of webhooks and the affected resources and operations.
120 // +optional
121 // +patchMergeKey=name
122 // +patchStrategy=merge
123 Webhooks []Webhook `json:"webhooks,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,2,rep,name=Webhooks"`
124}
125
126// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
127
128// MutatingWebhookConfigurationList is a list of MutatingWebhookConfiguration.
129type MutatingWebhookConfigurationList struct {
130 metav1.TypeMeta `json:",inline"`
131 // Standard list metadata.
132 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
133 // +optional
134 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
135 // List of MutatingWebhookConfiguration.
136 Items []MutatingWebhookConfiguration `json:"items" protobuf:"bytes,2,rep,name=items"`
137}
138
139// Webhook describes an admission webhook and the resources and operations it applies to.
140type Webhook struct {
141 // The name of the admission webhook.
142 // Name should be fully qualified, e.g., imagepolicy.kubernetes.io, where
143 // "imagepolicy" is the name of the webhook, and kubernetes.io is the name
144 // of the organization.
145 // Required.
146 Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
147
148 // ClientConfig defines how to communicate with the hook.
149 // Required
150 ClientConfig WebhookClientConfig `json:"clientConfig" protobuf:"bytes,2,opt,name=clientConfig"`
151
152 // Rules describes what operations on what resources/subresources the webhook cares about.
153 // The webhook cares about an operation if it matches _any_ Rule.
154 // However, in order to prevent ValidatingAdmissionWebhooks and MutatingAdmissionWebhooks
155 // from putting the cluster in a state which cannot be recovered from without completely
156 // disabling the plugin, ValidatingAdmissionWebhooks and MutatingAdmissionWebhooks are never called
157 // on admission requests for ValidatingWebhookConfiguration and MutatingWebhookConfiguration objects.
158 Rules []RuleWithOperations `json:"rules,omitempty" protobuf:"bytes,3,rep,name=rules"`
159
160 // FailurePolicy defines how unrecognized errors from the admission endpoint are handled -
161 // allowed values are Ignore or Fail. Defaults to Ignore.
162 // +optional
163 FailurePolicy *FailurePolicyType `json:"failurePolicy,omitempty" protobuf:"bytes,4,opt,name=failurePolicy,casttype=FailurePolicyType"`
164
165 // NamespaceSelector decides whether to run the webhook on an object based
166 // on whether the namespace for that object matches the selector. If the
167 // object itself is a namespace, the matching is performed on
168 // object.metadata.labels. If the object is another cluster scoped resource,
169 // it never skips the webhook.
170 //
171 // For example, to run the webhook on any objects whose namespace is not
172 // associated with "runlevel" of "0" or "1"; you will set the selector as
173 // follows:
174 // "namespaceSelector": {
175 // "matchExpressions": [
176 // {
177 // "key": "runlevel",
178 // "operator": "NotIn",
179 // "values": [
180 // "0",
181 // "1"
182 // ]
183 // }
184 // ]
185 // }
186 //
187 // If instead you want to only run the webhook on any objects whose
188 // namespace is associated with the "environment" of "prod" or "staging";
189 // you will set the selector as follows:
190 // "namespaceSelector": {
191 // "matchExpressions": [
192 // {
193 // "key": "environment",
194 // "operator": "In",
195 // "values": [
196 // "prod",
197 // "staging"
198 // ]
199 // }
200 // ]
201 // }
202 //
203 // See
204 // https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
205 // for more examples of label selectors.
206 //
207 // Default to the empty LabelSelector, which matches everything.
208 // +optional
209 NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty" protobuf:"bytes,5,opt,name=namespaceSelector"`
210
211 // SideEffects states whether this webhookk has side effects.
212 // Acceptable values are: Unknown, None, Some, NoneOnDryRun
213 // Webhooks with side effects MUST implement a reconciliation system, since a request may be
214 // rejected by a future step in the admission change and the side effects therefore need to be undone.
215 // Requests with the dryRun attribute will be auto-rejected if they match a webhook with
216 // sideEffects == Unknown or Some. Defaults to Unknown.
217 // +optional
218 SideEffects *SideEffectClass `json:"sideEffects,omitempty" protobuf:"bytes,6,opt,name=sideEffects,casttype=SideEffectClass"`
219}
220
221// RuleWithOperations is a tuple of Operations and Resources. It is recommended to make
222// sure that all the tuple expansions are valid.
223type RuleWithOperations struct {
224 // Operations is the operations the admission hook cares about - CREATE, UPDATE, or *
225 // for all operations.
226 // If '*' is present, the length of the slice must be one.
227 // Required.
228 Operations []OperationType `json:"operations,omitempty" protobuf:"bytes,1,rep,name=operations,casttype=OperationType"`
229 // Rule is embedded, it describes other criteria of the rule, like
230 // APIGroups, APIVersions, Resources, etc.
231 Rule `json:",inline" protobuf:"bytes,2,opt,name=rule"`
232}
233
234type OperationType string
235
236// The constants should be kept in sync with those defined in k8s.io/kubernetes/pkg/admission/interface.go.
237const (
238 OperationAll OperationType = "*"
239 Create OperationType = "CREATE"
240 Update OperationType = "UPDATE"
241 Delete OperationType = "DELETE"
242 Connect OperationType = "CONNECT"
243)
244
245// WebhookClientConfig contains the information to make a TLS
246// connection with the webhook
247type WebhookClientConfig struct {
248 // `url` gives the location of the webhook, in standard URL form
249 // (`scheme://host:port/path`). Exactly one of `url` or `service`
250 // must be specified.
251 //
252 // The `host` should not refer to a service running in the cluster; use
253 // the `service` field instead. The host might be resolved via external
254 // DNS in some apiservers (e.g., `kube-apiserver` cannot resolve
255 // in-cluster DNS as that would be a layering violation). `host` may
256 // also be an IP address.
257 //
258 // Please note that using `localhost` or `127.0.0.1` as a `host` is
259 // risky unless you take great care to run this webhook on all hosts
260 // which run an apiserver which might need to make calls to this
261 // webhook. Such installs are likely to be non-portable, i.e., not easy
262 // to turn up in a new cluster.
263 //
264 // The scheme must be "https"; the URL must begin with "https://".
265 //
266 // A path is optional, and if present may be any string permissible in
267 // a URL. You may use the path to pass an arbitrary string to the
268 // webhook, for example, a cluster identifier.
269 //
270 // Attempting to use a user or basic auth e.g. "user:password@" is not
271 // allowed. Fragments ("#...") and query parameters ("?...") are not
272 // allowed, either.
273 //
274 // +optional
275 URL *string `json:"url,omitempty" protobuf:"bytes,3,opt,name=url"`
276
277 // `service` is a reference to the service for this webhook. Either
278 // `service` or `url` must be specified.
279 //
280 // If the webhook is running within the cluster, then you should use `service`.
281 //
282 // Port 443 will be used if it is open, otherwise it is an error.
283 //
284 // +optional
285 Service *ServiceReference `json:"service,omitempty" protobuf:"bytes,1,opt,name=service"`
286
287 // `caBundle` is a PEM encoded CA bundle which will be used to validate the webhook's server certificate.
288 // If unspecified, system trust roots on the apiserver are used.
289 // +optional
290 CABundle []byte `json:"caBundle,omitempty" protobuf:"bytes,2,opt,name=caBundle"`
291}
292
293// ServiceReference holds a reference to Service.legacy.k8s.io
294type ServiceReference struct {
295 // `namespace` is the namespace of the service.
296 // Required
297 Namespace string `json:"namespace" protobuf:"bytes,1,opt,name=namespace"`
298 // `name` is the name of the service.
299 // Required
300 Name string `json:"name" protobuf:"bytes,2,opt,name=name"`
301
302 // `path` is an optional URL path which will be sent in any request to
303 // this service.
304 // +optional
305 Path *string `json:"path,omitempty" protobuf:"bytes,3,opt,name=path"`
306}