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 <jens@goauthentik.io>

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Co-authored-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
ChandonPierre 2023-07-24 06:25:14 -04:00 committed by GitHub
parent 56cf14e5ef
commit 8d4b7ce8d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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):