Skip to content

Commit 363dec3

Browse files
committed
remove patchType when no patch is available (invalid)
1 parent 02be90f commit 363dec3

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

enforcer/enforcer_main.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,18 @@ async def mutate(request: AdmissionReview):
158158

159159
logger.debug("Pod patches %s", patches)
160160

161+
response = {
162+
"uid": request.request.get("uid"),
163+
"allowed": True,
164+
}
165+
if patches:
166+
response["patchType"] = "JSONPatch"
167+
response["patch"] = base64.b64encode(json.dumps(patches).encode()).decode()
168+
161169
return {
162170
"apiVersion": "admission.k8s.io/v1",
163171
"kind": "AdmissionReview",
164-
"response": {
165-
"uid": request.request.get("uid"),
166-
"allowed": True,
167-
"patchType": "JSONPatch",
168-
"patch": base64.b64encode(json.dumps(patches).encode()).decode() if patches else None
169-
}
172+
"response": response
170173
}
171174

172175
except Exception as e:

0 commit comments

Comments
 (0)