Skip to content

Commit

Permalink
Merge pull request #121771 from pohly/apimachinery-encoding-shortcut
Browse files Browse the repository at this point in the history
encoding: avoid setting GVK unnecessarily

Kubernetes-commit: 508e3b94fe48136c2c7bff6239986851f0e21dc0
  • Loading branch information
k8s-publishing-bot committed Dec 14, 2023
2 parents aa9a6c8 + 013c6eb commit 2341c26
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/runtime/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,14 @@ func (e WithVersionEncoder) Encode(obj Object, stream io.Writer) error {
gvk = preferredGVK
}
}
kind.SetGroupVersionKind(gvk)
err = e.Encoder.Encode(obj, stream)
kind.SetGroupVersionKind(oldGVK)
return err

// The gvk only needs to be set if not already as desired.
if gvk != oldGVK {
kind.SetGroupVersionKind(gvk)
defer kind.SetGroupVersionKind(oldGVK)
}

return e.Encoder.Encode(obj, stream)
}

// WithoutVersionDecoder clears the group version kind of a deserialized object.
Expand Down

0 comments on commit 2341c26

Please sign in to comment.