@@ -21,6 +21,7 @@ import (
2121 "fmt"
2222
2323 "k8s.io/apimachinery/pkg/runtime"
24+ "k8s.io/apimachinery/pkg/util/json"
2425 "k8s.io/client-go/util/apply"
2526)
2627
@@ -146,17 +147,24 @@ func (c *typedClient) Apply(ctx context.Context, obj runtime.ApplyConfiguration,
146147 applyOpts := & ApplyOptions {}
147148 applyOpts .ApplyOptions (opts )
148149
149- return req .
150+ var contentType string
151+ body , err := req .
150152 NamespaceIfScoped (o .namespace , o .isNamespaced ()).
151153 Resource (o .resource ()).
152154 Name (o .name ).
153155 VersionedParams (applyOpts .AsPatchOptions (), c .paramCodec ).
154156 Do (ctx ).
155- // This is hacky, it is required because `Into` takes a `runtime.Object` and
156- // that is not implemented by the ApplyConfigurations. The generated clients
157- // don't have this problem because they deserialize into the api type, not the
158- // apply configuration: https://github.com/kubernetes/kubernetes/blob/22f5e01a37c0bc6a5f494dec14dd4e3688ee1d55/staging/src/k8s.io/client-go/gentype/type.go#L296-L317
159- Into (runtimeObjectFromApplyConfiguration (obj ))
157+ ContentType (& contentType ).
158+ Raw ()
159+ if err != nil {
160+ return err
161+ }
162+
163+ if contentType != "application/json" {
164+ return fmt .Errorf ("unexpected content type %q in apply response, expected application/json" , contentType )
165+ }
166+
167+ return json .Unmarshal (body , obj )
160168}
161169
162170// Get implements client.Client.
@@ -324,16 +332,23 @@ func (c *typedClient) ApplySubResource(ctx context.Context, obj runtime.ApplyCon
324332 return fmt .Errorf ("failed to create apply request: %w" , err )
325333 }
326334
327- return req .
335+ var contentType string
336+ respBody , err := req .
328337 NamespaceIfScoped (o .namespace , o .isNamespaced ()).
329338 Resource (o .resource ()).
330339 Name (o .name ).
331340 SubResource (subResource ).
332341 VersionedParams (applyOpts .AsPatchOptions (), c .paramCodec ).
333342 Do (ctx ).
334- // This is hacky, it is required because `Into` takes a `runtime.Object` and
335- // that is not implemented by the ApplyConfigurations. The generated clients
336- // don't have this problem because they deserialize into the api type, not the
337- // apply configuration: https://github.com/kubernetes/kubernetes/blob/22f5e01a37c0bc6a5f494dec14dd4e3688ee1d55/staging/src/k8s.io/client-go/gentype/type.go#L296-L317
338- Into (runtimeObjectFromApplyConfiguration (obj ))
343+ ContentType (& contentType ).
344+ Raw ()
345+ if err != nil {
346+ return err
347+ }
348+
349+ if contentType != "application/json" {
350+ return fmt .Errorf ("unexpected content type %q in apply response, expected application/json" , contentType )
351+ }
352+
353+ return json .Unmarshal (respBody , obj )
339354}
0 commit comments