|
| 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 v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + "encoding/json" |
| 21 | + "time" |
| 22 | + |
| 23 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 24 | +) |
| 25 | + |
| 26 | +const ( |
| 27 | + // ResourcePatchKind is the kind of the ResourcePatch. |
| 28 | + ResourcePatchKind = "ResourcePatch" |
| 29 | +) |
| 30 | + |
| 31 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 32 | + |
| 33 | +// ResourcePatch provides resource definition for kwokctl. |
| 34 | +// this is a action of resource patch. |
| 35 | +type ResourcePatch struct { |
| 36 | + //+k8s:conversion-gen=false |
| 37 | + metav1.TypeMeta `json:",inline"` |
| 38 | + |
| 39 | + // Resource represents the resource to be patched. |
| 40 | + Resource GroupVersionResource `json:"resource"` |
| 41 | + // Target represents the target of the ResourcePatch. |
| 42 | + Target Target `json:"target"` |
| 43 | + // DurationNanosecond represents the duration of the patch in nanoseconds. |
| 44 | + DurationNanosecond time.Duration `json:"durationNanosecond"` |
| 45 | + // Method represents the method of the patch. |
| 46 | + Method PatchMethod `json:"method"` |
| 47 | + // Template contains the patch data as a raw JSON message. |
| 48 | + Template json.RawMessage `json:"template,omitempty"` |
| 49 | +} |
| 50 | + |
| 51 | +// PatchMethod defines the method used to patch a resource. |
| 52 | +type PatchMethod string |
| 53 | + |
| 54 | +const ( |
| 55 | + // PatchMethodCreate means that the resource will be created by create. |
| 56 | + PatchMethodCreate PatchMethod = "create" |
| 57 | + // PatchMethodPatch means that the resource will be patched by patch. |
| 58 | + PatchMethodPatch PatchMethod = "patch" |
| 59 | + // PatchMethodDelete means that the resource will be deleted by delete. |
| 60 | + PatchMethodDelete PatchMethod = "delete" |
| 61 | +) |
| 62 | + |
| 63 | +// Target is a struct that represents the target of the ResourcePatch. |
| 64 | +type Target struct { |
| 65 | + // Name represents the name of the resource to be patched. |
| 66 | + Name string `json:"name"` |
| 67 | + // Namespace represents the namespace of the resource to be patched. |
| 68 | + Namespace string `json:"namespace,omitempty"` |
| 69 | +} |
| 70 | + |
| 71 | +// GroupVersionResource is a struct that represents the group version resource. |
| 72 | +type GroupVersionResource struct { |
| 73 | + // Group represents the group of the resource. |
| 74 | + Group string `json:"group,omitempty"` |
| 75 | + // Version represents the version of the resource. |
| 76 | + Version string `json:"version"` |
| 77 | + // Resource represents the type of the resource. |
| 78 | + Resource string `json:"resource"` |
| 79 | +} |
0 commit comments