Add logging for image mutation
All checks were successful
continuous-integration/drone Build is passing

This commit is contained in:
Lauri Võsandi 2022-12-22 22:01:20 +02:00
parent a382a33dd7
commit 0c9710cb13

View File

@ -19,11 +19,16 @@ app = Sanic("admission_control")
async def admission_control_handler(request): async def admission_control_handler(request):
patches = [] patches = []
for index, container in enumerate(request.json["request"]["object"]["spec"]["containers"]): for index, container in enumerate(request.json["request"]["object"]["spec"]["containers"]):
mutated_image = mutate_image(container["image"], harbor.hostname, cached_registries)
patches.append({ patches.append({
"op": "replace", "op": "replace",
"path": "/spec/containers/%d/image" % index, "path": "/spec/containers/%d/image" % index,
"value": mutate_image(container["image"], harbor.hostname, cached_registries), "value": mutated_image,
}) })
print("Substituting %s with %s for pod %s/%s" % (
container["image"], mutated_image,
request.json["request"]["object"]["metadata"]["namespace"],
request.json["request"]["object"]["metadata"]["name"]))
response = { response = {
"apiVersion": "admission.k8s.io/v1", "apiVersion": "admission.k8s.io/v1",
"kind": "AdmissionReview", "kind": "AdmissionReview",