Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Fix type errors from cached unstructured object
Browse files Browse the repository at this point in the history
The cacheClient may have saved in memory an unstructured object which is
not assignable to the native struct type. In this situation do JSON
marshaling

Signed-off-by: Darren Shepherd <darren@acorn.io>
  • Loading branch information
ibuildthecloud committed Jan 19, 2024
1 parent 384c159 commit 2a58ee7
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/runtime/copy.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package runtime

import (
"encoding/json"
"fmt"
"reflect"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
)

func CopyInto(dst, src runtime.Object) error {
if _, ok := src.(*unstructured.Unstructured); ok {
data, err := json.Marshal(src)
if err != nil {
return err
}
return json.Unmarshal(data, dst)
}
src = src.DeepCopyObject()
dstVal := reflect.ValueOf(dst)
srcVal := reflect.ValueOf(src)
Expand Down

0 comments on commit 2a58ee7

Please sign in to comment.