Skip to content

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

Merged
merged 1 commit into from
Aug 1, 2018

Conversation

shawn-hurley
Copy link
Member

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

type UtilDecoderFunc func(gv schema.GroupVersion) runtime.Decoder

// SetDecoderFunc sets a non default decoder function
func SetDecoderFunc(u UtilDecoderFunc) {
Copy link
Contributor

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.


// 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 {
Copy link
Member Author

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?

Copy link
Contributor

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.

Copy link
Contributor

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
@hasbro17
Copy link
Contributor

hasbro17 commented Aug 1, 2018

LGTM

@hasbro17 hasbro17 merged commit a72f861 into operator-framework:master Aug 1, 2018
@shawn-hurley shawn-hurley deleted the config-decoder branch October 17, 2018 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow Operator to change the runtime.Decoder that k8sutil will use
2 participants