...

Source file src/k8s.io/api/admission/v1beta1/types.go

Documentation: k8s.io/api/admission/v1beta1

     1  /*
     2  Copyright 2017 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 v1beta1
    18  
    19  import (
    20  	authenticationv1 "k8s.io/api/authentication/v1"
    21  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    22  	"k8s.io/apimachinery/pkg/runtime"
    23  	"k8s.io/apimachinery/pkg/types"
    24  )
    25  
    26  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    27  // +k8s:prerelease-lifecycle-gen:introduced=1.9
    28  // +k8s:prerelease-lifecycle-gen:deprecated=1.19
    29  // This API is never server served.  It is used for outbound requests from apiservers.  This will ensure it never gets served accidentally
    30  // and having the generator against this group will protect future APIs which may be served.
    31  // +k8s:prerelease-lifecycle-gen:replacement=admission.k8s.io,v1,AdmissionReview
    32  
    33  // AdmissionReview describes an admission review request/response.
    34  type AdmissionReview struct {
    35  	metav1.TypeMeta `json:",inline"`
    36  	// Request describes the attributes for the admission request.
    37  	// +optional
    38  	Request *AdmissionRequest `json:"request,omitempty" protobuf:"bytes,1,opt,name=request"`
    39  	// Response describes the attributes for the admission response.
    40  	// +optional
    41  	Response *AdmissionResponse `json:"response,omitempty" protobuf:"bytes,2,opt,name=response"`
    42  }
    43  
    44  // AdmissionRequest describes the admission.Attributes for the admission request.
    45  type AdmissionRequest struct {
    46  	// UID is an identifier for the individual request/response. It allows us to distinguish instances of requests which are
    47  	// otherwise identical (parallel requests, requests when earlier requests did not modify etc)
    48  	// The UID is meant to track the round trip (request/response) between the KAS and the WebHook, not the user request.
    49  	// It is suitable for correlating log entries between the webhook and apiserver, for either auditing or debugging.
    50  	UID types.UID `json:"uid" protobuf:"bytes,1,opt,name=uid"`
    51  	// Kind is the fully-qualified type of object being submitted (for example, v1.Pod or autoscaling.v1.Scale)
    52  	Kind metav1.GroupVersionKind `json:"kind" protobuf:"bytes,2,opt,name=kind"`
    53  	// Resource is the fully-qualified resource being requested (for example, v1.pods)
    54  	Resource metav1.GroupVersionResource `json:"resource" protobuf:"bytes,3,opt,name=resource"`
    55  	// SubResource is the subresource being requested, if any (for example, "status" or "scale")
    56  	// +optional
    57  	SubResource string `json:"subResource,omitempty" protobuf:"bytes,4,opt,name=subResource"`
    58  
    59  	// RequestKind is the fully-qualified type of the original API request (for example, v1.Pod or autoscaling.v1.Scale).
    60  	// If this is specified and differs from the value in "kind", an equivalent match and conversion was performed.
    61  	//
    62  	// For example, if deployments can be modified via apps/v1 and apps/v1beta1, and a webhook registered a rule of
    63  	// `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]` and `matchPolicy: Equivalent`,
    64  	// an API request to apps/v1beta1 deployments would be converted and sent to the webhook
    65  	// with `kind: {group:"apps", version:"v1", kind:"Deployment"}` (matching the rule the webhook registered for),
    66  	// and `requestKind: {group:"apps", version:"v1beta1", kind:"Deployment"}` (indicating the kind of the original API request).
    67  	//
    68  	// See documentation for the "matchPolicy" field in the webhook configuration type for more details.
    69  	// +optional
    70  	RequestKind *metav1.GroupVersionKind `json:"requestKind,omitempty" protobuf:"bytes,13,opt,name=requestKind"`
    71  	// RequestResource is the fully-qualified resource of the original API request (for example, v1.pods).
    72  	// If this is specified and differs from the value in "resource", an equivalent match and conversion was performed.
    73  	//
    74  	// For example, if deployments can be modified via apps/v1 and apps/v1beta1, and a webhook registered a rule of
    75  	// `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]` and `matchPolicy: Equivalent`,
    76  	// an API request to apps/v1beta1 deployments would be converted and sent to the webhook
    77  	// with `resource: {group:"apps", version:"v1", resource:"deployments"}` (matching the resource the webhook registered for),
    78  	// and `requestResource: {group:"apps", version:"v1beta1", resource:"deployments"}` (indicating the resource of the original API request).
    79  	//
    80  	// See documentation for the "matchPolicy" field in the webhook configuration type.
    81  	// +optional
    82  	RequestResource *metav1.GroupVersionResource `json:"requestResource,omitempty" protobuf:"bytes,14,opt,name=requestResource"`
    83  	// RequestSubResource is the name of the subresource of the original API request, if any (for example, "status" or "scale")
    84  	// If this is specified and differs from the value in "subResource", an equivalent match and conversion was performed.
    85  	// See documentation for the "matchPolicy" field in the webhook configuration type.
    86  	// +optional
    87  	RequestSubResource string `json:"requestSubResource,omitempty" protobuf:"bytes,15,opt,name=requestSubResource"`
    88  
    89  	// Name is the name of the object as presented in the request.  On a CREATE operation, the client may omit name and
    90  	// rely on the server to generate the name.  If that is the case, this field will contain an empty string.
    91  	// +optional
    92  	Name string `json:"name,omitempty" protobuf:"bytes,5,opt,name=name"`
    93  	// Namespace is the namespace associated with the request (if any).
    94  	// +optional
    95  	Namespace string `json:"namespace,omitempty" protobuf:"bytes,6,opt,name=namespace"`
    96  	// Operation is the operation being performed. This may be different than the operation
    97  	// requested. e.g. a patch can result in either a CREATE or UPDATE Operation.
    98  	Operation Operation `json:"operation" protobuf:"bytes,7,opt,name=operation"`
    99  	// UserInfo is information about the requesting user
   100  	UserInfo authenticationv1.UserInfo `json:"userInfo" protobuf:"bytes,8,opt,name=userInfo"`
   101  	// Object is the object from the incoming request.
   102  	// +optional
   103  	Object runtime.RawExtension `json:"object,omitempty" protobuf:"bytes,9,opt,name=object"`
   104  	// OldObject is the existing object. Only populated for DELETE and UPDATE requests.
   105  	// +optional
   106  	OldObject runtime.RawExtension `json:"oldObject,omitempty" protobuf:"bytes,10,opt,name=oldObject"`
   107  	// DryRun indicates that modifications will definitely not be persisted for this request.
   108  	// Defaults to false.
   109  	// +optional
   110  	DryRun *bool `json:"dryRun,omitempty" protobuf:"varint,11,opt,name=dryRun"`
   111  	// Options is the operation option structure of the operation being performed.
   112  	// e.g. `meta.k8s.io/v1.DeleteOptions` or `meta.k8s.io/v1.CreateOptions`. This may be
   113  	// different than the options the caller provided. e.g. for a patch request the performed
   114  	// Operation might be a CREATE, in which case the Options will a
   115  	// `meta.k8s.io/v1.CreateOptions` even though the caller provided `meta.k8s.io/v1.PatchOptions`.
   116  	// +optional
   117  	Options runtime.RawExtension `json:"options,omitempty" protobuf:"bytes,12,opt,name=options"`
   118  }
   119  
   120  // AdmissionResponse describes an admission response.
   121  type AdmissionResponse struct {
   122  	// UID is an identifier for the individual request/response.
   123  	// This should be copied over from the corresponding AdmissionRequest.
   124  	UID types.UID `json:"uid" protobuf:"bytes,1,opt,name=uid"`
   125  
   126  	// Allowed indicates whether or not the admission request was permitted.
   127  	Allowed bool `json:"allowed" protobuf:"varint,2,opt,name=allowed"`
   128  
   129  	// Result contains extra details into why an admission request was denied.
   130  	// This field IS NOT consulted in any way if "Allowed" is "true".
   131  	// +optional
   132  	Result *metav1.Status `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
   133  
   134  	// The patch body. Currently we only support "JSONPatch" which implements RFC 6902.
   135  	// +optional
   136  	Patch []byte `json:"patch,omitempty" protobuf:"bytes,4,opt,name=patch"`
   137  
   138  	// The type of Patch. Currently we only allow "JSONPatch".
   139  	// +optional
   140  	PatchType *PatchType `json:"patchType,omitempty" protobuf:"bytes,5,opt,name=patchType"`
   141  
   142  	// AuditAnnotations is an unstructured key value map set by remote admission controller (e.g. error=image-blacklisted).
   143  	// MutatingAdmissionWebhook and ValidatingAdmissionWebhook admission controller will prefix the keys with
   144  	// admission webhook name (e.g. imagepolicy.example.com/error=image-blacklisted). AuditAnnotations will be provided by
   145  	// the admission webhook to add additional context to the audit log for this request.
   146  	// +optional
   147  	AuditAnnotations map[string]string `json:"auditAnnotations,omitempty" protobuf:"bytes,6,opt,name=auditAnnotations"`
   148  
   149  	// warnings is a list of warning messages to return to the requesting API client.
   150  	// Warning messages describe a problem the client making the API request should correct or be aware of.
   151  	// Limit warnings to 120 characters if possible.
   152  	// Warnings over 256 characters and large numbers of warnings may be truncated.
   153  	// +optional
   154  	Warnings []string `json:"warnings,omitempty" protobuf:"bytes,7,rep,name=warnings"`
   155  }
   156  
   157  // PatchType is the type of patch being used to represent the mutated object
   158  type PatchType string
   159  
   160  // PatchType constants.
   161  const (
   162  	PatchTypeJSONPatch PatchType = "JSONPatch"
   163  )
   164  
   165  // Operation is the type of resource operation being checked for admission control
   166  type Operation string
   167  
   168  // Operation constants
   169  const (
   170  	Create  Operation = "CREATE"
   171  	Update  Operation = "UPDATE"
   172  	Delete  Operation = "DELETE"
   173  	Connect Operation = "CONNECT"
   174  )
   175  

View as plain text