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

fix #4206: ensuring null won't be returned from kubernetesdeserializer #4263

Merged
merged 2 commits into from
Aug 11, 2022

Conversation

shawkins
Copy link
Contributor

@shawkins shawkins commented Jul 7, 2022

Description

Fix #4206

This is to address #4206. We cannot throw an exception as it appears that the Config parsing has embedded HasMetadata (extensions) references, which lack type information. So instead we'll return a generic resource - that should ensure round-trip parse/serialization is also correct.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

  • Code contributed by me aligns with current project license: Apache 2.0
  • I Added CHANGELOG entry regarding this change
  • I have implemented unit tests to cover my changes
  • I have added/updated the javadocs and other documentation accordingly
  • No new bugs, code smells, etc. in SonarCloud report
  • I tested my code in Kubernetes
  • I tested my code in OpenShift

@shawkins shawkins requested review from metacosm and manusa July 7, 2022 20:13
@sonarcloud
Copy link

sonarcloud bot commented Jul 7, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@manusa manusa added this to the 6.1.0 milestone Jul 8, 2022
@shawkins
Copy link
Contributor Author

shawkins commented Jul 19, 2022

@manusa @rohanKanojia based upon our meeting we agree that mapping raw to HasMetadata is not good. It also creates a potentially odd set of builder methods as sundrio will assume the only valid types are the concrete types in the module and in the BuildableReferences. Raw should instead be any valid structured content.

My motivation to use the GenericKubernetesResource however was that it was the easiest way to preserve this content. if you run something like:

    IngressControllerSpec spec = new IngressControllerSpec();
    GenericKubernetesResource resource = new GenericKubernetesResource();
    resource.setAdditionalProperty("foo", "bar");
    spec.setUnsupportedConfigOverrides(resource);
    System.out.println(Serialization.asYaml(spec)); // contains unsupported
    IngressControllerSpec parsed = Serialization.unmarshal(Serialization.asYaml(spec), IngressControllerSpec.class);
    System.out.println(Serialization.asYaml(parsed)); // does not contain unsupported

You'll see that the unsupportedConfigOverrides are lost when they lack a kind/apiVersion.

That should be occurring in all such places like NamedExtension.extension, which seems to already exist in the Configs used in our test cases.

So if we don't want to use GenericKubernetesResource to conform to the existing mapping, then we'll have to change the generator / mapping logic.

As for the original issue #4206 - that could be handled separately for now just by considering the top-level object only, but it will of course get fixed if we generally handle the raw case - the Serialization.unmarshall would return a map of maps or whatever we think is appropriate for representing raw content when the root object lacks kind/apiVersion information.

@manusa
Copy link
Member

manusa commented Jul 19, 2022

base upon our meeting we agree that mapping raw to HasMetadata is not good. It also creates a potentially odd set of builder methods as sundrio will assume the only valid types are the concrete types in the module and in the BuildableReferences. Raw should instead be any valid structured content.

Right now the mapper has inconsistent handling for this, which is the worst part.

So in general, the following applies:

case "RawExtension":
return BasePackage + ".HasMetadata"

But you can also find:

reflect.TypeOf(runtime.RawExtension{}): "java.util.Map<String, Object>",

reflect.TypeOf(runtime.RawExtension{}): "java.util.Map<String, Object>",

and a few more...

And as I write this I'm recalling conversations around this topic and the specific mapping of rawExtension to Map precisely to avoid this problem. (#2073 #2335)

There also seems to be an internal issue about this d511cc8

Copy link
Collaborator

@metacosm metacosm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM apart from typo (see comment).

@shawkins
Copy link
Contributor Author

@manusa @metacosm here's an update to a hybrid / tactical solution. The deserializer will always return a generic, but we'll make a top level check to ensure that only valid generics are returned - which will satisfy #4206. This will allow for the HasMetadata mapping of raw to continue to work - then for a major release, or whenever we're comfortable with the breaking change, the mappings can be fixed.

Signed-off-by: Marc Nuri <marc@marcnuri.com>
@sonarcloud
Copy link

sonarcloud bot commented Aug 11, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

83.3% 83.3% Coverage
0.0% 0.0% Duplication

@manusa manusa merged commit 17199f6 into fabric8io:master Aug 11, 2022
@manusa manusa added the 5.12.x Backportable tentative label Aug 23, 2022
@manusa manusa removed the 5.12.x Backportable tentative label Sep 28, 2022
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.

Throw an exception when a resource cannot be deserialised instead of passing null downstream
4 participants