1 /* 2 Copyright 2019 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package webhook 18 19 import ( 20 "gomodules.xyz/jsonpatch/v2" 21 "sigs.k8s.io/controller-runtime/pkg/webhook/admission" 22 ) 23 24 // define some aliases for common bits of the webhook functionality 25 26 // Defaulter defines functions for setting defaults on resources. 27 // Deprecated: Use CustomDefaulter instead. 28 type Defaulter = admission.Defaulter 29 30 // Validator defines functions for validating an operation. 31 // Deprecated: Use CustomValidator instead. 32 type Validator = admission.Validator 33 34 // CustomDefaulter defines functions for setting defaults on resources. 35 type CustomDefaulter = admission.CustomDefaulter 36 37 // CustomValidator defines functions for validating an operation. 38 type CustomValidator = admission.CustomValidator 39 40 // AdmissionRequest defines the input for an admission handler. 41 // It contains information to identify the object in 42 // question (group, version, kind, resource, subresource, 43 // name, namespace), as well as the operation in question 44 // (e.g. Get, Create, etc), and the object itself. 45 type AdmissionRequest = admission.Request 46 47 // AdmissionResponse is the output of an admission handler. 48 // It contains a response indicating if a given 49 // operation is allowed, as well as a set of patches 50 // to mutate the object in the case of a mutating admission handler. 51 type AdmissionResponse = admission.Response 52 53 // Admission is webhook suitable for registration with the server 54 // an admission webhook that validates API operations and potentially 55 // mutates their contents. 56 type Admission = admission.Webhook 57 58 // AdmissionHandler knows how to process admission requests, validating them, 59 // and potentially mutating the objects they contain. 60 type AdmissionHandler = admission.Handler 61 62 // AdmissionDecoder knows how to decode objects from admission requests. 63 type AdmissionDecoder = admission.Decoder 64 65 // JSONPatchOp represents a single JSONPatch patch operation. 66 type JSONPatchOp = jsonpatch.Operation 67 68 var ( 69 // Allowed indicates that the admission request should be allowed for the given reason. 70 Allowed = admission.Allowed 71 72 // Denied indicates that the admission request should be denied for the given reason. 73 Denied = admission.Denied 74 75 // Patched indicates that the admission request should be allowed for the given reason, 76 // and that the contained object should be mutated using the given patches. 77 Patched = admission.Patched 78 79 // Errored indicates that an error occurred in the admission request. 80 Errored = admission.Errored 81 ) 82