kubernetes-client icon indicating copy to clipboard operation
kubernetes-client copied to clipboard

Getting java.lang.ClassNotFoundException: io.fabric8.kubernetes.client.dsl.V1FlowControlAPIGroupDSL

Open KaanSimsek opened this issue 1 year ago • 3 comments

Describe the bug

I am using kubernetes client version 6.12.1 and also for dependencyManagement my gradle file uses mavenBom spring-cloud-depencencies. But when I run my app I am getting this error Getting java.lang.ClassNotFoundException: io.fabric8.kubernetes.client.dsl.V1FlowControlAPIGroupDSL.

If I remove dependencyManagement part from my gradle error does not happen but I need it. Also I have checked other versions of the kubernetes client and I seen that 6.9.2 works.

Fabric8 Kubernetes Client version

6.12.1

Steps to reproduce

You can use this repo for reproducing the bug https://github.com/KaanSimsek/kubernetes-client-bug

Expected behavior

Being able to use mavenBom as dependency management.

Runtime

Kubernetes (vanilla)

Kubernetes API Server version

1.25.3@latest

Environment

macOS

Fabric8 Kubernetes Client Logs

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kubernetesClient' defined in class path resource [com/example/kubernetes_client_bug/KubernetesClientConfig.class]: Failed to instantiate [io.fabric8.kubernetes.client.KubernetesClient]: Factory method 'kubernetesClient' threw exception with message: io/fabric8/kubernetes/client/dsl/V1FlowControlAPIGroupDSL
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:648) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:485) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1335) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1165) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:962) ~[spring-context-6.1.6.jar:6.1.6]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624) ~[spring-context-6.1.6.jar:6.1.6]
	at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66) ~[spring-boot-3.2.5.jar:3.2.5]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-3.2.5.jar:3.2.5]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) ~[spring-boot-3.2.5.jar:3.2.5]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:334) ~[spring-boot-3.2.5.jar:3.2.5]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354) ~[spring-boot-3.2.5.jar:3.2.5]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-3.2.5.jar:3.2.5]
	at com.example.kubernetes_client_bug.KubernetesClientBugApplicationKt.main(KubernetesClientBugApplication.kt:13) ~[main/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.fabric8.kubernetes.client.KubernetesClient]: Factory method 'kubernetesClient' threw exception with message: io/fabric8/kubernetes/client/dsl/V1FlowControlAPIGroupDSL
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:177) ~[spring-beans-6.1.6.jar:6.1.6]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:644) ~[spring-beans-6.1.6.jar:6.1.6]
	... 19 common frames omitted
Caused by: java.lang.NoClassDefFoundError: io/fabric8/kubernetes/client/dsl/V1FlowControlAPIGroupDSL
	at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na]
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017) ~[na:na]
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150) ~[na:na]
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862) ~[na:na]
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760) ~[na:na]
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681) ~[na:na]
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639) ~[na:na]
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525) ~[na:na]
	at java.base/java.lang.Class.getDeclaredConstructors0(Native Method) ~[na:na]
	at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3373) ~[na:na]
	at java.base/java.lang.Class.getConstructor0(Class.java:3578) ~[na:na]
	at java.base/java.lang.Class.getConstructor(Class.java:2271) ~[na:na]
	at io.fabric8.kubernetes.client.KubernetesClientBuilder.build(KubernetesClientBuilder.java:80) ~[kubernetes-client-api-6.9.2.jar:na]
	at com.example.kubernetes_client_bug.KubernetesClientConfig.kubernetesClient(KubernetesClientConfig.kt:23) ~[main/:na]
	at com.example.kubernetes_client_bug.KubernetesClientConfig$$SpringCGLIB$$0.CGLIB$kubernetesClient$1(<generated>) ~[main/:na]
	at com.example.kubernetes_client_bug.KubernetesClientConfig$$SpringCGLIB$$FastClass$$1.invoke(<generated>) ~[main/:na]
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:258) ~[spring-core-6.1.6.jar:6.1.6]
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-6.1.6.jar:6.1.6]
	at com.example.kubernetes_client_bug.KubernetesClientConfig$$SpringCGLIB$$0.kubernetesClient(<generated>) ~[main/:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:140) ~[spring-beans-6.1.6.jar:6.1.6]
	... 20 common frames omitted
Caused by: java.lang.ClassNotFoundException: io.fabric8.kubernetes.client.dsl.V1FlowControlAPIGroupDSL
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525) ~[na:na]
	... 45 common frames omitted

Additional context

No response

KaanSimsek avatar May 28 '24 10:05 KaanSimsek

https://github.com/fabric8io/kubernetes-client/blob/main/doc/FAQ.md#ive-tried-adding-a-dependency-to-kubernetes-client-but-im-still-getting-weird-class-loading-issues-what-gives

The version of the Kubernetes Client you're using is not compatible with the version of Spring Cloud Kubernetes defined in its BOM.

See the linked FAQ entry to see if adding the Kubernetes Client BOM solves your issue.

manusa avatar May 28 '24 11:05 manusa

Thanks for the quick response @manusa . I think I am doing something wrong. I have tried the configuration below but it still gives same error. Am I using it wrong?

`

dependencyManagement {

imports {
    dependencies {
        dependency("io.fabric8:kubernetes-client-bom:6.12.1")
    }
    mavenBom("org.springframework.cloud:spring-cloud-dependencies:2023.0.1")
}

}

`

KaanSimsek avatar May 28 '24 12:05 KaanSimsek

Thanks for the quick response @manusa . I think I am doing something wrong. I have tried the configuration below but it still gives same error. Am I using it wrong?

`

dependencyManagement {

imports {
    dependencies {
        dependency("io.fabric8:kubernetes-client-bom:6.12.1")
    }
    mavenBom("org.springframework.cloud:spring-cloud-dependencies:2023.0.1")
}

}

`

Not sure how this is done on Gradle, but try:

dependencyManagement {
  imports {
    mavenBom("org.springframework.cloud:spring-cloud-dependencies:2023.0.1")
    mavenBom("io.fabric8:kubernetes-client-bom:6.12.1")
  }
}

manusa avatar Jun 04 '24 09:06 manusa

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[bot] avatar Sep 17 '24 02:09 stale[bot]