Skip to content
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

Static deserialization issues #3972

Closed
shawkins opened this issue Mar 15, 2022 · 8 comments
Closed

Static deserialization issues #3972

shawkins opened this issue Mar 15, 2022 · 8 comments

Comments

@shawkins
Copy link
Contributor

Is your task related to a problem? Please describe

To eventually remove the static type registration from the KubernetesDeserializer we can't have static entry points that rely on this implicit class resolution.

Describe the solution you'd like

Deprecate and provide alternatives to any static Serialization.unmarshall routines that don't supply the type.

Describe alternatives you've considered

No response

Additional context

No response

@shawkins shawkins added this to the 6.0.0 milestone Mar 15, 2022
@shawkins
Copy link
Contributor Author

shawkins commented Mar 15, 2022

Specifically deprecate

UNMATCHED_FIELD_TYPE_MODULE
jsonMapper()
yamlMapper()
unmarshal(InputStream is)
unmarshal(InputStream is, Map<String, String> parameters)
unmarshal(String str)

If we want the replacement to be available without completely building a client, then we'll need to add some method on the KubernetesClientBuilder. Otherwise with the logic in #3966 it would be easier to obtain the deserializer from the client:

var serdes = client.serialization(); // type and method name tbd
serdes.unmarshal("something yaml");

Under the covers we can use a HandlerInstantiator to associate an appropriate KubernetesDeserializer.

@shawkins
Copy link
Contributor Author

shawkins commented Mar 23, 2022

At a minimum we would introduce here an api for accessing what are now static concerns of serialization:

public interface KubernetesSerialization {

  <T> T unmarshal(InputStream is);

  <T> T unmarshal(InputStream is, Map<String, String> parameters);

  <T> T unmarshal(String str);

  <T> T clone(T resource);

  void setLogUnmatchedFieldWarnings(boolean logWarnings);

  void setRestrictUnmatchedFieldToTemplates(boolean restrictToTemplates);

  default void registerCustomKind(String kind, Class<? extends KubernetesResource> clazz) {
    registerCustomKind(null, kind, clazz);
  }

  void registerCustomKind(String apiVersion, String kind, Class<? extends KubernetesResource> clazz);

  // optionally we could include patchutils methods

  String withoutRuntimeState(KubernetesResource object, Format format, boolean omitStatus);

  String jsonDiff(KubernetesResource current, KubernetesResource updated, boolean omitStatus);

}

Assuming that we want users to obtain this without creating a client, there would likely need to be another factory: KubernetesSerialization.Factory or similar. It would also be obtainable off of the client: client.getKubernetesSerialization()

On the public interface it doesn't seem advisable to directly expose the mapper instances. Those would be available for internal use on the implementation class.

@manusa @rohanKanojia does this seem reasonable?

@shawkins
Copy link
Contributor Author

After talking with @manusa the usage of registerCustomKind is more limited for the client than I thought. We probably want to avoid using that internally or promoting that for usage by users.

This may require users to deal more with generic resources, which we'd like to offer a KubernetesResource.adapt(class) call.

This would also affect the Serialization.clone method.

@shawkins
Copy link
Contributor Author

shawkins commented Apr 4, 2022

The next steps here is to remove all internal usage of KubernetesDeserializer.registerCustomKind - even if we have a non-static KubernetesDeserializer, that kind of side implicit side-effect is undesirable. The expectation moving forward will be that the class is jandex discoverable. In some situations if it is not, rather than seeing the typed result it would instead be a generickubenetesresource. The places affected by this change will be:

  • direct untyped user calls to Serialization
  • client.load - if the item is at a top level, the api server will be consulted to create the ResourceHandler. If not found, then an exception will be thrown.
  • transitive references to the type via KubernetesResource, or HasMetadata - under a template for example

All other kubernetesclient calls will function as expected because they are typed.

The only issue with KubernetesResource.adapt is the handling of mutability since the real type is not a view, but a converted instance. It would be on the user to after making modifications, set the modified item back:

MyResource resource = something.getResource().adapt(MyResource.class) ;
// do something
something.setResource(resource);

@shawkins shawkins modified the milestones: 6.0.0, 6.x May 18, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Jul 22, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Jul 22, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Jul 22, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Jul 22, 2022
@stale
Copy link

stale bot commented Aug 16, 2022

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

@stale stale bot added the status/stale label Aug 16, 2022
manusa pushed a commit to shawkins/kubernetes-client that referenced this issue Aug 23, 2022
manusa pushed a commit to shawkins/kubernetes-client that referenced this issue Aug 23, 2022
@manusa manusa closed this as completed in 7622aee Aug 23, 2022
@manusa manusa reopened this Aug 23, 2022
@stale stale bot closed this as completed Aug 31, 2022
@manusa manusa reopened this Sep 1, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Nov 15, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Nov 15, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Nov 21, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Nov 21, 2022
@manusa manusa reopened this Dec 7, 2022
@shawkins
Copy link
Contributor Author

shawkins commented Dec 8, 2022

@manusa some next steps:

  • refine the KubernetesSerialization interface and where that would be associated with the client.
  • ideally allow for the configuration/setting of the objectmappers to the instance associated with the client via the KubernetesClientBuilder - will that help quarkus native scenarios if we use (likely via a copy) their objectmapper?
  • decide if we want to continue to allow KubernetesDeserializer.registerCustomKind. If we do not, then I don't think we'll have any additional state that we're associating with the deserializer - all classes must be known via the spi. If we do, then we'll have to make it part of the interface

shawkins added a commit to shawkins/kubernetes-client that referenced this issue Dec 8, 2022
…ialization

The methods accepting parameters have been deprecated
Support for Parameterizable has been removed - it should have been
rarely used.
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Dec 8, 2022
…ialization

The methods accepting parameters have been deprecated
Support for Parameterizable has been removed - it should have been
rarely used.
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Dec 8, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Dec 8, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Dec 8, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Dec 8, 2022
also moving more of the openshift impl to be client based
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Dec 9, 2022
also moving more of the openshift impl to be client based
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Dec 9, 2022
also moving more of the openshift impl to be client based
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Dec 11, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Dec 11, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Dec 14, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Dec 14, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Dec 14, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Dec 15, 2022
all parameter operations are now localized to template logic (overloaded
get and load)

also fixes kubernetesclientbuilder.withconfig
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Dec 15, 2022
all parameter operations are now localized to template logic (overloaded
get and load)

also fixes kubernetesclientbuilder.withconfig
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Dec 15, 2022
all parameter operations are now localized to template logic (overloaded
get and load)

also fixes kubernetesclientbuilder.withconfig
@manusa manusa closed this as completed in 1d3e263 Dec 22, 2022
@manusa manusa reopened this Dec 22, 2022
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Feb 17, 2023
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Feb 17, 2023
shawkins added a commit to shawkins/kubernetes-client that referenced this issue Feb 17, 2023
@shawkins
Copy link
Contributor Author

Marking as resolved by #4662 - we'll make further adjustments to the KubernetesSerialization from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants