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

Test and fix for the wrong "Kind" declared on KubernetesListHandler #2336

Merged
merged 2 commits into from
Jul 9, 2020

Conversation

ahgittin
Copy link
Contributor

@ahgittin ahgittin commented Jul 8, 2020

Description

This PR changes KubernetesListHandler.getKind() from returning "Service" to returning "List". The latter is what KubernetesList.getKind() returns, and the former causes the resulting ResourceHandler.Key to be identical to what is computed for ServiceHandler, meaning Handlers.of(key) can return the wrong handler.

In practice the problem noted above can cause the Kubernetes client to fail when working with kind: Service YAML manifests, in some circumstances. This was observed under OSGi using the DefaultKubernetesClient. Handlers.of(<Service,v1>) returned the KubernetesListHandler which subsequently threw the following exception:

Failed after 466ms: io.fabric8.kubernetes.api.model.Service cannot be cast to io.fabric8.kubernetes.api.model.KubernetesList
java.lang.ClassCastException: io.fabric8.kubernetes.api.model.Service cannot be cast to io.fabric8.kubernetes.api.model.KubernetesList
	at io.fabric8.kubernetes.client.handlers.KubernetesListHandler.edit(KubernetesListHandler.java:39)
	at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.acceptVisitors(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:331)
	at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.createOrReplace(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:248)
	at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.createOrReplace(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:64)
	at ...

The problem is not usually observed because KubernetesListHandler is not registered as a service in POJO, but it is under OSGi, and of course because Handlers keeps a map based on the key, whether the problem actually happens depends which of the two handlers was registered last.

This PR also includes a test which asserts there are no conflicts among the stock handlers, which fails prior to the fix and passes subsequently.

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

@centos-ci
Copy link

Can one of the admins verify this patch?

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 8, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 2 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@rohanKanojia
Copy link
Member

ok to test

@rohanKanojia
Copy link
Member

rohanKanojia commented Jul 8, 2020

@ahgittin : Thanks for your contribution 👍. There are two sonar code smells, I think they can be easily addressed

@ahgittin
Copy link
Contributor Author

ahgittin commented Jul 8, 2020 via email

@rohanKanojia
Copy link
Member

[merge]

@fusesource-ci fusesource-ci merged commit df36613 into fabric8io:master Jul 9, 2020
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.

6 participants