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

Upgrade to latest fabric8 libraries #60

Closed
BramMeerten opened this issue Mar 22, 2023 · 6 comments · Fixed by #87
Closed

Upgrade to latest fabric8 libraries #60

BramMeerten opened this issue Mar 22, 2023 · 6 comments · Fixed by #87
Assignees

Comments

@BramMeerten
Copy link

Currently fabric8 version 6.2.0 is used.
When I try to use fabric8 6.5.0 in my project, I get an error from kubernetes-webhooks-framework:

@Factory
@RequiredArgsConstructor
public class MyCustomResourceAdmissionControlConfig {

    @Singleton
    public AdmissionController<MyCustomResource> validatingController() {
        return new AdmissionController<>((cr, operation) -> {
            // ...
        });
    }
}
 java.lang.ClassCastException: class io.fabric8.kubernetes.api.model.GenericKubernetesResource cannot be cast to class com.myproject.model.MyCustomResource (io.fabric8.kubernetes.api.model.GenericKubernetesResource and com.myproject.model.MyCustomResource are in unnamed module of loader 'app')
 	at io.javaoperatorsdk.webhook.admission.validation.DefaultAdmissionRequestValidator.handle(DefaultAdmissionRequestValidator.java:28) ~[kubernetes-webhooks-framework-core-1.0.0.jar:?]
 	at io.javaoperatorsdk.webhook.admission.AdmissionController.handle(AdmissionController.java:27) ~[kubernetes-webhooks-framework-core-1.0.0.jar:?]
 	at com.myproject.validation.admissioncontrol.AdmissionControlEndpoint.validate(AdmissionControlEndpoint.java:21) ~[my-project-admission-control-1.0.0.jar:?]
 	at com.myproject.validation.admissioncontrol.$AdmissionControlEndpoint$Definition$Exec.dispatch(Unknown Source) ~[my-project-admission-control-1.0.0.jar:?]
 	at io.micronaut.context.AbstractExecutableMethodsDefinition$DispatchedExecutableMethod.invoke(AbstractExecutableMethodsDefinition.java:371) ~[micronaut-inject-3.8.7.jar:3.8.7]

The reason I want to use version 6.5.0 is because I'm upgrading snakeyaml dependency because of a critical CVE (CVE-2022-1471). This is only possible in kubernetes-client version 6.5.0 (fabric8io/kubernetes-client#4933).

Is it possible to upgrade to 6.5.0 or make sure it's compatible?

@BramMeerten
Copy link
Author

BramMeerten commented Mar 27, 2023

Error seems to be caused by a breaking change in 6.3.0:

Fix fabric8io/kubernetes-client#4579: the implicit registration of resource and list types that happens when using the resource(class) methods has been removed. This makes the behavior of the client more predictable as that was an undocumented side-effect. If you expect to see instances of a custom type from an untyped api call - typically KubernetesClient.load, KubernetesClient.resourceList, KubernetesClient.resource(InputStream|String), then you must either create a META-INF/services/io.fabric8.kubernetes.api.model.KubernetesResource file (see above fabric8io/kubernetes-client#3923), or make calls to KubernetesDeserializer.registerCustomKind - however since KubernetesDeserializer is an internal class that mechanism is not preferred.

Once I added the file resources/META-INF/services/io.fabric8.kubernetes.api.model.KubernetesResource with content:

com.myproject.model.MyCustomResource

Everything works.

Maybe this ticket should remain open so documentation can be added once fabric8 is upgraded?

@csviri
Copy link
Contributor

csviri commented Mar 27, 2023

Hi @BramMeerten , somehow I missed the issue, currently I'm working also to have the most recent version of fabric8 here by default.

yes, we can keep this open, and will update the Docs. But also feel free to open a PR for that.

@csviri csviri self-assigned this Mar 27, 2023
@csviri
Copy link
Contributor

csviri commented Mar 28, 2023

for conversion Hooks we are acutally doing this: or make calls to KubernetesDeserializer.registerCustomKind . would make sense also to do for dynamic admission controllers. Will discuss this also with the fabric8 team.

@BramMeerten
Copy link
Author

I did not look at that option because it saids however since KubernetesDeserializer is an internal class that mechanism is not preferred..
For users of this library, it would be much easier though. Curious to hear what the fabric8 team thinks.

@csviri
Copy link
Contributor

csviri commented Mar 28, 2023

Checked on this briefly. There is an other difference though, for conversion hooks we have the mappers, and those always (well almost) work on CustomResources. But for validators and mutators in the API it is anyways desired to use lambdas, also those not always work on some concrete classes, can be more generic. So there can be a mutation hook that adds a label to any resource (HasMetadata in fabric8 client). So in some cases it is not even very straightforward from the code, what custom resources to register.

Therefore would probably stick rather with the advised way in this case. However, there should be a sample, and docs for this for sure.

It's also a question if this should be also changed for conversion hooks, to use the advised approach.

@csviri
Copy link
Contributor

csviri commented Mar 30, 2023

@BramMeerten
added related PR: #87
if you have some time pls review it, if it makes sense this way. Will make a release after it is merged.

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 a pull request may close this issue.

2 participants