From 17caa561ecf098c95596977a2bc1bd5ee818202e Mon Sep 17 00:00:00 2001
From: Abhinav Sinha <37282098+zeborg@users.noreply.github.com>
Date: Thu, 17 Mar 2022 19:50:24 +0530
Subject: [PATCH] Replace `ToUnstructured()` with Marshal/Unmarshal (#3150)

Signed-off-by: Abhinav Sinha <abhinav@nirmata.com>

Co-authored-by: shuting <shuting@nirmata.com>
---
 pkg/dclient/client.go | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/pkg/dclient/client.go b/pkg/dclient/client.go
index e61829665c..d0dcbae0e9 100644
--- a/pkg/dclient/client.go
+++ b/pkg/dclient/client.go
@@ -2,6 +2,7 @@ package client
 
 import (
 	"context"
+	"encoding/json"
 	"fmt"
 	"strings"
 	"time"
@@ -10,7 +11,6 @@ import (
 	openapiv2 "github.com/googleapis/gnostic/openapiv2"
 	meta "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
-	"k8s.io/apimachinery/pkg/runtime"
 	"k8s.io/apimachinery/pkg/runtime/schema"
 	patchTypes "k8s.io/apimachinery/pkg/types"
 	"k8s.io/apimachinery/pkg/version"
@@ -186,11 +186,19 @@ func (c *Client) UpdateStatusResource(apiVersion string, kind string, namespace
 }
 
 func convertToUnstructured(obj interface{}) *unstructured.Unstructured {
-	unstructuredObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&obj)
+	unstrObj := map[string]interface{}{}
+
+	raw, err := json.Marshal(obj)
 	if err != nil {
 		return nil
 	}
-	return &unstructured.Unstructured{Object: unstructuredObj}
+
+	err = json.Unmarshal(raw, &unstrObj)
+	if err != nil {
+		return nil
+	}
+
+	return &unstructured.Unstructured{Object: unstrObj}
 }
 
 //IDiscovery provides interface to mange Kind and GVR mapping