1
16
17 package webhook
18
19 import (
20 v1 "k8s.io/api/admission/v1"
21 "k8s.io/api/admission/v1beta1"
22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23 )
24
25 func convertAdmissionRequestToV1(r *v1beta1.AdmissionRequest) *v1.AdmissionRequest {
26 return &v1.AdmissionRequest{
27 Kind: r.Kind,
28 Namespace: r.Namespace,
29 Name: r.Name,
30 Object: r.Object,
31 Resource: r.Resource,
32 Operation: v1.Operation(r.Operation),
33 UID: r.UID,
34 DryRun: r.DryRun,
35 OldObject: r.OldObject,
36 Options: r.Options,
37 RequestKind: r.RequestKind,
38 RequestResource: r.RequestResource,
39 RequestSubResource: r.RequestSubResource,
40 SubResource: r.SubResource,
41 UserInfo: r.UserInfo,
42 }
43 }
44
45 func convertAdmissionRequestToV1beta1(r *v1.AdmissionRequest) *v1beta1.AdmissionRequest {
46 return &v1beta1.AdmissionRequest{
47 Kind: r.Kind,
48 Namespace: r.Namespace,
49 Name: r.Name,
50 Object: r.Object,
51 Resource: r.Resource,
52 Operation: v1beta1.Operation(r.Operation),
53 UID: r.UID,
54 DryRun: r.DryRun,
55 OldObject: r.OldObject,
56 Options: r.Options,
57 RequestKind: r.RequestKind,
58 RequestResource: r.RequestResource,
59 RequestSubResource: r.RequestSubResource,
60 SubResource: r.SubResource,
61 UserInfo: r.UserInfo,
62 }
63 }
64
65 func convertAdmissionResponseToV1(r *v1beta1.AdmissionResponse) *v1.AdmissionResponse {
66 var pt *v1.PatchType
67 if r.PatchType != nil {
68 t := v1.PatchType(*r.PatchType)
69 pt = &t
70 }
71 return &v1.AdmissionResponse{
72 UID: r.UID,
73 Allowed: r.Allowed,
74 AuditAnnotations: r.AuditAnnotations,
75 Patch: r.Patch,
76 PatchType: pt,
77 Result: r.Result,
78 Warnings: r.Warnings,
79 }
80 }
81
82 func convertAdmissionResponseToV1beta1(r *v1.AdmissionResponse) *v1beta1.AdmissionResponse {
83 var pt *v1beta1.PatchType
84 if r.PatchType != nil {
85 t := v1beta1.PatchType(*r.PatchType)
86 pt = &t
87 }
88 return &v1beta1.AdmissionResponse{
89 UID: r.UID,
90 Allowed: r.Allowed,
91 AuditAnnotations: r.AuditAnnotations,
92 Patch: r.Patch,
93 PatchType: pt,
94 Result: r.Result,
95 Warnings: r.Warnings,
96 }
97 }
98
99 func toV1AdmissionResponse(err error) *v1.AdmissionResponse {
100 return &v1.AdmissionResponse{
101 Result: &metav1.Status{
102 Message: err.Error(),
103 },
104 }
105 }
106
View as plain text