From 8d4b7ce8d3fa62cd88d29101b98f700507194ffc Mon Sep 17 00:00:00 2001 From: ChandonPierre <80500072+ChandonPierre@users.noreply.github.com> Date: Mon, 24 Jul 2023 06:25:14 -0400 Subject: [PATCH] outposts: fix patch processing (#6338) * outposts: fix patch processing for custom object types * outposts: correct parsing patch type * small change Signed-off-by: Jens Langhammer --------- Signed-off-by: Jens Langhammer Co-authored-by: Jens Langhammer --- authentik/outposts/controllers/k8s/base.py | 25 ++++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/authentik/outposts/controllers/k8s/base.py b/authentik/outposts/controllers/k8s/base.py index c07a1fded..ca8542a75 100644 --- a/authentik/outposts/controllers/k8s/base.py +++ b/authentik/outposts/controllers/k8s/base.py @@ -1,7 +1,9 @@ """Base Kubernetes Reconciler""" +from dataclasses import asdict from json import dumps from typing import TYPE_CHECKING, Generic, Optional, TypeVar +from dacite.core import from_dict from django.utils.text import slugify from jsonpatch import JsonPatchConflict, JsonPatchException, JsonPatchTestFailed, apply_patch from kubernetes.client import ApiClient, V1ObjectMeta @@ -43,7 +45,7 @@ class KubernetesObjectReconciler(Generic[T]): patches = self.controller.outpost.config.kubernetes_json_patches if not patches: return None - return patches.get(self.name, None) + return patches.get(self.reconciler_name(), None) @property def is_embedded(self) -> bool: @@ -75,18 +77,27 @@ class KubernetesObjectReconciler(Generic[T]): """Get patched reference object""" reference = self.get_reference_object() patch = self.get_patch() - v1deploy_json = ApiClient().sanitize_for_serialization(reference) try: + json = ApiClient().sanitize_for_serialization(reference) + # Custom objects will not be known to the clients openapi types + except AttributeError: + json = asdict(reference) + try: + ref = json if patch is not None: - ref_v1deploy = apply_patch(v1deploy_json, patch) - else: - ref_v1deploy = v1deploy_json + ref = apply_patch(json, patch) except (JsonPatchException, JsonPatchConflict, JsonPatchTestFailed) as exc: raise ControllerException(f"JSON Patch failed: {exc}") from exc mock_response = Response() - mock_response.data = dumps(ref_v1deploy) + mock_response.data = dumps(ref) - return ApiClient().deserialize(mock_response, reference.__class__.__name__) + try: + result = ApiClient().deserialize(mock_response, reference.__class__.__name__) + # Custom objects will not be known to the clients openapi types + except AttributeError: + result = from_dict(reference.__class__, data=ref) + + return result # pylint: disable=invalid-name def up(self):