|
76 | 76 | -- server = mutate |
77 | 77 | -- |
78 | 78 | -- mutate :: W.AdmissionReviewRequest -> Handler W.AdmissionReviewResponse |
79 | | --- mutate req = pure $ W.mutatingWebhook req (\_ -> Right W.Allowed) addToleration |
| 79 | +-- mutate req = pure $ W.mutatingWebhook req (\_ -> Right addToleration) |
80 | 80 | -- |
81 | 81 | -- addToleration :: W.Patch |
82 | 82 | -- addToleration = |
@@ -106,24 +106,22 @@ data Allowed = Allowed |
106 | 106 | mutatingWebhook :: |
107 | 107 | -- | the request the webhook receives from Kubernetes |
108 | 108 | AdmissionReviewRequest -> |
109 | | - -- | logic to validate the request or reject it with an error |
110 | | - (AdmissionRequest -> Either Status Allowed) -> |
111 | | - -- | the change to apply to the object |
112 | | - Patch -> |
| 109 | + -- | logic to validate the request by returning the change to apply to the object or reject the request with an error |
| 110 | + (AdmissionRequest -> Either Status Patch) -> |
113 | 111 | -- | the response sent back to Kubernetes |
114 | 112 | AdmissionReviewResponse |
115 | | -mutatingWebhook AdmissionReviewRequest {request = req} allow patch = |
| 113 | +mutatingWebhook AdmissionReviewRequest {request = req} mutator = |
116 | 114 | admissionReviewResponse AdmissionResponse |
117 | 115 | { uid = rid, |
118 | 116 | allowed = isRight processedRequest, |
119 | | - patch = Just patch, |
| 117 | + patch = either (const Nothing) Just processedRequest, |
120 | 118 | status = either Just (const Nothing) processedRequest, |
121 | 119 | patchType = Just JSONPatch, |
122 | 120 | auditAnnotations = Nothing |
123 | 121 | } |
124 | 122 | where |
125 | 123 | AdmissionRequest {uid = rid} = req |
126 | | - processedRequest = allow req |
| 124 | + processedRequest = mutator req |
127 | 125 |
|
128 | 126 | -- | Lets you create a validating admission webhook |
129 | 127 | validatingWebhook :: |
|
0 commit comments