-
Notifications
You must be signed in to change notification settings - Fork 1.8k
util/k8sutil: add ability to configure decoder #369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util/k8sutil: add ability to configure decoder #369
Conversation
pkg/util/k8sutil/k8sutil.go
Outdated
type UtilDecoderFunc func(gv schema.GroupVersion) runtime.Decoder | ||
|
||
// SetDecoderFunc sets a non default decoder function | ||
func SetDecoderFunc(u UtilDecoderFunc) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a note to highlight the fact that this is just an experimental knob for the special use case of setting a codecs.UniversalDeserializer
to deserialize an Unstructured object without overwriting the TypeMeta.
Because this is only a temporary workaround for supporting unstructured objects.
c207f2b
to
75c4451
Compare
pkg/util/k8sutil/k8sutil.go
Outdated
|
||
// GetCodecs get the codec factory for the scheme | ||
// Exposing the codecs factory so that a user can use the codecs for the scheme. | ||
func GetCodecs() serializer.CodecFactory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is unacceptable, then we could add the codecs as a parameter to the UtilDecoderFunc
. @hasbro17 I would love to hear your thoughts on which approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to expose this?
I thought we only needed to let users configure the decoder to codecs.UniversalDeserializer
in order to support unstructured objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shawn-hurley Let's pass in the CodecFactory as an argument to UtilDecoderFunc
. That way SetDecoderFunc
is less ambiguous to use and we don't increase the API surface if we really don't need to.
So we can get rid of GetCodecs()
and change UtilDecoderFunc
to
type UtilDecoderFunc func(codecFactory serializer.CodecFactory, gv schema.GroupVersion) runtime.Decoder
You'll have to change the defaultDecoder function signature and wherever it's called below as well
func decoder(codecFactory serializer.CodecFactory, gv schema.GroupVersion) runtime.Decoder {
return codecFactory.UniversalDecoder(gv)
}
func RuntimeObjectFromUnstructured(u *unstructured.Unstructured) runtime.Object {
gvk := u.GroupVersionKind()
decoder := decoderFunc(codecs, gvk.GroupVersion())
Creates a typed function for getting the decoder from the codecs Adds method to set decoder func Adds package var for the decoder fun fixes operator-framework#352
75c4451
to
ed39331
Compare
LGTM |
Creates a typed function for getting the decoder from the scheme
Adds method to set decoder func
Adds package var for the decoder fun
fixes #352