Skip to content

Commit

Permalink
fix: unable to serialize secret with gzip data
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanJosipovic committed Sep 13, 2024
1 parent 0c8f6c7 commit 6aabc75
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
19 changes: 19 additions & 0 deletions src/KubeUI/Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Avalonia.Data.Converters;
using k8s;
using k8s.Models;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text.Json;

namespace KubeUI;

Expand Down Expand Up @@ -244,4 +247,20 @@ public static string GetKubeAssetPath(Type type)

return "/Assets/kube/blank.svg";
}

public static IKubernetesObject<V1ObjectMeta> CloneObject(object obj)
{
var json = KubernetesJson.Serialize(obj);

return (IKubernetesObject<V1ObjectMeta>)DeserializeKubeJson(json, obj.GetType());
}

private static readonly MethodInfo _deserializeJson = typeof(KubernetesJson).GetMethod(nameof(KubernetesJson.Deserialize), BindingFlags.Static | BindingFlags.Public, [typeof(string), typeof(JsonSerializerOptions)]);

public static object DeserializeKubeJson(string json, Type type)
{
var fooRef = _deserializeJson.MakeGenericMethod(type);

return fooRef.Invoke(null, [json, null]);
}
}
9 changes: 1 addition & 8 deletions src/KubeUI/ViewModels/ResourceYamlViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private void SetYamlDocument()
{
if (!EditMode && HideNoisyFields)
{
var ObjectClone = CloneObject(Object);
var ObjectClone = Utilities.CloneObject(Object);

if (ObjectClone.Metadata != null)
{
Expand Down Expand Up @@ -119,13 +119,6 @@ private bool CanSetEditMode()
return true;
}

public IKubernetesObject<V1ObjectMeta> CloneObject(object obj)
{
var source = Client.Serialization.KubernetesYaml.Serialize(obj);

return (IKubernetesObject<V1ObjectMeta>)Client.Serialization.KubernetesYaml.Deserializer.Deserialize(source, obj.GetType())!;
}

public void Dispose()
{
if (Cluster != null)
Expand Down

0 comments on commit 6aabc75

Please sign in to comment.