You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I see #193 which is handy to parse yaml data into a go-object, but the methodology there involves type-casting into specific types and then dealing with whatever they are (specifically).
I have a slightly different use-case: I want to read a yaml file for one or more objects, convert them into the corresponding kubernetes objects, and then, ignoring the type, modify some of the ObjectMeta (mostly add some annotations, labels, and/or ownership links), and then create-or-update the object. This is purely doing some modifications on the ObjectMeta, and ignores any type-specific Spec fields.
If I use a type-switch, I'll wind up with a boat-load of essentially duplicated code (including the Client.Create()), which I really want to avoid. However, the object I get from serializer.NewCodecFactory(reconciler.scheme).UniversalDeserializer().Decode.decode() is a runtime.Object, which apparently can't be converted into a v1.PartialObjectMetadata, which is probably what (in theory) I want.
AHA! I found my mistake: The trick is to typecast to a client.Object, which is what the client internally uses, anyway. These can still be manipulated in certain ways, and it removes the need to do a type-switch.
I see #193 which is handy to parse yaml data into a go-object, but the methodology there involves type-casting into specific types and then dealing with whatever they are (specifically).
I have a slightly different use-case: I want to read a yaml file for one or more objects, convert them into the corresponding kubernetes objects, and then, ignoring the type, modify some of the ObjectMeta (mostly add some annotations, labels, and/or ownership links), and then create-or-update the object. This is purely doing some modifications on the ObjectMeta, and ignores any type-specific Spec fields.
If I use a type-switch, I'll wind up with a boat-load of essentially duplicated code (including the Client.Create()), which I really want to avoid. However, the object I get from
serializer.NewCodecFactory(reconciler.scheme).UniversalDeserializer().Decode.decode()
is a runtime.Object, which apparently can't be converted into a v1.PartialObjectMetadata, which is probably what (in theory) I want.rough code (ignoring error checking):
This fails at this part:
obj, ok := runObj.(*v1.PartialObjectMetadata)
Any suggestions?
The text was updated successfully, but these errors were encountered: