@@ -17,7 +17,12 @@ limitations under the License.
17
17
package apiutil
18
18
19
19
import (
20
+ "encoding/json"
20
21
"fmt"
22
+ "io"
23
+ "strings"
24
+
25
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21
26
22
27
"k8s.io/apimachinery/pkg/api/meta"
23
28
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -82,7 +87,7 @@ func RESTUnstructuredClientForGVK(gvk schema.GroupVersionKind, baseConfig *rest.
82
87
break
83
88
}
84
89
}
85
- jsonInfo .Serializer = unstructured . UnstructuredJSONScheme
90
+ jsonInfo .Serializer = dynamicCodec {}
86
91
cfg .NegotiatedSerializer = serializer .NegotiatedSerializerWrapper (jsonInfo )
87
92
88
93
return rest .RESTClientFor (cfg )
@@ -105,3 +110,30 @@ func createRestConfig(gvk schema.GroupVersionKind, baseConfig *rest.Config) *res
105
110
return cfg
106
111
107
112
}
113
+
114
+ //Copied from deprecated-dynamic/bad_debt.go
115
+ // dynamicCodec is a codec that wraps the standard unstructured codec
116
+ // with special handling for Status objects.
117
+ // Deprecated only used by test code and its wrong
118
+ type dynamicCodec struct {}
119
+
120
+ func (dynamicCodec ) Decode (data []byte , gvk * schema.GroupVersionKind , obj runtime.Object ) (runtime.Object , * schema.GroupVersionKind , error ) {
121
+ obj , gvk , err := unstructured .UnstructuredJSONScheme .Decode (data , gvk , obj )
122
+ if err != nil {
123
+ return nil , nil , err
124
+ }
125
+
126
+ if _ , ok := obj .(* metav1.Status ); ! ok && strings .ToLower (gvk .Kind ) == "status" {
127
+ obj = & metav1.Status {}
128
+ err := json .Unmarshal (data , obj )
129
+ if err != nil {
130
+ return nil , nil , err
131
+ }
132
+ }
133
+
134
+ return obj , gvk , nil
135
+ }
136
+
137
+ func (dynamicCodec ) Encode (obj runtime.Object , w io.Writer ) error {
138
+ return unstructured .UnstructuredJSONScheme .Encode (obj , w )
139
+ }
0 commit comments