| 1 |
/* |
| 2 |
Copyright 2024 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 patch |
| 18 |
|
| 19 |
import ( |
| 20 |
"context" |
| 21 |
|
| 22 |
v1 "k8s.io/api/core/v1" |
| 23 |
"k8s.io/apimachinery/pkg/runtime" |
| 24 |
"k8s.io/apimachinery/pkg/runtime/schema" |
| 25 |
"k8s.io/apimachinery/pkg/util/managedfields" |
| 26 |
"k8s.io/apiserver/pkg/admission" |
| 27 |
"k8s.io/apiserver/pkg/admission/plugin/cel" |
| 28 |
) |
| 29 |
|
| 30 |
// Patcher provides a patch function to perform a mutation to an object in the admission chain. |
| 31 |
type Patcher interface { |
| 32 |
// Patch returns a copy of the object in the request, modified to change specified by the patch. |
| 33 |
// The original object in the request MUST NOT be modified in-place. |
| 34 |
Patch(ctx context.Context, request Request, runtimeCELCostBudget int64) (runtime.Object, error) |
| 35 |
} |
| 36 |
|
| 37 |
// Request defines the arguments required by a patcher. |
| 38 |
type Request struct { |
| 39 |
MatchedResource schema.GroupVersionResource |
| 40 |
VersionedAttributes *admission.VersionedAttributes |
| 41 |
ObjectInterfaces admission.ObjectInterfaces |
| 42 |
OptionalVariables cel.OptionalVariableBindings |
| 43 |
Namespace *v1.Namespace |
| 44 |
TypeConverter managedfields.TypeConverter |
| 45 |
} |